Editor extensions
Your editor or IDE may have a Bazel plugin you can install. These plugins can:-
Highlight syntax in
BUILDfiles -
Provide build commands for targets
These plugins do not have auto-completion yet, though a Starlark Language Service is available in the Buck ecosystem and may eventually become part of Bazel.
Starlark
Starlark is a Python-like language used to define Bazel build rules and extensions. Implementations of the Starlark interpreter exist in Java, Go, and Rust. The Starlark specification is readable and explains how its execution model guarantees safe, parallel evaluation of build logic.- BUILD files are written in a restricted subset of Starlark.
- Bazel extensions (*.bzl files) can use the full Starlark language, enabling more complex logic and reusable rules.
load statements
load is a Starlark language construct used to import reusable rules, functions, or macros from other .bzl files.
load statements should appear at the top of the file. They import symbols into file scope and are eagerly evaluated.
The first argument is a label of a .bzl source file, and the following arguments are symbols to load.
package statements
Optionally you can use package statements to define default values for all targets in the BUILD file.
The glob function
The glob function allows you to skip listing individual files, for example:
srcs = glob(["*.ts"]).
However, the glob must be evaluated every time Bazel loads the file, and so it incurs a performance penalty, especially as the number of files in the package grows.
It also doesn’t descend into sub-packages, so it’s easy to omit files by accident.
Here’s a talk about glob from BazelCon 2024

