huacnlee/cargo

Drop-in replacement for Rust's Cargo

A Rust Cargo that keeps target small on its own

huacnlee/cargo is a fork of Cargo, the Rust build tool. Install it and it replaces your cargo, with nothing to configure. Git worktrees and projects share build output that stays under a size limit on its own, so you can run as many AI agents as you like, stop deleting target, and stop rebuilding from scratch.

$ 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.

Why I built this

Rust is one of the most valuable languages of the AI era, but target became my biggest headache: a 2 TB drive was not enough. The tools I tried did not solve it, so I changed Cargo itself. Read the background.

Day five, nothing deleted

It now runs on four of my computers: two Linux, one macOS and one Windows, which has seen less use. On Linux and macOS it has run for five days straight, full of worktrees doing automated AI development. I have not cleaned a target directory once, and the disk has not filled up again.

Disktree treemap of a home directory: ~/.cargo/targets is 41.7 GB of 99.5 GB, with 711.9 GB of the disk free.
My home directory on Omarchy, November 4, 2026, in Disktree. All Rust build output is 41.7 GB. All my checkouts and worktrees, in work, are 9.9 GB. 711.9 GB of the disk is free.

Rust still compiles slower than languages like Go. That is a trade I accept: we wait a little, and users get the faster app.

I also wrote about this on X.

Every new worktree costs less

5 git worktrees of a 525-crate Rust workspace, each built once. Measured.

Disk used

5.1 GBvs 33.6 GB with Cargo, 6.6× less

Cargo
33.6 GB
Fork
5.1 GB

Build time

1.6 minvs 8.5 min with Cargo, 5.3× faster

Cargo
8.5 min
Fork
1.6 min

nsh, a 525-crate workspace, dev build of one binary per worktree on an 8-core Apple Silicon Mac, Rust 1.99 stable. Five worktrees of the same commit in one run; edits are the median of three runs. Compiler caches such as sccache off.

Total disk 33.6 GB → 5.1 GB

12345

Total build time 8.5 min → 1.6 min

12345

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.

One worktree, first build

Empty build directory. Most of the difference is debug info that dependencies no longer carry.

Cargo
111.4 s
Fork
77.2 s

Rebuild after editing a core crate

Edit nsh-core, which most of the workspace depends on, in the second of two worktrees. About as fast as Cargo, the first edit in a new worktree included; Cranelift on nightly.

Cargo
9.1 s
Fork
9.7 s
Fork, nightly
9.2 s

Undo the edit

The files match a build made before, so the fork reuses it; Cargo compiles the crates again.

Cargo
8.8 s
Fork
3.4 s
Fork, nightly
3.2 s

Projects share dependencies too

Release builds of Cargo 1.99.0 and this fork, run one after another on the same machine: nsh, then mado (a 330-crate app in its own repository), then mado again from an empty build directory, as a new worktree or after cargo clean would start. One run each.

nsh, first build

Empty build directories. The same speed; dependencies now land in the shared directory.

Cargo
207.9 s
Fork
206.7 s

mado, first build after nsh

mado builds its dependencies at opt-level 3 and nsh at 0, so the two share almost nothing (1 of 330 crates). The fork is faster because dependencies carry no debug info.

Cargo
513.8 s
Fork
379.2 s

mado again, empty build directory

Cargo compiles all 330 crates again, as in its first build. The fork finds the dependencies in the shared directory and compiles 2 crates.

Cargo
513.8 s
Fork
16.2 s

Disk after nsh and mado

Cargo: both target directories. Fork: both project directories (2.3 GB and 0.4 GB) and the shared dependencies (2.2 GB).

Cargo
10.3 GB
Fork
4.9 GB

What a cleanup looks like

After a build, at most once an hour, Cargo removes what no build has used for a day, 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"
projects-max-size = "50 GiB" # all other projects
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.