Repository navigation
mbx 2.0 makes CI builds incremental. Until now, a CI job that changed one crate compiled that crate from nothing, because rustc's incremental state stayed on a runner that no longer exists. In 2.0 the cache stores that state with each workspace crate's result, so a later job that has to compile the crate starts from the earlier job's state, like a rebuild on your own machine. It works with every cache: the local store, the GitHub Action, an S3 bucket and the mbx cache server. It is on by default in CI and needs no configuration.
2.0 also cleans up target directories: mbx now removes build units that are no longer used from every target directory it builds into, so target/ stops growing without limit.
Both features are on by default, and both change what an existing setup does. Read "Upgrading from 1.x" below before you update. This release also stops build scripts from reporting stale commit hashes, stops builds from slowing down when the remote cache is unreachable, and restores binaries as writable files.
Incremental CI builds
Added in #1086.
-
A workspace crate's cached result now includes the incremental state rustc compiled it with. A later build that misses on that crate fetches the state and compiles from it. A build that hits downloads no state.
-
It is on when
CIorGITHUB_ACTIONSis set.MBX_SHARED_INCREMENTAL=0(orshared_incremental = falsein.mbx.toml) turns it off, andMBX_SHARED_INCREMENTAL=1turns it on for local builds. Local builds outside CI are unchanged. -
The state only helps when rustc would have reused it locally: the same checkout path, toolchain, target, profile, features and flags. LTO compiles, and optimized compiles that would run local ThinLTO, keep no state.
-
If the state is missing or damaged, the crate compiles from scratch and the build continues.
-
The build summary reports the state it fetched and packed:
mbx[cache]: incremental state: 1 compilations started from fetched state (68.8 MiB fetched in 32.1ms, 206.2 MiB unpacked in 203.9ms); 1 units packed (67.6 MiB in 103.7ms) -
In CI on filesystems that can't clone files, such as ext4, compiler outputs enter the store by hard link (
store_hardlink, Unix only), so each output is written once instead of twice. -
The store refuses a write that would leave less than
gc.store_reserve_size(default 2 GiB) free on the disk. The build continues without storing that result. -
The costs: a CI job with an empty cache takes longer than before, and the cache grows by each workspace crate's packed state.
Target directory cleanup
Added in #1086.
mbx removes unused build units and stale incremental state from every target directory it builds into, including one that CARGO_TARGET_DIR names. A unit is removed when one of these applies:
- no build has used it for
target.max_age(30 days) - a newer build of the same crate replaced it a week ago
- it is an older build of a test or program beyond
target.max_executable_builds - the compiler that built it is uninstalled
The top-level programs and libraries of a profile are never removed, and neither is anything in a directory that no mbx build has used. mbx gc --dry-run shows what a sweep would remove.
Units of replaced dependency versions are also removed sooner (#1079). In managed target directories, units built from a registry version that Cargo.lock now lists only at other versions are removed, along with every unit built against them. This happens once a successful mbx build has used the new lockfile for a day and the units have gone untouched for two days. It also works on filesystems without access times, such as APFS, and requires Cargo 1.100 or later. To turn it off:
[target]
prune_outdated_dependencies = false # or MBX_TARGET_PRUNE_OUTDATED_DEPENDENCIES=falseGitHub Action
jdx/mr-boxington-action 1.8.0 is released under @v1, so workflows need no change. It installs the latest mbx unless version pins one or an mbx is already on PATH. With the GitHub cache backend it now:
- Restores a fresh runner's target directory so that unchanged workspace crates are not rebuilt. Source files get back the modification times they had in the job that saved the cache (
restore-source-times). On Linux, a job that only restores leaves out the files its build will write again (selective-restore). - Puts back files that a workspace build script generated beside its sources in a path git ignores, so that script does not run again in every job (
restore-generated-files). - Reads the compiler into memory while the cache restores, on Linux (
compiler-warm). - Raises the kernel's dirty-page limits on GitHub-hosted Linux runners, so a restore is not held to the disk's write speed (
raise-dirty-page-limits). - Downloads the cache archive to memory on Linux when at least 4 GiB is available, and tries once more on disk when that restores nothing.
Each named input is "true" by default, and "false" turns it off.
Benchmarks
Restore plus build time in seconds, for a job with no source change and for a job after a commit. Every job ran on a fresh GitHub-hosted ubuntu-26.04 runner with rustc 1.100.1 and restored what one earlier job had saved. Each figure is the median of five jobs, except the two marked as four. rust-cache is Swatinem/rust-cache v2.9.3 and kache is 2.5.0, both with their default settings. mbx was measured twice: with its cache directory kept by actions/cache, and with the GitHub Action at its defaults.
| Project | Case | Plain Cargo, no cache | rust-cache | kache | mbx, actions/cache |
mbx, action |
|---|---|---|---|---|---|---|
| mise | no change | 418.6 | 287.7 | 258.6 | 72.6 | 63.4 |
| mise | after a commit | 458.0 | 265.9 | 287.3 | 110.4 | 101.7 |
| hk | no change | 80.7 | 16.5 | 41.5 | 9.8 | 12.7 |
| hk | after a commit | 84.3 | 18.8 | 49.7 | 15.8 | 14.9 |
| aube | no change | 138.8 | 51.3 (four jobs) | 41.7 | 41.5 | 30.6 |
| aube | after a commit to its top crate | 119.3 | 45.7 | 73.1 | 57.2 | 40.8 |
| aube | after a commit to aube-resolver |
143.9 | 48.9 (four jobs) | 71.8 | 60.6 | 43.4 |
What to know when reading the table:
- The gap depends on the project. mise has one large crate of its own, and there mbx with the action is 2.6 to 4.5 times faster than rust-cache and kache. hk and aube are short builds and the rows are close: mbx with the action is 3 to 6 s ahead of the next fastest row, which five jobs do not separate. On aube, mbx with
actions/cachewas slower than rust-cache after a commit. - Most of mbx's time is the restore, and its cache entry is the largest. On mise the entry is 3,048 MB with the action, against 1,268 MB for rust-cache's and 1,618 MB for kache's.
- The first build, with an empty cache, is slower than plain Cargo. On mise it took 426.8 s with the action and 568.3 s with
actions/cache, against about 419 s for plain Cargo. - Disk. mise's first build through the action left a 10.7 GB target directory and a 9.0 GB mbx cache. On a GitHub-hosted runner of a private repository, which had 14.7 GB free, an earlier build of 2.0 ran out of disk during that first build. That was not tried again with the release.
- Why the others take the time they do. rust-cache leaves workspace crates out of what it saves, so Cargo compiles them in every job. kache 2.5.0 misses the run of some build scripts when the registry sources have been unpacked again, as they are on a fresh runner. mise's build script records the build time, so mise's own crate then compiles again. A workflow that also restores Cargo's unpacked sources with their old timestamps was not measured. With
KACHE_CACHE_EXECUTABLES=0, which is not kache's default, kache took 262.0 and 222.0 s on mise. - Two of rust-cache's figures on aube are the median of four jobs. One job in each of those cases landed on a runner with an older image, where rust-cache computed another key and restored nothing. Those two jobs were left out and were not run again.
- These runs used a build of mbx and of the action from shortly before the release, not the released binaries. Fixes made in review after the runs are in the release.
The full tables, with the range of every figure, the kache row with KACHE_CACHE_EXECUTABLES=0, the commits and the method, are in the description of #1086.
Upgrading from 1.x
There is nothing to configure: update mbx. These are the changes an existing setup will see.
-
CI builds compile workspace crates once after upgrading. Results stored with incremental state have new keys, so the first CI run compiles workspace crates, including their build scripts, once. Dependencies keep their cached results. To keep the 1.x behavior, set
MBX_SHARED_INCREMENTAL=0. -
Some files in
target/are read-only in CI. Freshly compiled libraries, proc macros, build-script executables and test harnesses share a file with the store. If a later step runs plaincargoin the same target directory, it can fail withoutput file ... is not writeable. Run that step through mbx, or setMBX_STORE_HARDLINK=0. Binaries, examples andcdyliblibraries are still writable copies. -
Cleanup now covers every target directory mbx builds into, including one that
CARGO_TARGET_DIRnames. To protect directories or turn off the age-based rules:[target] keep = ["/data/shared-target", "~/src/app"] # or turn off the rules, keeping only size budgets and low-disk collection: max_age = "none" max_executable_builds = "none"
gc.auto = falsestops automatic sweeps entirely. -
Mixed versions sharing a cache.
- 1.x and 2.0 machines can share a remote cache namespace while a fleet updates. 2.0 writes separate (generation 2) task manifests and leaves the ones 1.x reads alone. 1.x keeps its own hits but doesn't reuse what 2.0 records.
- If 1.x shares a local store with 2.0, its collection removes packed incremental state, and
mbx cache importleaves it out. 2.0 then compiles those crates from scratch once. - The shim/agent protocol is now version 16.
-
MBX_VERIFY=1turns incremental CI builds off for the build it verifies. -
The
ra-jitfallback for blaze has been removed (#1088). With the experimentalMBX_BLAZE=1, the Cargo shim now looks only forblaze. Ifblazeisn't onPATH, it warns and builds with Cargo. Install a current blaze release to keep routed builds. -
Library crates.
mbx-cache-core0.24.0 andmbx-cache-rustc0.24.0 add public fields, includingRestoreStats::avoided_compiler_cpu_ns,CompileMetadata.shared_state,AgentRequest::StoreBlob.link,RustcInputPrediction::prefetch_groupandRustcInputPrediction::compiler_cpu_ns. Code that builds these structs field by field needs updating.
Also added
mbx statsseparates local and remote hits and records compiler CPU time (#1068, requested by @kixelated in #1067).savings.hit_sourcesinmbx stats --jsonholds running totals of hits, wall time avoided and CPU time avoided for each source. The text report shows matchinghit sourcesandcompiler CPU avoidedrows. A hit counts as remote when it is the first use of a result this build fetched from the remote. CPU time is measured on Unix only and for rustc hits only, andcpu_timed_hitssays how many hits have a value. The totals start counting with this release.- Prefetch downloads only the profile being built (#1062, reported in #1055). Before, when dev and release builds shared one remote cache, the first predicted hit prefetched both profiles' outputs. Now it prefetches only predictions with the same target and profile codegen settings. In one measurement, a release restore went from 332.6 MB downloaded to 102.7 MB. Which outputs are restored, and the hit counts, are unchanged.
- More flags are cached. Builds that pass
-C unsafe-allow-abi-mismatch=…(#1058, discussion 1056),-Zub-checksor-Zmir-enable-passes(#1076, discussion 1075) now use the cache instead of bypassing it. Each value is part of the cache key. Malformed values still bypass.
Fixed
Remote cache and restores
-
An unreachable remote cache no longer slows builds down (#1065). Before, every lookup and upload against a remote that refused connections was retried with backoff. One build took 288 s instead of 22 s and printed thousands of warnings. Now, after three failed connections in a row, mbx warns once and skips the remote. It checks the remote in the background and starts using it again when it answers. This applies to cache servers and
s3://remotes. Error responses such as a 500 don't count as failed connections.- The JSON build report gains a
remote_skippedfield. - The CI summary now says
N background uploads were not published, notfailed. - A remote connection now gets slightly less than
http.timeoutto open (29 s by default), so a host that drops packets is also detected.
- The JSON build report gains a
-
Restored binaries are writable (#1070). On filesystems that can't clone files, such as ext4, a restored binary used to be a read-only hard link to the store, so
strip target/debug/appfailed withPermission denied. The following are now restored as separate, writable copies:- binaries and examples
harness = falsetests and benchescdylib,dylibandstaticliblibraries
.rliband.rmetafiles, proc macros, build scripts and test harnesses are still hard linked. Each restored binary now takes up its own disk space. -
Native library directories with internal aliases are cached (#1077). Before, a
-L nativedirectory containing symlinks to other directories in the same tree, such as Debian's/usr/lib/aarch64-linux-gnu, made crates compile on every fresh-target build. Those aliases are now followed and hashed under the names mbx searched. Links that point outside the tree, dangling links and cycles still bypass the cache. -
Large C dependencies no longer push workspace crates out of the task manifest (#1072). With a dependency like aws-lc-sys, the 15 MiB manifest could fill up, and the next CI job compiled some workspace crates without a cache lookup. Three changes fix this:
- C/C++ predictions are about half their previous size.
- When the manifest overflows, mbx drops the predictions that save the least compiler time per byte.
- A command that only hit now refreshes its entries when the manifest is near its size limit.
Build scripts
- Build scripts that embed the commit hash run again when
HEADchanges (#1071, #1074). Before, a script that rangit rev-parse HEADwithout declaring git files was replayed from the cache, so a fresh CI checkout's binary reported the previous commit. mbx now searches the script's output andOUT_DIRfor the current commit (in full, or abbreviated to at least seven characters). If the commit is there, the result is keyed on it.- If git can't read the repository, for example because of
detected dubious ownership, mbx doesn't cache the result (build-script-unreadable-headbypass). Adding the checkout tosafe.directorymakes the result cacheable again. - After upgrading, each workspace build script runs once.
- Tag-only
git describeoutput, dirty-tree flags and build timestamps are still not detected.
- If git can't read the repository, for example because of
- Build scripts run again when an external link directory is missing (#1087, reported by @ThomasSteinbach in #1084). A script such as
ort-sysdownloads a library to~/.cacheand printscargo:rustc-link-search=native=<dir>. Before, on a machine where that directory didn't exist, mbx replayed the run and linking failed withcannot find -l…. If a directory the script filled is now gone, the script runs again. mbx checks only that the directory exists, not what is in it. Indentedcargo:directives are now recognized. - Build-script results that embed only
CARGO_HOMEare shared across checkouts (#1059, discussion 1053). Before, a script whose output contained any root path, such as aws-lc-sys embedding its registry source path, ran again in every checkout. Results that embedCARGO_HOMEor a registry source directory are now reused by checkouts that share the same Cargo home. Results that embed checkout-local paths still run again.
Other
- A
RUSTC_WRAPPERthat mbx defers to keeps incremental compilation (#1085, discussion 1078). When another tool is theRUSTC_WRAPPER, mbx no longer forcesCARGO_INCREMENTAL=0. An inherited value or Cargo's profile settings apply instead. If you relied on those builds being non-incremental, setCARGO_INCREMENTAL=0yourself. - A
clang-cllink to mbx'sclangshim runs clang incl.exemode (#1080). cargo-xwin creates this kind of link. Before, it printed mbx's own version or help. These compilations are not cached.
Full Changelog: v1.32.0...v2.0.0
AI-assisted — Tool: Claude Code; model: anthropic/claude-fable-5-2; version: 2.1.331.