...
dev
is a light wrapper around Bazel that is well-suited to specific CRDB development tasks. Properly, when we say dev
, we’re referring to the Go binary whose source lives in cockroach/pkg/cmd/dev
, side-by-side with the Cockroach source. At the top level of the repo there is a wrapper script also called dev
whose only job is to build pkg/cmd/dev
and then invoke it with the passed-in arguments. We encourage placing this in your $PATH
(ahead of pkg/bin
). This means that you can always type ./dev
to run the version of dev
at the commit you’ve checked out, which is typically what you want to do.
...
Before trying to build anything, run the following:
Code Block |
---|
./dev doctor |
If dev
notices any issues with your system that might prevent you from being able to build, it will let you know and tell you how to fix it. Make sure to run dev doctor
before you ask for help just in case it catches something you didn’t know about.
...
Start by building cockroach-short
as follows:
Code Block |
---|
./dev build //pkg/cmd/cockroach-short |
...
You can also build cockroach{ccl,oss}
:
Code Block |
---|
./dev build //pkg/cmd/cockroach //pkg/cmd/cockroach-oss |
...
Code Block |
---|
# build "verbosely", outputting all commands as they are run
./dev build short -- -s |
You can cross-compile with the --cross
option, as in:
Code Block |
---|
./dev build --cross |
--cross
takes an optional argument which is the platform to cross-compile to: --cross=linux
, --cross=windows
, --cross=macos
. dev
will symlink the built binaries into the artifacts
directory in this case.
Running tests
Run ./dev test
with the name of one or more packages to execute all tests from those packages:
Code Block |
---|
./dev test pkg/sql/types |
If the test passes, you’ll see a brief message indicating which tests were run and their status:
...
Code Block |
---|
# Run benchmarks for pkg/sql/parser ./dev bench pkg/sql/parser # Open a container running the "bazelbuilder" image. Requires Docker. ./dev builder # Generate code (run this before submitting your PR). ./dev generate # Run lints (WARNING: not all lints work in Bazel yet) ./dev lint # logic tests! ./dev testlogic --files=$FILES --subtests=$SUBTESTS --config=$CONFIG |
...
This is a (non-exhaustive) 1-to-1 mapping of dev
commands to their make
equivalents. Feel free to add to this
| equivalent non- |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
Since
./dev
always buildsdev
unconditionally before doing anything else, that means there will be a slight delay before your build or test actually begins. Due to caching this pause should never be too long, but if it’s annoying you or you’ve found a way to thrash the cache, you can do:Code Block ./dev build dev
This will place a binary at
bin/dev
and ifbin
is in yourPATH
, you can then omit the leading./
. In this document we’ll always spell./dev
without with the leading./
to squash ambiguity and for ease of copy-pasting.
General Bazel tips
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.
...
We recommend dev
because it takes care of some common pitfalls for you and because it has a less wordy CLI (especially for tests), but you’re still welcome to directly use Bazel. A couple notes for those of you who wish to avoid dev
:
You should still ask
dev doctor
if your machine is up-to-snuff before you try tobazel build
. The checks it performs aren’tdev
-specific.dev
prints out the (relevant) calls tobazel
it makes before it does so. You can therefore rundev
once just to learn how to ask Bazel to perform your build/test and then just directly call intobazel
on subsequent iterations.dev
strips out symlinks toccache
in yourPATH
, which break the Bazel build asccache
tries to write outside the sandbox. If you usebazel
directly you should get theccache
links out of yourPATH
manually (i.e. uninstallccache
).If you want to build with the UI, you must include the
--config with_ui
argument tobazel build
.dev
checks whether your executable should include the UI bits and passes it in for you.In general, test targets are named after the package under test plus the suffix
_test
. For example:bazel test pkg/sql/parser:parser_test
. Note that there are exceptions:pkg/roachpb:string_test
is one, and more may be added later.When running tests under stress, race,--rewrite
,dev
does the legwork to invoke with the necessary flags with bazel. This involves running under another binary (stress
), running with certain gotags (race
), or allowing certain paths outside the bazel sandbox to be written to (testdata
). Feel free to see the actualbazel
command invoked and tweak as necessary.