huacnlee/cargo Source Releases

Drop-in Cargo fork

Cargo that cleans up after itself

Every git worktree of a project shares one build directory, which stays under a size limit on its own. There is nothing to configure.

Disk used

Build time

$ curl -fsSL https://huacnlee.github.io/cargo/install.sh | sh

Installs over ~/.cargo/bin/cargo and keeps the rustup proxy as cargo.rustup. cargo +nightly and rust-toolchain.toml keep working. Run the script with --uninstall to put the proxy back.

Install once, stay current. At most once a day, after a command, cargo checks for a new release in the background and installs it: checksum verified, renamed into place, nothing printed. The last result is in ~/.cargo/.fork-update.log. Set CARGO_FORK_AUTO_UPDATE=0 to turn it off; it never runs in CI.

Every new worktree costs less

Total disk

Total build time

Each worktree is a fresh checkout building one binary. Cargo gives every worktree its own target directory and compiles all dependencies again. The fork compiles them once and reuses them, so later worktrees only build the workspace crates.

Projects share dependencies too

What a cleanup looks like

After a build, at most once an hour, Cargo removes what no checkout has used for a week, then the least recently used units until the project fits. It prints one line when it frees something.

$ cargo build
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.89s
     Cleaned 680 stale build units, 10.1GiB freed (build.gc)

What changes

Your projects, Cargo.toml and .cargo/config.toml stay as they are.

Change a default
# ~/.cargo/config.toml
[build.gc]
max-size = "auto"      # or "15 GiB", "none"
shared-max-size = "50 GiB"
max-unused = "1 day"
shared-max-unused = "7 days"
frequency = "1 hour"   # or "always", "never"
enabled = true

Set CARGO_SHARED_DEPS=0 to keep dependencies in the project's build directory, CARGO_CHECK_SHARED_DEPS=0 to only check them in cargo check, CARGO_SHARE_WORKSPACE_UNITS=0 to build your crates per worktree, CARGO_DEV_CRANELIFT=0 to keep LLVM on nightly, and CARGO_RUSTC_THREADS=1 for a single-threaded front end.