Skip to content

Matzkowsky/bazel-compilation-database

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compilation database with Bazel Build Status

If you use Bazel and want to use libclang based editors and tools, you can now generate JSON compilation database easily without using build intercept hooks. The advantage is that you can generate the database even if your source code does not compile, and the generation process is much faster.

For more information on compilation database, Guillaume Papin has an excellent article.

How to Use

Make the files in this github repo available somewhere in your repo, and run the generate.sh script. This will create a compile_commands.json file at your workspace root. For example,

  git submodule add https://github.com/matzkowsky/bazel-compilation-database bazel-compdb
  bazel-compdb/generate.sh

An alternative to running the generate.sh script is to define a target of rule type compilation_database with the attribute targets as a list of top-level cc_.* labels which you want to include in your compilation database. For example,

## Replace workspace_name and dir_path as per your setup.
load("@workspace_name//dir_path:aspects.bzl", "compilation_database")

compilation_database(
    name = "example_compdb",
    targets = [
        "//a_cc_binary_label",
        "//a_cc_library_label",
    ],
    remove_workspace_root_marker = True,
)

Note that you will have to replace "WORKSPACE_ROOT" in the generated file with the output of bazel info workspace. Or you can set remove_workspace_root_marker attribute to False in which case, the directory entry will simply be bazel-{workspace name}

Contributing

Contributions are most welcome. Please submit a pull request giving the owners of this github repo access to your branch for minor style related edits, etc.

Known Issues

Please check open issues at the github repo.

We have tested only for C and C++ code, and with tools like YouCompleteMe, rtags, and the woboq code browser.

Alternatives

  1. Kythe: uses Bazel action listeners
  2. Bear: uses build intercept hooks

These approaches could be more accurate than the approach of this tool in some rare cases, but need a more complicated setup and a full build every time you refresh the database.

About

Tool to generate compile_commands.json from the Bazel build system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 60.4%
  • Shell 22.5%
  • C++ 17.1%