This page contains resources that help you use Bazel with C++ projects. It links to a tutorial, build rules, and other information specific to building C++ projects with Bazel.Documentation Index
Fetch the complete documentation index at: https://bazel-pr-29415.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Working with Bazel
The following resources will help you work with Bazel on C++ projects:- Tutorial: Building a C++ project
- C++ common use cases
- C/C++ rules
- C++ toolchain configuration
- Tutorial: Configuring C++ toolchains
- Integrating with C++ rules
Best practices
In addition to general Bazel best practices, below are best practices specific to C++ projects.BUILD files
Follow the guidelines below when creating your BUILD files:-
Each
BUILDfile should contain onecc_libraryrule target per compilation unit in the directory. - You should granularize your C++ libraries as much as possible to maximize incrementality and parallelize the build.
-
If there is a single source file in
srcs, name the library the same as that C++ file’s name. This library should contain C++ file(s), any matching header file(s), and the library’s direct dependencies. For example: -
Use one
cc_testrule target percc_librarytarget in the file. Name the target[library-name]_testand the source file[library-name]_test.cc. For example, a test target for themyliblibrary target shown above would look like this:
Include paths
Follow these guidelines for include paths:- Make all include paths relative to the workspace directory.
-
Use quoted includes (
#include "foo/bar/baz.h") for non-system headers, not angle-brackets (#include <foo/bar/baz.h>). -
Avoid using UNIX directory shortcuts, such as
.(current directory) or..(parent directory). -
For legacy or
third_partycode that requires includes pointing outside the project repository, such as external repository includes requiring a prefix, use theinclude_prefixandstrip_include_prefixarguments on thecc_libraryrule target.