What is a Bazel repository?
A Bazel repository is a directory tree containing source files that can be used in a Bazel build. The repository is identified by boundary marker files at its root, such as theREPO.bazel and MODULE.bazel.
In most cases, a Bazel repository corresponds to a Git repository, and this training uses the terms interchangeably. However, Bazel also supports multiple or nested Bazel repositories within a single Git repository.
Starter repository
The codelab repo we cloned from Bazel shell starter contains a pre-configured Bazel repository. Your work repository will have many similar files, but if it uses an older Bazel version, there will be some differences. For example, older Bazel versions relied on aWORKSPACE file to install plugins.
Repository folder structure
Due to historical usage with the Perforce version control system at Google, Bazel always puts the files it creates outside the source tree in temporary folders. Use thebazel info command to see where Bazel stores temporary files:
bazel-out→$(bazel info execution_root)/bazel-outbazel-bin→bazel-out/[most recent target platform]/binbazel-testlogs→$(bazel info bazel-testlogs)
Standard Bazel files
MODULE.bazelallows this repository to participate in Bazel’s plugin dependency system (called “bzlmod”), either by publishing a module, or declaring dependencies on existing ones. We’ll cover the details in a later section.REPO.bazelis used to specify some common attributes for all build targets inside the repository. This is used with JavaScript to ignore thenode_modulesfolders. See Repo Bazel files..bazelversionfile indicates what version of Bazel should be used. It typically contains the exact version, to ensure identical results between developers and the CI system. However it’s also possible to use “floating” versions likelatest. See the bazelisk documentation..bazelrcstores persistent settings. We’ll cover this in detail in a later section..bazeliskrcis a less commonly-used configuration for Bazelisk, the version-aware wrapper we installed. This is where the Aspect CLI is selected.
Older Bazel versions required a
.bazelignore file instead, but it didn’t support glob patterns making it pretty hard to use. See bazelbuild/bazel#7093.
