Rust cargo on a Mac: a 4 MiB program left 753 MiB in target, and what each cargo clean removes
Rust projects are famous for a target folder that grows without limit. We built one small program with six common dependencies (181 crates in total) in debug and release mode, measured every folder Cargo creates, and tried each variant of cargo clean. The short result: one tiny program produced 752 MiB of build output and 120 MiB of downloaded crates, and the variants of cargo clean remove very different amounts.
The test project
We set CARGO_HOME to a scratch folder so the Mac's own ~/.cargo stayed untouched (Cargo 1.99.1 from Homebrew, Apple silicon). The program itself is ten lines; everything else is dependencies.
Where the space goes
| Place | What it holds | Size after debug + release builds |
|---|---|---|
target/debug | compiled dependencies and your code, debug mode | 487 MiB (deps alone 447 MiB) |
target/release | the same, optimised | 265 MiB |
target/ total | 753 MiB (770,664 KB) | |
$CARGO_HOME/registry/cache | downloaded .crate files | 13 MiB |
$CARGO_HOME/registry/src | those crates unpacked | 89 MiB |
$CARGO_HOME/registry/index | the crates.io index | 17 MiB |
| Debug binary vs release binary | what you actually run | 15.5 MiB vs 4.1 MiB |
A program of 4 MiB left 753 MiB of intermediate files. That ratio is why target folders add up: after ten projects you can be at 7 GB without having written much code. The registry is shared across projects, so it grows slowly (about 120 MiB here) while every project keeps its own target.
cargo clean, three ways
| Command | What Cargo said it removed | target after | Rebuild time |
|---|---|---|---|
cargo clean --release | 1,129 files, 261.7 MiB | 487 MiB (debug kept) | release rebuild 24 s (the first release build took 18 s) |
cargo clean -p demo | 190 files, 38.6 MiB (only our own crate) | the rest kept | seconds: only our code rebuilds |
cargo clean | 2,549 files, 708.7 MiB | gone (folder removed) | debug rebuild 10 s with the registry kept; 25 s on the very first build, which also downloads crates |
The useful reading: cargo clean -p yourcrate is cheap but frees little, since the weight is in dependencies. cargo clean --release is the one to run when you only need a debug loop. Plain cargo clean is safe, because everything in target is rebuilt from source, and costs only the compile time. Rebuild times here are small because this is a small dependency set; a larger program with hundreds of crates takes proportionally longer, which we did not test.
Sweeping old projects
The biggest win is old projects you have not built in months. Find every target folder next to a Cargo.toml and see the sizes first:
On the Mac we used for this article that list was empty (no Rust projects), so there is no real-world sweep to quote; the numbers above are from the lab project. For each old project, cd in and run cargo clean. Do not delete the ~/.cargo folder blindly: it also holds installed tools such as cargo install binaries in ~/.cargo/bin.
Smaller options
- Share one target folder across projects with
CARGO_TARGET_DIRor thebuild.target-dirconfig so dependencies compile once (projects with different settings can then slow each other down). - Trim the registry by deleting
registry/srcandregistry/cache(the Cargo Book describes both as re-creatable); Cargo fetches again on the next build. We did not test deleting them. - Debug info is a large part of debug builds; setting
debug = "line-tables-only"in a profile reduces it. We did not measure that.
For other developer caches on the same disk see Gradle, node_modules and the caches that never go away and the Go cache article, which uses the same cold, warm and cleaned rebuild test.
Zofle shows your Mac storage by category and lets you move big, old files to the Trash with Undo, so you can see what is worth the effort before you run any command.
Download Zofle for MacSources and method
- The Cargo Book: cargo clean, Cargo home, build cache.
- Built and measured on 15 November 2026 with Cargo 1.99.1 on an Apple silicon Mac, one run per step, with CARGO_HOME in a scratch folder deleted afterwards. Sizes in MiB from du -sk. Times are indicative.
Zofle Pro news
People signing up now will get Zofle Pro, with more features, for free when we launch it.