Skip to main content
So far in the training courses, our BUILD files used features that ship with Bazel or with rulesets. What do we do when we need something more? First, recall that an Action is a transformation from some inputs to some outputs, by spawning a tool. So the first step in integrating Bazel with any language or code generation tooling is to setup the runtime and fetch the tool itself. When the tool doesn’t already exist, you might write one. To determine what Actions to run, the dependency graph is “lowered” to the action graph during the analysis phase. This lowering is defined by rule implementations.
DefinitionA “Rule” extends Bazel to understand how to produce an action sub-graph from the user’s dependency graph.Features:
  • Output Groups: Multiple named sets of outputs
  • Can run multiple actions. Which actions run depends on which outputs are requested.
  • Interoperability API with other rules: “Providers”
  • Walk the dependency graph: “Aspects”
Macros are expanded during the Loading phase. Macros are significantly easier to write than custom rules. They are much more readable as well, since they look very similar to BUILD files. Custom rules are complex, and you can nearly always accomplish your goal with a macro instead. So, we’ll learn about the more usable alternative in the next section: Macros.