Setting up your coding environment
For now we have support for IntelliJ. We don’t have IDE support for other languages in Bazel right now.
- Install Bazel on your system. Note that for developing Bazel, you need the latest released version of Bazel.
- Clone Bazel’s Git repository from GitHub:
git clone https://github.com/bazelbuild/bazel.git
Try to build Bazel (you might need to install some prerequisites first):
On Linux/macOS, in Bash/Terminal:
cd bazel bazel build //src:bazel
On Windows, in the Command Prompt:
cd bazel bazel --output_user_root=c:\tmp build //src:bazel.exe
For faster iteration times (but larger binaries), use
- This will produce a working Bazel binary in
Creating an IntelliJ project
To work with IntelliJ:
- Install Bazel’s IntelliJ plug-in.
- Set the path to the Bazel binary in the plugin preferences
- Import the Bazel workspace as a Bazel project
Import Bazel Project...) with the following settings:
- Use existing Bazel workspace: choose your cloned Git repository.
Import from workspaceand choose the
scripts/ij.bazelprojectfile as the
- Download Google’s Java Code Style Scheme file for IntelliJ,
import it (go to
Import) and use it when working on Bazel’s code.
To test out Bazel, you need to compile it. To compile a development version of Bazel, you need a the latest released version of Bazel, which can be compiled from source.
bazel build //src:bazel builds the Bazel binary using
bazel from your PATH
and the resulting binary can be found at
bazel-bin/src/bazel. This is the
recommended way of rebuilding Bazel once you have bootstrapped it.
In addition to the Bazel binary, you might want to build the various tools Bazel
uses. They are located in
//src/tools/... and their directories contain README files describing their
When modifying Bazel, you want to make sure that the following still works:
- Build a distribution archive with
bazel build //:bazel-distfile. After unzipping it in a new empty directory, run
bash compile.sh allthere. It rebuilds Bazel with
./compile.sh, Bazel with the
compile.shBazel and Bazel with the Bazel-built binary. It compares if the constructed Bazel builts are identical and then runs all Bazel tests with
bazel test //src/... //third_party/ijar/.... This is what we use at Google to ensure that we don’t break Bazel when pushing new commits, too.
Start creating a debug configuration for both C++ and Java in your
with the following:
build:debug -c dbg build:debug --javacopt="-g" build:debug --copt="-g" build:debug --strip="never"
Then you can rebuild Bazel with
bazel build --config debug //src:bazel and use
your favorite debugger to start debugging.
For debugging the C++ client you can just run it from gdb or lldb as you normally would. But if you want to debug the Java code, you must attach to the server using the following:
- Run Bazel with debugging option
--host_jvm_debugbefore the command (e.g.,
bazel --host_jvm_debug build //src:bazel).
- Attach a debugger to the port 5005. With
jdbfor instance, run
jdb -attach localhost:5005.
- Our IntelliJ plugin has built-in debugging support
Bazel’s code description
Bazel is organized in several parts:
- Client code in
src/main/cppprovides the command-line interface.
- Protocol buffers in
- Server code in
- Java native interfaces in
- Various tooling for language support (see the list in the compiling Bazel section).
Searching Bazel’s source code
To quickly search through Bazel’s source code, use Bazel Code Search. You can navigate Bazel’s repositories, branches, and files. You can also view history, diffs, and blame information. To learn more, see the Bazel Code Search User Guide.