Rust cargo on a Mac: a 4 MiB program left 753 MiB in target, and what each cargo clean removes

By the Zofle team · 15 November 2026 · 4 min read

Cargo target folder and registry sizes after building a small program

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

bash
cargo new demo && cd demo
# Cargo.toml dependencies: tokio (full), serde (derive), serde_json,
#   clap (derive), regex, reqwest (json)
cargo build            # debug
cargo build --release
grep -c '^name' Cargo.lock    # 181 crates

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

PlaceWhat it holdsSize after debug + release builds
target/debugcompiled dependencies and your code, debug mode487 MiB (deps alone 447 MiB)
target/releasethe same, optimised265 MiB
target/ total753 MiB (770,664 KB)
$CARGO_HOME/registry/cachedownloaded .crate files13 MiB
$CARGO_HOME/registry/srcthose crates unpacked89 MiB
$CARGO_HOME/registry/indexthe crates.io index17 MiB
Debug binary vs release binarywhat you actually run15.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

CommandWhat Cargo said it removedtarget afterRebuild time
cargo clean --release1,129 files, 261.7 MiB487 MiB (debug kept)release rebuild 24 s (the first release build took 18 s)
cargo clean -p demo190 files, 38.6 MiB (only our own crate)the rest keptseconds: only our code rebuilds
cargo clean2,549 files, 708.7 MiBgone (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:

bash
find ~/projects -name Cargo.toml -not -path "*/node_modules/*" -not -path "*/target/*" \
  | while read f; do d=$(dirname "$f"); [ -d "$d/target" ] && du -sk "$d/target" | awk -v d="$d" '{printf "%.0f MiB  %s\n", $1/1024, d}'; done | sort -rn

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_DIR or the build.target-dir config so dependencies compile once (projects with different settings can then slow each other down).
  • Trim the registry by deleting registry/src and registry/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 Mac

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

One email when it's ready. No spam, ever.