cargo-heft 0.2.2

Find out what takes up space in your Cargo target directory.
cargo-heft-0.2.2 is not a library.

cargo-heft

CI crates.io Rust

cargo-heft tells you what takes up space in a Cargo target/ directory, and how much each profile setting would save.

A target/ directory easily grows to several gigabytes. Disk usage is the second most common complaint about the Rust toolchain in the 2025 State of Rust survey, and the Rust project has a goal to reduce it. du gives you one number. cargo-heft splits it by kind of file, by crate, and by what is inside the files: debuginfo, metadata and code.

It only reads: nothing in your target/ is changed or deleted. It runs on macOS and Linux.

Change log

Features

  • Sizes are what the files take on disk, and the total matches du -s.
  • Hard links are counted once, so the numbers add up.
  • Four views: by kind of file, by content, by profile and by crate.
  • Looks inside .rlib files, objects and binaries to separate metadata, debuginfo and code.
  • Points out metadata that is stored twice, as a .rmeta file and inside the .rlib.
  • --what-if builds your workspace once per profile setting and shows how much each one would save.
  • Understands both the classic target layout and the build-dir layout of Cargo 1.100.
  • JSON output for scripts and CI.

See how it counts for the details and the limits.

Usage

cargo install cargo-heft

Then, in a workspace you have built:

cargo heft              # measure the target directory
cargo heft --top 5      # list only the five largest crates
cargo heft --what-if    # what would each profile setting save?
cargo heft --json       # machine-readable output

Part of the output for ripgrep after a dev build:

target: 307.7 MB on disk (293.4 MiB in the units du -h uses)

by content
  debuginfo                         89.9 MB   29.2%
  code, data and symbols            87.7 MB   28.5%
  incremental cache                 68.3 MB   22.2%
  metadata (.rmeta files)           30.2 MB    9.8%
  metadata (inside rlib/dylib)      30.1 MB    9.8%
  other                              1.4 MB    0.5%
  note: 30.1 MB of metadata is stored twice, as a .rmeta file and inside its .rlib

And --what-if on the same project:

  setting                                  size  vs first    build
  as configured                        308.1 MB               8.5s
  debug = "line-tables-only"           245.5 MB    -20.3%     6.7s
  debug = false                        187.0 MB    -39.3%     6.3s
  incremental = false                  216.8 MB    -29.6%     5.9s
  line-tables-only, no incremental     172.1 MB    -44.1%     5.4s

Options

  • --target-dir <DIR>: measure this directory instead of the workspace's.
  • --top <N>: how many crates to list (default 15).
  • --json: machine-readable output. It has a schema_version, which goes up when a key is removed or renamed or a value changes meaning.
  • --what-if: compare profile settings.
  • --profile <NAME>: the profile --what-if builds (default dev).
  • -- <args>: extra arguments for cargo build in --what-if, such as -p my-crate.

Results

On 18 well-known projects (ripgrep, tokio, cargo, rust-analyzer, ruff, uv and others), a quarter to a third of target/ is debuginfo, and a fifth to a third is the incremental cache. A recent nightly needs 19% less space than Rust 1.100, about half of that because metadata is no longer stored twice. The tables, the raw data and the scripts are in bench/results.

Contributing

See CONTRIBUTING.md.

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.