Skip to content

perf(dev): share Cargo package cache across worktrees - #199

Draft
johnmatthewtennant wants to merge 2 commits into
jtennant/per-worktree-cargo-targetsfrom
jtennant/shared-cargo-home
Draft

perf(dev): share Cargo package cache across worktrees#199
johnmatthewtennant wants to merge 2 commits into
jtennant/per-worktree-cargo-targetsfrom
jtennant/shared-cargo-home

Conversation

@johnmatthewtennant

@johnmatthewtennant johnmatthewtennant commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Category: infrastructure
User Impact: Rust dependency builds can now be reused across Berd worktrees instead of being invalidated by checkout-specific package paths.

Problem: Hermit gives each Berd worktree its own CARGO_HOME. That changes the absolute paths of downloaded Rust dependency sources, so Cargo invalidates otherwise reusable compiler artifacts copied or cached from another worktree.

Solution: Berd now uses a stable user-level Cargo home for registry, Git, and package caches while keeping each worktree’s Cargo target directory isolated. Cargo’s package-cache locking supports concurrent access, so dependency downloads are shared without reintroducing build-directory lock contention. The shared Cargo home’s bin directory remains first on PATH, preserving cargo install behavior.

File changes

bin/hermit.hcl
Overrides the Hermit rustup package’s checkout-local Cargo home with ${HOME}/.cache/berd/cargo-home and prepends that Cargo home’s bin directory to PATH.

scripts/release/tests/release-scripts.test.mjs
Pins the shared Cargo-home and binary-path contracts so future Hermit package changes cannot silently restore worktree-specific dependency paths.

Related issue

None found.

Testing

  • In two fresh macOS worktrees at the same commit, a seeded cargo test -p berdctl --no-run consumer reported 59 Fresh crates, 0 Dirty, 0 Compiling, and 0 downloads, finishing in 0.15 seconds.
  • The same fresh-worktree experiment with cargo check reported 59 Fresh crates and finished in 0.15 seconds. Clippy reused all 58 dependencies and rechecked only the path-sensitive workspace crate.
  • Two fresh worktrees built concurrently with separate target directories and one shared empty Cargo home. Both succeeded with no build-directory lock waits; Cargo briefly serialized only its package cache.
  • Hermit resolves both the stable Cargo home and its binary path on macOS. The focused release-script regression passes locally; the stable-home contract and just check also passed on Linux Blox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant