Wefti

How to cache CMake configure in CI

Every new CI runner repeats the same compiler checks. Wefti v0.4.0 can share verified compiler checks and configure results through a remote cache.

Configure with the native wefti command. Use setup-wefti on GitHub Actions, an HTTPS or S3 remote cache, or a portable probe archive to reuse results on another runner. In v0.4.0, the synthetic warm-probe configure ran 7.30x as fast as CMake 4.5.1. The geometric mean speedup with a warm probe cache was 2.21x across five large projects.

How the compiler probe cache works

The native wefti command stores each eligible compiler check result, such as try_compile(), check_include_file(), and check_symbol_exists(), in a content-addressed cache. Each entry records its inputs: absolute paths and SHA-256 digests of the compiler binary, headers, and configuration files. A later configure uses an entry only when every recorded input still matches.

The recorded inputs include the compiler driver configuration. For Clang, Wefti records the .cfg configuration files that the driver can read, for example clang.cfg and <triple>-clang++.cfg. For GCC, it records the specs file, cc1 or cc1plus, as, collect2, ld, and libgcc. If one of these files changes, the check runs again.

Probe cache modes
WEFTI_PROBE_CACHEBehavior
readwriteDefault in the wefti command. Reads verified entries and records new ones. on and 1 mean the same.
readonlyReads verified entries and records nothing.
verifyRuns each check again, compares it with the cached hit, and uses the fresh result. Incremental replay is off in this mode.
offRuns every check live. This is the default when the binary runs as cmake.

Native mode runs independent literal compile probes in parallel. WEFTI_PROBE_JOBS sets the number of jobs (up to 32). The default is the smaller of 16 and the number of logical CPUs, lowered by available memory (2 GiB reserved plus 1 GiB per job). Set WEFTI_PROBE_JOBS=1 to run checks in sequence. Use wefti cache status, wefti cache dir, and wefti cache clear to inspect or clean the cache.

Share the probe cache between CI runners

Export verified entries to one archive in a trusted job, and import that archive with its SHA-256 digest on the other runners.

  1. Install the same Wefti release. Install the same Wefti release on the producer and consumer runners. Use the same runner image, compiler, and toolchain paths.
  2. Fill the probe cache. Set WEFTI_PROBE_CACHE_DIR and configure once with the native wefti command to record verified compiler probes.
  3. Export the archive and its digest. Run wefti cache export probes.tar.gz in a protected job and save the SHA-256 digest of the archive as a separate file.
  4. Import with the trusted digest. On the consumer runner, run wefti cache import probes.tar.gz --sha256 with the digest from the producer job, then configure.
  5. Check the build tree for drift. Run wefti doctor -B build to find a stale CMakeCache.txt after a compiler, toolchain file, or prefix path change.
export WEFTI_PROBE_CACHE=readwrite
export WEFTI_PROBE_CACHE_DIR="$HOME/.cache/wefti-probes"
wefti -S . -B build -G Ninja
wefti cache export probes.tar.gz
sha256sum probes.tar.gz | cut -d ' ' -f 1 > probes.sha256

Export writes a deterministic gzip tar archive. It skips locks, temporary files, FetchContent data, and credentials, and it prints the SHA-256 digest of the archive. The archive contains compiler paths, compiler flags, and captured compiler output, so treat it like build logs.

export WEFTI_PROBE_CACHE_DIR="$RUNNER_TEMP/wefti-probes"
wefti cache import probes.tar.gz --sha256 "$(cat probes.sha256)"
wefti -S . -B build -G Ninja
With --sha256 (trusted)
The digest must match the archive and come from a trusted producer. Import publishes the entries into the live probe cache and keeps valid local entries.
Without --sha256 (untrusted)
Import stages the entries as candidates outside the live cache. Candidates never cause a cache hit. They can only repair a missing or damaged blob of a matching local entry.

Import validates the full archive before it writes anything, and a failure changes nothing. Read the digest from the producer artifact, not from the cache, so that one writer cannot change both the archive and the digest. Pull request jobs that restore a main archive should import without --sha256 or skip the import.

GitHub Actions workflow

The Node.js 24 setup action enables GitHub Actions Cache v2 for later steps. Wefti restores a cache pack during configure and saves a pack after a successful configure that writes new entries, if the write policy allows it.

steps:
  - uses: actions/checkout@v6
  - uses: wefti/wefti/actions/setup-wefti@v0.4.0
    with:
      version: v0.4.0
  - run: wefti -S . -B build
  - run: wefti cache status

See the GitHub Actions guide for cache settings.

Share a portable probe archive

Save this workflow as .github/workflows/wefti.yml and run it on a protected main branch. The first job exports the archive and its digest. The build job imports both from the same run. The native wefti command does the configure, and the cmake and ctest aliases keep the existing build and test commands.

name: Build with wefti
on:
  push:
    branches: [main]

permissions:
  contents: read

env:
  WEFTI_PROBE_CACHE: readwrite
  WEFTI_PROBE_CACHE_DIR: ${{ github.workspace }}/.wefti-probes

jobs:
  prepare-probes:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - name: Install wefti and Ninja
        run: |
          sudo apt-get update
          sudo apt-get install -y ninja-build
          curl -fsSLO https://raw.githubusercontent.com/wefti/wefti/v0.4.0/scripts/install.sh
          bash install.sh --version 0.4.0 --alias-cmake
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      - name: Configure and export verified probes
        run: |
          wefti -S . -B build -G Ninja
          wefti cache export probes.tar.gz
          sha256sum probes.tar.gz | cut -d ' ' -f 1 > probes.sha256
      - uses: actions/upload-artifact@v4
        with:
          name: wefti-probes
          path: |
            probes.tar.gz
            probes.sha256
          if-no-files-found: error

  build:
    needs: prepare-probes
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - name: Install wefti and Ninja
        run: |
          sudo apt-get update
          sudo apt-get install -y ninja-build
          curl -fsSLO https://raw.githubusercontent.com/wefti/wefti/v0.4.0/scripts/install.sh
          bash install.sh --version 0.4.0 --alias-cmake
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      - uses: actions/download-artifact@v4
        with:
          name: wefti-probes
      - name: Import probes and run the build
        run: |
          wefti cache import probes.tar.gz --sha256 "$(cat probes.sha256)"
          wefti -S . -B build -G Ninja
          cmake --build build
          ctest --test-dir build --output-on-failure

Optional HTTPS or S3 remote cache

Set WEFTI_CACHE_REMOTE to the HTTPS endpoint of a shared cache to reuse compiler probes and configure results such as compiler identification and recorded platform checks. Wefti verifies remote entries against local inputs before it uses them. Replay journals and Ninja generation records stay in the local build directory.

HTTP and S3 transfer individual entries and data files by default. Set WEFTI_CACHE_REMOTE_MODE=pack to transfer a single archive during configure.

Remote cache settings
VariableEffect
WEFTI_CACHE_REMOTEHTTPS endpoint URL. Plain HTTP is rejected.
WEFTI_CACHE_REMOTE_AUTHanonymous (default), bearer, header, or s3. The s3 mode reads AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optional AWS_SESSION_TOKEN.
WEFTI_CACHE_REMOTE_HEADERCustom HTTP header name required when WEFTI_CACHE_REMOTE_AUTH=header.
WEFTI_CACHE_REMOTE_TOKENBearer token or custom header value.
WEFTI_CACHE_REMOTE_TRUSTHTTP and S3 default to pinned, which requires an identical trusted local entry. Use signed with a shared WEFTI_CACHE_REMOTE_KEY to verify signed entries.
WEFTI_CACHE_REMOTE_WRITEHTTP and S3 uploads require WEFTI_CACHE_REMOTE_WRITE=1 and WEFTI_CACHE_REMOTE_EXPORT_CAPTURED_OUTPUT=1.
WEFTI_OFFLINESet to 1 or set WEFTI_FETCH_OFFLINE=1 to turn off remote cache access.

For backend settings and trust policies, see the caching reference.

Pin FetchContent sources for offline CI

Use --fetch-lock to pin archive hashes and Git commits in wefti-fetch.lock in the source directory. The modes are off, auto (default), update, and frozen. Frozen mode requires the lockfile and rejects a declaration that differs from its pin before any cache lookup or transfer.

wefti -S . -B build -G Ninja --fetch-lock=update
git add wefti-fetch.lock

WEFTI_FETCH_OFFLINE=1 wefti -S . -B build -G Ninja --fetch-lock=frozen

WEFTI_FETCH_OFFLINE=1 blocks FetchContent and ExternalProject network transfers and keeps local and cached sources. WEFTI_FETCH_LOCK_FILE changes the lockfile path. In the v0.4.0 local FetchContent warm-fetch benchmark, Wefti read cached content with the origins hidden and ran 1.72x as fast as CMake 4.5.1, which fetched with the origins visible (148.50 ms and 254.95 ms).

Audit configure inputs with --hermetic

Add --hermetic (or --hermetic=warn) to report undeclared environment reads, file reads, child processes, and network access during configure. Use --hermetic=strict to reject them. CI can then show that configure reads only the inputs that you declare.

wefti -S . -B build -G Ninja --hermetic=strict

Allow known inputs with WEFTI_HERMETIC_ALLOW_ENV, WEFTI_HERMETIC_ALLOW_PATHS, and WEFTI_HERMETIC_ALLOW_PROGRAMS. Each takes a semicolon-separated list. WEFTI_HERMETIC selects off, warn, or strict from the environment. Hermetic mode turns off the probe cache, parallel probes, incremental replay, and FetchContent prefetch for that configure, so use it in an audit job and not in every build.

Detect a stale CMakeCache.txt with wefti doctor

Run wefti doctor -B build to find compiler, toolchain file, launcher, or prefix path changes since the last fresh configure. It reads CMakeCache.txt and the drift receipt at CMakeFiles/wefti/toolchain-inputs-v1.json. It does not run compilers or project scripts, and it never changes the cache.

wefti doctor -B build
wefti --fresh -S . -B build -G Ninja

The exit code is 0 for a clean tree, 1 for drift, missing tool files, an invalid receipt, or a missing build directory, and 2 for invalid arguments. To recover, configure again with --fresh and the same -D options, or use a new build directory.

Verified v0.4.0 results

The synthetic warm-probe configure ran 7.30x as fast as CMake 4.5.1. Across five large projects, the geometric mean speedup with a warm probe cache was 2.21x. All runs used an Apple M1 with 16 GiB of memory. The complete benchmark report lists every workload.

Warm probe cache configure speedups in v0.4.0
WorkloadSpeedup
Synthetic warm-probe configure7.30x (468.31 ms vs 3,417.55 ms)
OpenCV3.85x
DuckDB2.37x
Protobuf2.17x
LLVM1.69x
Qt Base1.58x
Geometric mean of the five large projects2.21x
Local FetchContent warm-fetch1.72x

The probe cache passed 16 / 16 soundness checks in v0.4.0. A warm-probe run starts from a new build tree with a filled probe cache. Your speedup depends on how many compiler checks your project runs.

Frequently asked questions

How do I cache CMake configure results in GitHub Actions?

Add wefti/wefti/actions/setup-wefti@v0.4.0 and configure with wefti -S . -B build. Wefti uses GitHub Actions Cache v2 to share verified probes and configure results between runners. Run wefti cache status after configure to see what was restored.

Is it safe to import a probe cache from another runner?

Import with --sha256 only when the digest comes from a trusted producer, such as a protected main branch job. Without --sha256, Wefti stages the entries as untrusted candidates that never cause a cache hit. Import validates the full archive before it writes anything.

Why does an imported probe cache miss on my runner?

Each entry records absolute paths and SHA-256 digests of the compiler binary, headers, and configuration files. An entry hits only when the runner has the same compiler bytes at the same path. A compiler upgrade or a path change misses safely and runs the check again.

Does the cmake alias use the probe cache?

Yes, from version 0.3.1, when you set WEFTI_PROBE_CACHE=on. The cmake, ccmake, ctest, and cpack names keep the cache off by default. Incremental replay, the Ninja skip, and drift checks stay off in compatibility mode, and WEFTI_ORACLE_MODE=1 always turns the cache off.

How do I run FetchContent offline in CI?

Record pins once with --fetch-lock=update and commit wefti-fetch.lock. In CI, configure with --fetch-lock=frozen and WEFTI_FETCH_OFFLINE=1. Frozen mode requires the lockfile and rejects a declaration that differs from its pin.

How do I detect a stale CMakeCache.txt?

Run wefti doctor -B build. It compares the drift receipt with the current compiler, toolchain file, and CMAKE_PREFIX_PATH without running compilers or project scripts. It exits with 0 when the tree is clean and 1 when it finds drift.