docs/basics/hermeticity.mdx
This page covers hermeticity, the benefits of using hermetic builds, and strategies for identifying non-hermetic behavior in your builds.
When given the same input source code and product configuration, a hermetic build system always returns the same output by isolating the build from changes to the host system.
In order to isolate the build, hermetic builds are insensitive to libraries and other software installed on the local or remote host machine. They depend on specific versions of build tools, such as compilers, and dependencies, such as libraries. This makes the build process self-contained as it doesn't rely on services external to the build environment.
The two important aspects of hermeticity are:
The major benefits of hermetic builds are:
If you are preparing to switch to Bazel, migration is easier if you improve your existing builds' hermeticity in advance. Some common sources of non-hermeticity in builds are:
.mk files/usr/bin binaries, absolute
paths, system C++ compilers for native C++ rules autoconfiguration)Starting with local execution, issues that affect local cache hits reveal non-hermetic actions.
make and get a successful build,
running the build again should not rebuild any targets. If you run each build
step twice or on different systems, compare a hash of the file contents and
get results that differ, the build is not reproducible.--experimental_workspace_rules_log_file={{ '<var>' }}PATH{{ '</var>' }} to
your Bazel command.Note: Make your build fully hermetic when mixing remote and local execution, using Bazel’s “dynamic strategy” functionality. Running Bazel inside the remote Docker container will enable the build to execute the same in both environments.
For more information about how other projects have had success using hermetic builds with Bazel, see these BazelCon talks: