This post is based on the BazelCon 2026 talk I gave with Antonio Di Stefano
(Frekt.dev). You can watch the recording on YouTube
below.
Bazel has used persistent
workers for years to
make compilation faster. A persistent test runner applies the same idea to
tests: keep a long-running test execution process alive and reuse it across
multiple tests, instead of paying its warmup cost every time.
This "Maintaining Compatibility" trilogy began by describing how to, well,
maintain compatibility with Bzlmod builds, legacy WORKSPACE builds, and a
range of dependency versions. However, this was only half the story. Automated
testing is essential for validating our compatibility assertions, not lying to
ourselves and our users, and preventing the undoing of our hard work.
The previous post described how to write and run tests
that enable switching between Bazel versions and the Bzlmod and legacy
WORKSPACE build modes. Those tests use the latest versions of our non-Bazel
dependencies to ensure forward compatibility.
This fourth and final part of our trilogy describes how to write tests to
validate backwards compatibility with combinations of older dependency
versions. We'll build on the techniques from the previous post, while learning
what makes these backwards compatibility tests substantially different from
other tests in the suite.
We've covered techniques for ensuring that your project remains compatible with
different Bazel versions, both Bzlmod and legacy WORKSPACE builds, and older
dependency versions. However, we shouldn't make any promises until we've
validated that these properties actually hold, preferably via automated testing
and continuous integration.
This third post in our four part trilogy covers writing Bazel tests that
allow for flexibly switching between various Bazel configurations. We'll
consider advice on how to run the tests locally while developing and how to run
them in continuous integration.
In the previous post, we reviewed guidelines for
maintaining compatibility with both Bzlmod and legacy WORKSPACE builds, and
older and newer dependency versions. I promised that in this post and the next,
we'd discuss testing approaches to help ensure that this remains the case.
However, a discussion in the Bazel Slack workspace has revealed a Bzlmod and
legacy WORKSPACE compatibilty issue I'd missed in the previous post. So in
this post, I'll discuss what to do with the class of legacy WORKSPACE
configuration macros that use Label with computed repository names.
As we'll see, this one issue alone ended up meriting a substantial post in
itself. We'll cover adding dependency attributes to repository rules, generating
.bzl files to resolve Labels, chaining together module extensions, and using
macros in generated BUILD files. The former two options are relatively
straightforward, but we cover the latter two options in case your use case
requires them.
Such legacy WORKSPACE macros commonly seem to pertain to toolchain
configuration, selecting repositories to instantiate based on user defined
parameters. So we'll use a small example project to illustrate these solutions
as they apply specifically to toolchain configuration.
As we're well aware by now, Bzlmod is the new hotness, and WORKSPACE is old and
busted and going away in Bazel 9. However, Bazel 8 still supports
WORKSPACE, and thus legacy WORKSPACE usage won't completely disappear for
some years yet. Despite the Bazel community's efforts to help facilitate Bzlmod
migrations (including this blog series), some projects may remain unable to
migrate sooner than later.
What's more, publishing your repository for use by other projects raises the
challenge of supporting a range of older and newer versions of its dependencies.
Your repository should work with the newest versions of Bazel, rules_java,
protobuf, and other dependencies in order to stay current. However, not every
project that could benefit from the latest version of your repository will want
to upgrade these other dependencies right away.
This post describes how to design a repository to remain compatible with both
WORKSPACE and Bzlmod, and with newer and older dependency versions. Just as
importantly, in the next two posts, we'll discuss testing approaches to help
ensure that this remains the case.
One of Bazel’s key features is that tests are treated as the same as other build actions. Bazel provides a uniform command line interface for running tests no matter the underlying language or test framework. While there’s much to be said about writing test rules and frameworks that mesh well with Bazel, this post will focus on the experience of running tests as a developer with bazel test. Running tests is a core software engineering workflow, so it’s not surprising Bazel has many useful features for iterating locally with a test.