Yifan Hong | 707b393 | 2023-01-10 13:13:47 -0800 | [diff] [blame] | 1 | # Build `compile_commands.json` |
| 2 | |
Yifan Hong | 2b7882ef | 2023-02-08 12:38:34 -0800 | [diff] [blame] | 3 | The `compile_commands.json` file helps you enable cross-references |
| 4 | in your editor. Follow these instructions to place `compile_commands.json` |
| 5 | at the root of your repository. |
| 6 | |
Yifan Hong | 707b393 | 2023-01-10 13:13:47 -0800 | [diff] [blame] | 7 | ## GKI |
| 8 | |
| 9 | Run the following to place `compile_commands.json` at the root of your |
| 10 | repository: |
| 11 | |
| 12 | ```shell |
| 13 | $ tools/bazel run //common:kernel_aarch64_compile_commands |
| 14 | ``` |
| 15 | |
Yifan Hong | 2b7882ef | 2023-02-08 12:38:34 -0800 | [diff] [blame] | 16 | Or, to place the file somewhere else, you may provide the **absolute** path |
| 17 | to the destination as an argument to the script after `--`: |
| 18 | |
| 19 | ```shell |
| 20 | $ tools/bazel run //common:kernel_aarch64_compile_commands -- /tmp/compile_commands.json |
| 21 | ``` |
| 22 | |
Ulises Mendez Martinez | f471506 | 2025-02-20 13:38:12 +0000 | [diff] [blame] | 23 | Use the option `--real_clang_path` to update `clang`'s value of the |
| 24 | `"command"`'s in the generated `.json` with its absolute path. |
| 25 | |
| 26 | ```shell |
| 27 | $ tools/bazel run //common:kernel_aarch64_compile_commands -- --real_clang_path |
| 28 | ``` |
| 29 | |
| 30 | |
Yifan Hong | 707b393 | 2023-01-10 13:13:47 -0800 | [diff] [blame] | 31 | ## Device kernel |
| 32 | |
| 33 | If you want to build `compile_commands.json` for in-tree modules, create a |
HONG Yifan | 31a8fde | 2024-07-01 17:41:07 -0700 | [diff] [blame] | 34 | `kernel_compile_commands` target with `deps` set to the `kernel_build` and |
| 35 | external module targets (`kernel_module`, `ddk_module` and/or |
| 36 | `kernel_module_group`). Then `tools/bazel run` the target. |
Yifan Hong | 707b393 | 2023-01-10 13:13:47 -0800 | [diff] [blame] | 37 | |
| 38 | See `kernel_compile_commands` in |
| 39 | [documentation for all rules](api_reference.md) for details. |
Yifan Hong | 2b7882ef | 2023-02-08 12:38:34 -0800 | [diff] [blame] | 40 | |
Ulises Mendez Martinez | 7062909 | 2024-10-16 12:12:53 +0000 | [diff] [blame] | 41 | **NOTE:** For out-of-tree modules built with the `kernel_module` macro, make |
| 42 | sure your `Makefile` files support the `compile_commands.json` target. |
| 43 | |
Yifan Hong | 2b7882ef | 2023-02-08 12:38:34 -0800 | [diff] [blame] | 44 | ## See also |
| 45 | |
| 46 | See also the following links to incorporate clangd to your editor. |
| 47 | |
| 48 | [clangd - Getting started](https://clangd.llvm.org/installation) |
| 49 | |
| 50 | See the following for the schema of `compile_commands.json`. |
| 51 | |
| 52 | [JSON Compilation Database Format Specification](https://clang.llvm.org/docs/JSONCompilationDatabase.html) |