Practical Bazel

Practical Bazel: Supporting Trinary Stamp Attributes
Practical Bazel bazel stamping
Published: 2023-03-06
Practical Bazel: Supporting Trinary Stamp Attributes

In Bazel, stamping is the process of embedding additional information into built binaries, such as the source control revision or other workspace-related information. Rules that support stamping typically include an integer stamp attribute, where 1 means “always stamp”, 0 means “never stamp”, and -1 means “use the Bazel build --stamp flag. This blog post explains how to write a rule that supports these values.

Read more...
Practical Bazel: local_archive() Workspace Rule
Practical Bazel bazel
Published: 2023-03-01
Practical Bazel: local_archive() Workspace Rule

In general, one should never check in binary artifacts into Git; it is better to retrieve them from an artifact repository or a website using http_archive(). However, sometimes convenience is more important than ideological purity. To handle these cases, I wrote a simple workspace rule named local_archive().

Read more...
Practical Bazel: Building Multiple Workspaces in CI
Practical Bazel bazel
Published: 2022-10-18
Practical Bazel: Building Multiple Workspaces in CI

For most Bazel projects, I strongly recommend using a single Bazel workspace per source code repository. However, it can be occasionally useful to nest multiple workspaces within a single repository. For example, when I’m writing Bazel rulesets, I will often create test cases that contain own workspace with a slightly different configuration in order to test various workspace-level configuration settings for the ruleset, while maintaining a root workspace which is the primary workspace for the ruleset.

Read more...
Practical Bazel: Use a Single .bazelrc With Multiple Configurations
Practical Bazel bazel
Published: 2022-10-17
Practical Bazel: Use a Single .bazelrc With Multiple Configurations

Bazel users commonly need to manage multiple different configurations when building and testing software, such as:

  • A configuration that is used by developers on their own PCs, which often has debug mode turned on
  • A configuration that is used by the continuous integration (CI) default build and test pipeline, which often builds in release mode
  • A configuration for generating a tagged, version release, which often has stamping enabled
  • (Perhaps many more)
Read more...
Practical Bazel: Implementing compilation_mode in Rules
Practical Bazel bazel
Published: 2022-10-13
Practical Bazel: Implementing compilation_mode in Rules

As developers know, virtually all compilers support the notion of compilation mode, e.g.. whether to compile the code in debug or release mode. In Bazel, this concept is built natively into the build system itself. When compiling software using bazel build, one can select a compilation mode using the --compilation_mode (often shorted to -c) flag.

Read more...