Skip to content

levanliu/bazel-compile-commands

Repository files navigation

compile_commands.json generator for Bazel

bazel-compile-commands build status of main branch

This 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_COMPILE_COMMANDS 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.

Usage of bazel-compile-commands

Inside a Bazel workspace run:

bazel-compile-commands

This will generate a compile_commands.json file in the current directory.

VS Code integration

See the .vscode/tasks.json file as an example on how to integratebazel-compile-commands into VS Code.

Mentions

Build

Linux and macOS

bazel build --config=gnu //bcc:bazel-compile-commands

Windows

bazel build --config=cl //bcc:bazel-compile-commands

Alternative tools

Links

Issues

License

This source code is under the MIT license with the exceptions mentioned in "Third party source code in this repository".

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published