blob: 7facdca285bf2dfee7096e68ef1de17823829df5 [file] [log] [blame] [view]
Yifan Hong707b3932023-01-10 13:13:47 -08001# Build `compile_commands.json`
2
Yifan Hong2b7882ef2023-02-08 12:38:34 -08003The `compile_commands.json` file helps you enable cross-references
4in your editor. Follow these instructions to place `compile_commands.json`
5at the root of your repository.
6
Yifan Hong707b3932023-01-10 13:13:47 -08007## GKI
8
9Run the following to place `compile_commands.json` at the root of your
10repository:
11
12```shell
13$ tools/bazel run //common:kernel_aarch64_compile_commands
14```
15
Yifan Hong2b7882ef2023-02-08 12:38:34 -080016Or, to place the file somewhere else, you may provide the **absolute** path
17to 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 Martinezf4715062025-02-20 13:38:12 +000023Use 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 Hong707b3932023-01-10 13:13:47 -080031## Device kernel
32
33If you want to build `compile_commands.json` for in-tree modules, create a
HONG Yifan31a8fde2024-07-01 17:41:07 -070034`kernel_compile_commands` target with `deps` set to the `kernel_build` and
35external module targets (`kernel_module`, `ddk_module` and/or
36`kernel_module_group`). Then `tools/bazel run` the target.
Yifan Hong707b3932023-01-10 13:13:47 -080037
38See `kernel_compile_commands` in
39[documentation for all rules](api_reference.md) for details.
Yifan Hong2b7882ef2023-02-08 12:38:34 -080040
Ulises Mendez Martinez70629092024-10-16 12:12:53 +000041**NOTE:** For out-of-tree modules built with the `kernel_module` macro, make
42sure your `Makefile` files support the `compile_commands.json` target.
43
Yifan Hong2b7882ef2023-02-08 12:38:34 -080044## See also
45
46See also the following links to incorporate clangd to your editor.
47
48[clangd - Getting started](https://clangd.llvm.org/installation)
49
50See the following for the schema of `compile_commands.json`.
51
52[JSON Compilation Database Format Specification](https://clang.llvm.org/docs/JSONCompilationDatabase.html)