Wefti

How to cache CMake configure in CI

Every new CI runner repeats the same compiler checks. Wefti stores verified check results, moves them between runners in one archive, pins FetchContent sources, and audits what configure reads.

Configure with the native wefti command and set WEFTI_PROBE_CACHE_DIR to keep SHA-256 verified compiler checks. Move them between runners with wefti cache export probes.tar.gz and wefti cache import probes.tar.gz --sha256 <digest>. In v0.3.0, the synthetic warm-probe configure ran 7.65x as fast as CMake 4.5.1, and the geometric mean for five large projects was 2.17x.

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. Reads verified entries and records new ones.
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.

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

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.3.0/scripts/install.sh
          bash install.sh --version 0.3.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.3.0/scripts/install.sh
          bash install.sh --version 0.3.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 an HTTPS endpoint to let native configure recover probe entries from a shared server. Wefti verifies the remote entry and its recorded inputs before it uses the entry. Remote access is read-only by default, and an empty or unset value turns it off.

Remote probe 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_WRITESet to 1 to allow uploads. Uploads also need WEFTI_CACHE_REMOTE_EXPORT_CAPTURED_OUTPUT=1.
WEFTI_OFFLINESet to 1 (or set WEFTI_FETCH_OFFLINE=1) to turn off remote probe cache access.

Configure gives remote access a budget of 3 seconds. Wefti passes the URL and credentials to curl on standard input, so they do not appear on the command line or on disk.

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.3.0 local FetchContent warm-fetch benchmark, Wefti read cached content with the origins hidden and ran 1.73x as fast as CMake 4.5.1, which fetched with the origins visible (175.50 ms and 303.26 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.3.0 results

The synthetic warm-probe configure ran 7.65x as fast as CMake 4.5.1. Across five large projects, the warm probe cache geometric mean was 2.17x, with OpenCV at 4.38x. 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.3.0
WorkloadSpeedup
Synthetic warm-probe configure7.65x (602.60 ms and 4608.06 ms)
OpenCV4.38x
DuckDB2.29x
Protobuf1.88x
LLVM1.70x
Qt Base1.51x
Geometric mean of the five large projects2.17x
Local FetchContent warm-fetch1.73x

Probe cache gates passed 16 / 16 checks in v0.3.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?

Configure once with the native wefti command, run wefti cache export probes.tar.gz, and upload the archive and its SHA-256 digest as artifacts. In the next job, run wefti cache import probes.tar.gz --sha256 with that digest before you configure.

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?

No. The cmake, ccmake, ctest, and cpack names and WEFTI_ORACLE_MODE=1 select compatibility mode, which turns off the probe cache, incremental replay, and drift checks. Use the wefti command for configure to use the cache.

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.