We’re partway through a migration of our We’ve migrated the cockroach
build system to Bazel. Bazel is a modern build system with better performance characteristics and correctness guarantees than we currently have with make
/go build
. Today, you can perform almost all day-to-day CRDB dev tasks with Bazel rather than with make
. make
is deprecated and we will remove this option for building Cockroach at some point in the next release cycle.
...
Bazel has a configuration file called .bazelrc. You can put a global configuration file at
~/.bazelrc
or a per-repository file at.bazelrc.user
in the root of yourcockroach
repo.Tired of running./dev gen bazel
? Set theALWAYS_RUN_GAZELLE
env-var to automatically run./dev gen bazel
before everydev test
ordev build
incantation. Note thisWhile Bazel is the “official” build system, you do not have to use it for normal development. For example, many people do development from their IDE’s, and this is expected to “just work”. Note that since not all generated code is checked into the repo, you’ll first have to generate code to get much of it to build from a non-Bazel build system. We refer to this as the “escape hatch”. This escape hatch is specifically supported so if you have difficulty running a test in another build system after generating code, that’s a bug you should report. You can run the following commands to make this happen:
dev gen go
Generates all
.go
code that goes into the build, includingcgo
code
dev gen cgo
Generates some stub files that tell
cgo
how to link in thec-deps
; part ofdev gen go
dev gen protobuf
Generates all
.pb.go
/.pb.gw.go
files; part ofdev gen go
Tired of running
./dev gen bazel
? Set theALWAYS_RUN_GAZELLE
env-var to automatically rungazelle
before everydev test
ordev build
incantation. Note this does add a tiny delay – noticeable when iterating on small tests throughdev test
.i.e.
echo 'export ALWAYS_RUN_GAZELLE=1' >> ~/.zshrc
Note that
gazelle
is only a subset of the aactions thatdev gen bazel
performs. This by itself is able to handle most updates to the code, but is not able to handle things like vendoring new dependencies (dev gen bazel
can do this for you).
If you have
ccache
installed,bazel
will fail with an error likeccache: error: Failed to create temporary file for /home/alyshanjahani/.ccache/tmp/message_li.stdout: Read-only file system
. To avoid this you should get theccache
links out of yourPATH
manually (i.e. uninstallccache
), and then you might need to dobazel clean --expunge
.Alternatively, if you would like to use Bazel with
ccache
, you can enable support for writing outside the sandbox by adding the following to your$HOME/.bazelrc
or<repo>/.bazelrc.user
file:
- For MacOS/Darwin:Code Block build --sandbox_writable_path=/Users/<USER>/Library/Caches/ccache/
- For Linux:
Code Block build --sandbox_writable_path=/home/<USER>/.ccache
...