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

Picaud Vincent picture Picaud Vincent · Jul 7, 2017 · Viewed 8.7k times · Source

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.

Answer

Picaud Vincent picture Picaud Vincent · Jul 7, 2017

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: