BUILD Generation
In most languages, for most code changes, we expect that BUILD
files can be automatically created and updated, using the configure
command.
bazel configure
is in the Aspect CLI only.
If your project doesn’t use the Aspect CLI, you can install the Gazelle tool using the gazelle_binary
rule, however this means developers have to build it from source when they run it.
The configure
command indexes the source code structure, similar to how an editor or IDE provides jump-to-definition. BUILD generators rely on conventions to decide what to create:
srcs
contains all files in the current package with the typical file extension.deps
can be determined by looking at all theimport
statements in thesrcs
and mapping them to labels which provide that symbol.- tests can be separated out by a file convention
The 200-series courses discuss how to modify or extend the conventions, either using Gazelle’s Go API, or using the same “Starlark” language as Bazel rules and macros.
By Hand
In some cases, there’s no BUILD generator for your language, or it doesn’t include the feature you need to configure, for example where to deploy the binary. Expect to edit BUILD
files yourself sometimes.
- Look around the repo for examples
- Ask your DevInfra team to provide more documentation, or write the missing BUILD generator
- Consider using Macros to reduce the boilerplate you have to type.
- Use
#keep
to avoid the BUILD generator changing your code.