Skip to main content

Automatic BUILD generation

In most languages, BUILD files can be automatically created and updated by running this command:
The gazelle tool 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 the import statements in the srcs 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.

Manual BUILD Authoring.

In some cases, there’s no BUILD generator for your language, or it doesn’t include the feature you need for configuration. In this case, you will edit BUILD files on your own.
  1. Look around the repo for examples.
  2. Ask your DevInfra team to provide more documentation, or write the missing BUILD generator.
  3. Consider using Macros to reduce the boilerplate you have to type.
  4. Use #keep to avoid the BUILD generator changing your code.