فا
← BACK TO THE WIRE
N°0285Rust2 MIN2 SOURCES

Cargo’s Nightly Disk Diet: Why Rust Is Separating Metadata From Libraries

Cargo is testing a nightly default that removes duplicated Rust metadata from library artifacts, potentially shrinking target directories by nearly 30% in release-style builds.

SHARE
Rust
Cargo’s Nightly Disk Diet: Why Rust Is Separating Metadata From Libraries
IMAGE: AI-GENERATED

Rust’s latest Cargo experiment targets one of the least glamorous costs of compilation: disk usage. Starting with nightly Cargo and nightly rustc, Cargo is rolling out -Zembed-metadata=no by default to test whether build directories can become smaller without sacrificing normal workflows.

The underlying issue comes from pipelined compilation. Cargo emits an .rmeta file early so dependent crates can begin compiling before a library has finished. When compilation completes, the resulting .rlib traditionally contains the same Rust metadata again alongside executable code. The result is duplicate metadata on disk.

With metadata embedding disabled, rustc leaves full metadata in separate .rmeta files and stores only stub metadata in .rlib and .dylib artifacts. Cargo’s unstable documentation describes this as a disk-saving feature and exposes it manually through cargo +nightly -Zno-embed-metadata build.

The size improvement depends heavily on the profile. In the Cargo team’s published test, a serde release build without incremental compilation or debuginfo fell from 40.88 MiB to 28.68 MiB—a 29.8% reduction. A default development build, where incremental artifacts and debug information dominate, fell from 179.70 MiB to 171.29 MiB, or 4.7%. The team reports an approximately 33% reduction for its Cargo build in the best case.

That distinction matters for CI and developer machines. The experiment is most valuable for clean release-oriented builds, large workspaces, and environments where cached artifacts consume meaningful storage. It is less likely to transform a typical debug directory whose largest files are incremental state and symbols.

There is also a sharp boundary for custom tooling. Most Cargo-driven builds should continue to work transparently, but a workflow that manually links .rlib files may need to pass the matching .rmeta file through --extern. A build cache or bespoke compiler wrapper that assumes all metadata lives inside the library should therefore be tested explicitly.

The safety-focused takeaway is simple: do not redesign a stable build pipeline around this yet. Rust’s Cargo team says the nightly default is an experiment intended to gather feedback, and the feature is not currently headed for stabilization. Nightly users can test their workspaces, watch for manual-linking or cache issues, and report regressions; stable users can wait for a future decision based on that evidence.

TAGSRustCargonightlybuild performance
Grounded sources2 REFS
  1. [01]Experiment in reducing target directory size on nightlyblog.rust-lang.org
  2. [02]Cargo Unstable Features: no-embed-metadatadoc.rust-lang.org
Read next

Get the wire in your inbox

Every new signal, straight from the generator. No noise, unsubscribe anytime.

RSS AVAILABLE · NO SPAM