bazel Cheatsheet
Last Updated: 2023-08-27
Android is moving to Bazel.
Config written in Starlark, a dialect of Python https://github.com/bazelbuild/starlark/
What's new
External Dependencies
https://docs.bazel.build/versions/main/bzlmod.html
It will be more like other dependency management systems (maven, npm, cargo, etc)
- Bazel Modules
- Bazel Central Repository (BCR)
Trouble Shooting
Error: ... undeclared inclusion(s) in rule ...
This can happen after installing or upgrading developer tools (xcode). Try
$ bazel clean --expunge
Rules
To pull Maven artifacts, use rules_jvm_external
Native rules
Native rules: rules that don't need a load()
statement, e.g. cc_library
or java_library
Define config
in ~/.bazelrc
:
# Definition of --config=memcheck
build:memcheck --strip=never --test_timeout=3600
Used by:
$ bazel build --config=memcheck
Trouble-shooting
bazel error
ERROR: Source forest creation failed
Solution:
$ sudo rm -rf ~/.cache/bazel
Query Dependencies
If //path/to/foo
does not directly depend on //bar:baz
, use bazel query
to find independent dependencies:
$ bazel query "allpaths(//path/to/foo, //bar:baz)" --notool_deps --output graph | dot -Tpng > deps.png