compile_commands.json
generator for BazelThis repository contains two tools to generate a compile_commands.json
file
from a Bazel workspace without the need to modify any of the Bazel configuration
files. This is the equivalent of _CMAKE_EXPORT_COMPILECOMMANDS from CMake for
Bazel.
The
Microsoft C/C++ Extension for Visual Studio Code
struggles sometimes with Bazel workspaces since not all include paths are at the
default locations. The compile_commands.json
file can be used with clangd
to
have a significant better LSP experience. For
Visual Studio Code (VS Code), the
clangd extension
can be used to utilize the project compile information via the
compile_commands.json
file.
Invoke bazel-compile-commands //...
to generate a compile_commands.json
file
for the
Bazel label
//...
. For more information, see
man 1 bazel-compile-commands
.
The bazel-compile-commands
command is ideal when you need a
compile_commands.json
file instantly and don't require automatic updates of
the compile_commands.json
file. For example in CI use cases when you when
static analysis tools use a compile_commands.json
file as input.
bazel-compile-commands
Inside a Bazel workspace run:
bazel-compile-commands
This will generate a compile_commands.json
file in the current directory.
man 1 bazel-compile-commands
See the .vscode/tasks.json
file as an example on how
to integratebazel-compile-commands
into VS Code.
bazel build --config=gnu //bcc:bazel-compile-commands
bazel build --config=cl //bcc:bazel-compile-commands
--spawn_strategy=local
Bazel flag.This source code is under the MIT license with the exceptions mentioned in "Third party source code in this repository".