Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

Experiment in reducing target directory size on nightly

The Cargo Team has initiated an experiment to assess the impact of a proposed change that could reduce the size of the target directory during Rust compilation. This experiment will involve enabling the -Zembed-metadata=no feature on the nightly channel by default on Cargo. By doing so, the compiler will stop including metadata in the .rlib files, thereby reducing their file size.

This change is currently an experiment and not headed for stabilization, as the team aims to evaluate its practicality and gather feedback from nightly users.

The primary purpose of this experiment is to address the significant issue of high disk usage of Rust compilation artifacts, which is frequently reported by Rust users. In a 2025 State of Rust survey, high disk usage was the second most commonly reported problem, following compilation speed. The experiment focuses on one major source of data that contributes to large target directory sizes—the crate metadata, which can be duplicated across multiple files.

Traditionally, Cargo has employed pipelined compilation to expedite the building of crate graphs. When compiling a library crate, it instructs the compiler to generate an .rmeta file (containing all the necessary crate metadata) as soon as possible, even before the final executable code is available. This approach allows dependent crates to begin compiling sooner.

However, once the library finishes compiling, the final .rlib file contains both the executable code and the Rust-specific metadata, resulting in duplicate storage of the metadata—once in the .rmeta file and again in the .rlib file.

To mitigate this issue, last year, the Cargo team introduced an unstable compiler flag, -Zembed-metadata, alongside a corresponding Cargo flag. When using -Zembed-metadata=no, the compiler will refrain from placing metadata in the .rlib files, thereby reducing their size. In the upcoming experiment, Cargo will default to using -Zembed-metadata=no for both Cargo and the rustc when both are on the nightly channel.

The results of this experiment indicate that the disk size reductions depend heavily on the amount of crate metadata in the target directory. In cases with no incremental artifacts and no debug information, such as when using the release profile, the disk size reductions can be substantial, reaching almost 30%. However, when using the dev profile, which includes incremental compilation and debug information generation, the size reductions are more modest, around 5%.

The experiment also shows promising results for Cargo itself, with a reduction of approximately 33% or 300 MiB in the target directory size.

While this change is expected to have minimal impact on the vast majority of Rust users, it might affect those who manually link to .rlib files. In such cases, they may need to use the --extern flag to access the crate's metadata. Cargo does not currently uplift the corresponding .rmeta file when using -Zembed-metadata=no, so users must locate it using Cargo's JSON output or other methods if necessary.

To opt out of this experiment, users can either use the -Zembed-metadata=yes command-line argument or set the environment variable CARGO_UNSTABLE_EMBED_METADATA=true. Additionally, users can opt out through a .cargo/config.toml file. The Cargo team will review feedback regarding this change to determine the appropriate path forward, whether it should be stabilized as-is, require modifications, or necessitate a return to the drawing board.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at blog.rust-lang.org →

More in Tech

More from Tuesday 18 August →