Summary
The kpm-build (macos-latest) job in .github/workflows/ci.yml flakes intermittently with rustup-init: unexpected argument 'build' found when Swatinem/rust-cache@v2 restores a cache containing a stale cargo shim. The cached shim overwrites the fresh binary just installed by dtolnay/rust-toolchain@stable, and subsequent cargo build invocations are interpreted as rustup-init build.
Linux and Windows are unaffected.
Environment
- Workflow:
.github/workflows/ci.yml job kpm-build, matrix macos-latest
- Runner: GitHub-hosted macOS arm64 (Darwin-arm64)
- Actions:
dtolnay/rust-toolchain@stable
Swatinem/rust-cache@v2
Reproduction Steps
Non-deterministic — depends on cache state of the runner. Observed on PR #130 (commit pushed twice on the same branch):
- Push to a branch that triggers
kpm-build.
- First run (#25870337001 at 15:56 UTC) — green ✅
- Re-trigger the workflow on the same commit (#25870675080 at 16:03 UTC) — macOS failed, Linux+Windows green
- Re-run the failed job — green again ✅ (cache rebuilt from scratch)
Expected Behavior
cargo build -p webarkitlib-rs --features ffi-backend runs the toolchain installed by dtolnay/rust-toolchain@stable.
Actual Behavior
$ cargo build -p webarkitlib-rs --features ffi-backend
error: error: unexpected argument 'build' found
Usage: rustup-init[EXE] [OPTIONS]
For more information, try '--help'.
Process completed with exit code 1.
The cargo binary on PATH resolves to rustup-init (the bootstrap installer), not real cargo. This happens after Swatinem/rust-cache@v2 restores /Users/runner/.cargo/bin/ from cache key v0-rust-kpm-build-Darwin-arm64-9d946206-575a3e0f.
Error Details
2026-05-14T16:03:27.8362710Z ##[group]Run cargo build -p webarkitlib-rs --features ffi-backend
2026-05-14T16:03:27.9682690Z error: error: unexpected argument 'build' found
2026-05-14T16:03:27.9683270Z
2026-05-14T16:03:27.9684700Z Usage: rustup-init[EXE] [OPTIONS]
2026-05-14T16:03:27.9700800Z ##[error]Process completed with exit code 1.
Failing run: https://github.com/webarkit/WebARKitLib-rs/actions/runs/25870675080/job/76024750833?pr=130
Root Cause
Workflow step order:
actions/checkout@v5
dtolnay/rust-toolchain@stable — installs cargo to /Users/runner/.cargo/bin/cargo
Swatinem/rust-cache@v2 — restores /Users/runner/.cargo/bin from cache (this step overwrites the fresh cargo binary)
cargo build … — fails
On macOS, the cache occasionally contains a cargo shim that points to rustup-init (the Rust bootstrap installer). When restored, it shadows the real binary. This is a known interaction between rust-cache and toolchain managers — the rust-cache step does not currently exclude /Users/runner/.cargo/bin from restoration when the toolchain is freshly installed.
Impact
Medium — blocks PR CI on macOS approximately every Nth run. Workaround (re-run failed job) is trivial but recurring.
Suggested Mitigations
In order of preference / non-invasiveness:
Option A — Pin cache key to the toolchain version (minimal change)
- name: Install Rust toolchain
id: rust
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v0-rust-${{ steps.rust.outputs.cachekey }}"
This invalidates the cache when the Rust toolchain version changes, preventing stale cargo shims from surviving across toolchain updates.
Option B — Exclude .cargo/bin from cache
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-bin: false
cache-bin: false (available in Swatinem/rust-cache ≥ 2.5.0) prevents caching of .cargo/bin. Tradeoff: slightly slower for cargo-installed tools (e.g. cargo-binstall), none of which the project uses today.
Option C — Sanity-check cargo after cache restore (defensive)
- name: Verify cargo is real
run: |
cargo --version || (echo "cargo binary is broken; reinstalling" && rustup default stable)
Catches the symptom but doesn't address the root cause. Useful as a belt-and-braces alongside A or B.
Recommendation
Apply Option A (cache key pinned to toolchain version) as the first fix — minimal, addresses the documented race. If flakes recur, layer Option B on top.
Visual Evidence
Job comparison from the same workflow run #25870675080:
| Job |
Result |
kpm-build (ubuntu-latest) |
✅ pass |
kpm-build (windows-latest) |
✅ pass |
kpm-build (macos-latest) |
❌ fail (then pass on re-run) |
Additional Context
References
Summary
The
kpm-build (macos-latest)job in.github/workflows/ci.ymlflakes intermittently withrustup-init: unexpected argument 'build' foundwhenSwatinem/rust-cache@v2restores a cache containing a stalecargoshim. The cached shim overwrites the fresh binary just installed bydtolnay/rust-toolchain@stable, and subsequentcargo buildinvocations are interpreted asrustup-init build.Linux and Windows are unaffected.
Environment
.github/workflows/ci.ymljobkpm-build, matrixmacos-latestdtolnay/rust-toolchain@stableSwatinem/rust-cache@v2Reproduction Steps
Non-deterministic — depends on cache state of the runner. Observed on PR #130 (commit pushed twice on the same branch):
kpm-build.Expected Behavior
cargo build -p webarkitlib-rs --features ffi-backendruns the toolchain installed bydtolnay/rust-toolchain@stable.Actual Behavior
The
cargobinary onPATHresolves torustup-init(the bootstrap installer), not real cargo. This happens afterSwatinem/rust-cache@v2restores/Users/runner/.cargo/bin/from cache keyv0-rust-kpm-build-Darwin-arm64-9d946206-575a3e0f.Error Details
Failing run: https://github.com/webarkit/WebARKitLib-rs/actions/runs/25870675080/job/76024750833?pr=130
Root Cause
Workflow step order:
actions/checkout@v5dtolnay/rust-toolchain@stable— installs cargo to/Users/runner/.cargo/bin/cargoSwatinem/rust-cache@v2— restores/Users/runner/.cargo/binfrom cache (this step overwrites the fresh cargo binary)cargo build …— failsOn macOS, the cache occasionally contains a
cargoshim that points torustup-init(the Rust bootstrap installer). When restored, it shadows the real binary. This is a known interaction betweenrust-cacheand toolchain managers — the rust-cache step does not currently exclude/Users/runner/.cargo/binfrom restoration when the toolchain is freshly installed.Impact
Medium — blocks PR CI on macOS approximately every Nth run. Workaround (re-run failed job) is trivial but recurring.
Suggested Mitigations
In order of preference / non-invasiveness:
Option A — Pin cache key to the toolchain version (minimal change)
This invalidates the cache when the Rust toolchain version changes, preventing stale cargo shims from surviving across toolchain updates.
Option B — Exclude
.cargo/binfrom cachecache-bin: false(available inSwatinem/rust-cache≥ 2.5.0) prevents caching of.cargo/bin. Tradeoff: slightly slower for cargo-installed tools (e.g.cargo-binstall), none of which the project uses today.Option C — Sanity-check cargo after cache restore (defensive)
Catches the symptom but doesn't address the root cause. Useful as a belt-and-braces alongside A or B.
Recommendation
Apply Option A (cache key pinned to toolchain version) as the first fix — minimal, addresses the documented race. If flakes recur, layer Option B on top.
Visual Evidence
Job comparison from the same workflow run #25870675080:
kpm-build (ubuntu-latest)kpm-build (windows-latest)kpm-build (macos-latest)Additional Context
ffi-backend); this issue precedes the build entirely —cargoitself never runsReferences
Swatinem/rust-cachecache-bin docs: https://github.com/Swatinem/rust-cache#cache-bin