CMake vs Bazel, and how to get reproducible CMake builds
Teams look at Bazel for hermetic and repeatable builds. Wefti adds the configure side of that to a CMake project, and Bazel still does more.
Bazel gets hermetic builds by replacing your build files with Bazel files. Wefti keeps CMake and adds --hermetic=strict to reject undeclared reads during configure, --fetch-lock=frozen to pin FetchContent sources, and wefti cache export to move verified compiler probes between runners. Wefti does not sandbox compiler actions or run remote execution.
What hermetic means for a CMake project
A hermetic build reads only the inputs that it declares. In CMake, configure can read any environment variable, any file on disk, any program on PATH, and the network. Two machines can then configure the same source tree and get different results.
Bazel solves this by running each action in a sandbox and by asking you to declare every input in BUILD files. A move to Bazel means rewriting those build files. Wefti takes a smaller step. It audits what configure reads and pins what configure downloads.
| Area | Wefti 0.3.0 | Bazel |
|---|---|---|
| Project input | CMakeLists.txt, presets | BUILD files, MODULE.bazel |
| Rewrite from CMake | None | Every build file |
| Undeclared configure inputs | --hermetic=warn reports them and --hermetic=strict rejects them | Sandboxed actions |
| Pinned dependencies | wefti-fetch.lock for FetchContent archives and Git commits | Module lockfile and external repositories |
| Remote cache | Probe cache archives, HTTPS and S3 remote probe cache | Local and remote action cache |
| Remote execution | No | Yes |
Sources
The Bazel column comes from Bazel remote caching and Bazel sandboxing. The Wefti column comes from the tooling guide and the caching guide.
Make a CMake build more reproducible
Do these steps in order. Each one narrows the inputs of your configure step.
- Pin FetchContent sources. Run
wefti -S . -B build --fetch-lock=updateonce. Wefti writes archive hashes and Git commits towefti-fetch.lock. Commit that file. - Audit what configure reads. Run
wefti -S . -B build --hermetic=warn. The report lists undeclared environment reads, files outside the project, child processes, and network access. - Declare the inputs that you accept. Set
WEFTI_HERMETIC_ALLOW_ENV,WEFTI_HERMETIC_ALLOW_PATHS, andWEFTI_HERMETIC_ALLOW_PROGRAMSfor reads that you want to allow. - Freeze CI. Configure with
--hermetic=strict --fetch-lock=frozenandWEFTI_FETCH_OFFLINE=1. Frozen mode needs the lockfile and rejects a declaration that differs from its pin.
wefti -S . -B build --fetch-lock=update
wefti -S . -B build --hermetic=warn
WEFTI_FETCH_OFFLINE=1 wefti -S . -B build --hermetic=strict --fetch-lock=frozen
wefti cache export probes.tar.gz
What stays outside Wefti
The hermetic audit covers configure. It does not sandbox the compiler, the linker, or custom build commands, and it does not run actions on remote machines. If your repository needs sandboxed actions, remote execution, or one cache for every action at scale, Bazel does that work and Wefti does not.
Hermetic and profile runs turn off incremental replay, so use them for audits and for CI checks. Use a plain native configure when you want the fastest repeat.
A reproducible archive is a smaller goal that Wefti does reach. cmake -E tar and CPack archives record user and group 0, and wefti cache export writes the same bytes for the same cache content.
Frequently asked questions
Is Bazel better than CMake for reproducible builds?
Bazel sandboxes actions and tracks every declared input, so it goes further than CMake. A move needs new build files. Wefti keeps CMake and adds configure audits and lockfiles.
How do I make a CMake build hermetic?
Run --hermetic=warn to find undeclared reads, declare the ones you accept, and then use --hermetic=strict in CI. Add --fetch-lock=frozen so FetchContent downloads match pinned hashes.
Is there a lockfile for CMake FetchContent?
Wefti writes wefti-fetch.lock with --fetch-lock=update. It pins archive hashes and Git commits. The modes are off, auto, update, and frozen.
Can I run a CMake configure offline?
Yes, when a lockfile pins your sources. Configure with --fetch-lock=frozen and WEFTI_FETCH_OFFLINE=1. Wefti can download pinned sources before FetchContent_MakeAvailable() asks for them when you are online.
Does Wefti give me remote caching like Bazel?
Only for compiler probes. Wefti shares verified try_compile results through archives, and it supports HTTPS and S3 remote probe caches. It does not cache compiler output or run remote execution.
Do cmake and ctest run the hermetic checks?
No. The names cmake, ctest, cpack, and ccmake select compatibility mode, which behaves like CMake 4.5.1. Run the native wefti command to use --hermetic and --fetch-lock.