Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate compile_commands.json for a C++ Bazel project

Tags:

c++

bazel

In a C++ Bazel project, I want to use tools like Clang Tools or RTags, etc.

For that I need to generate a compile_commands.json file.

The solution is trivial for CMake with the CMAKE_EXPORT_COMPILE_COMMANDS.

For simple Makefiles you can still use the Bear tool.

However AFAIK there is no built-in solution for C++ Bazel projects.

like image 660
Picaud Vincent Avatar asked Jul 07 '17 08:07

Picaud Vincent


People also ask

How is Compile_commands json generated?

You can generate a project compile_commands. json using the pio run --target command and compiledb target. A default location for compile_commands. json is a project directory.

What is Compile_commands json?

The compile_commands. json file is a compilation database that consists of an array of “command objects” , where each command object specifies one way a translation unit is compiled in the project.


1 Answers

Extra information:

  • Bear is currently not working with Bazel: this issue
  • a good documentation concerning compile_command.json can be found here.

Suggested solutions:

After Googling about that I found gist:Basics of generating a compile_commands.json file with Bazel.

It works fine and I have written an automated solution with bash scripts <- my solution

Alternative:

Also on GitHub, you can find:

  • Kythe: uses Bazel action listeners
  • github.com/grailbio/bazel-compilation-database: provides a script and a bazel rule.
like image 168
Picaud Vincent Avatar answered Sep 20 '22 09:09

Picaud Vincent