Cargo's New Build Directory Layout v2 Enters Public Testing — Developers Urged to Test Nightly Feature

By • min read
<p><strong>The Cargo team has released a second-generation build directory layout (v2) for nightly testing, calling on developers to validate it before the change becomes the default.</strong> The new layout reorganizes how intermediate build artifacts are stored, moving from a content-type organization to a per-package, hashed structure.</p> <p>"We need community help to uncover edge cases that our crater runs missed," said a Cargo team member. "Many projects rely on undocumented internal details, and we want to ensure a smooth transition."</p> <p>Testing requires the <code>-Zbuild-dir-new-layout</code> flag with nightly <strong>2026-03-10 or later</strong>. Developers can run their test suites and release pipelines with this flag to identify incompatibilities.</p> <h2 id="background">Background</h2> <p>The build directory (or <code>target/</code> subfolder) currently organizes artifacts by content type (e.g., <code>.fingerprint</code>, <code>build/</code>). While internal, many tools and scripts have come to depend on this structure due to missing Cargo features.</p><figure style="margin:20px 0"><img src="https://www.rust-lang.org/static/images/rust-social-wide.jpg" alt="Cargo&#039;s New Build Directory Layout v2 Enters Public Testing — Developers Urged to Test Nightly Feature" style="width:100%;height:auto;border-radius:8px" loading="lazy"><figcaption style="font-size:12px;color:#666;margin-top:5px">Source: blog.rust-lang.org</figcaption></figure> <p>Proposal <a href="#">#16147</a> aims to make the new layout the default, pending community feedback. A crater run has already been performed, but the team warns it does not cover all scenarios.</p> <h2 id="how-to-test">How to Test</h2> <p>To participate, run your usual commands with the additional flag:</p> <pre><code>cargo test -Zbuild-dir-new-layout</code></pre> <p>Also test release processes, CI scripts, and any tool that interacts with <code>build-dir</code> or <code>target-dir</code>. Failure may not be isolated to the flag — users can also set <code>CARGO_BUILD_BUILD_DIR=build</code> (since Cargo 1.91) to separate build and target directories.</p> <h2 id="what-is-changing">What Is Changing</h2> <p>The new layout scopes build artifacts by <strong>package name</strong> and a <strong>hash of the build unit and its inputs</strong>. The old content-type folders (e.g., <code>.fingerprint</code>, <code>build/</code>) are replaced with per-package directories.</p> <p><strong>What stays the same:</strong> The final artifact layout under <code>target/debug/</code> or <code>target/release/</code> remains unchanged. Nesting under profile and target triple (if specified) also stays.</p> <h2 id="known-failure-modes">Known Failure Modes</h2> <p>Several common patterns are likely to break:</p> <ul> <li><strong>Inferring binary paths from test paths</strong> — Use <code>std::env::var_os("CARGO_BIN_EXE_*")</code> (stable since Cargo 1.94) or <code>env!("CARGO_BIN_EXE_*")</code> instead of path inference.</li> <li><strong>Build scripts looking up <code>target-dir</code> from their binary or <code>OUT_DIR</code></strong> — See <a href="https://github.com/rust-lang/cargo/issues/13663">Issue #13663</a>. Workarounds need updating.</li> <li><strong>Looking up user-requested artifacts from <code>rustc</code></strong> — See <a href="https://github.com/rust-lang/cargo/issues/13672">Issue #13672</a>. Similar workaround updates required.</li> </ul> <h2 id="library-support">Library Support Status</h2> <p>The following testing libraries have been checked:</p> <ul> <li><strong>assert_cmd</strong> — fixed</li> <li><strong>cli_test_dir</strong> — <a href="https://github.com/assert-rs/cli_test_dir/issues/65">Issue #65</a></li> <li><strong>compiletest_rs</strong> — <a href="https://github.com/rust-lang/compiletest-rs/issues/309">Issue #309</a></li> <li><strong>executable-path</strong> — fixed</li> <li><strong>snapbox</strong> — fixed</li> <li><strong>term-transcript</strong> — <a href="https://github.com/assert-rs/term-transcript/issues/269">Issue #269</a></li> <li><strong>test_bin</strong> — <a href="https://github.com/assert-rs/test_bin/issues/13">Issue #13</a></li> <li><strong>trycmd</strong> — fixed</li> </ul> <h2 id="what-this-means">What This Means</h2> <p>For most developers using standard Cargo workflows, the change should be transparent. However, tools that parse the build directory structure or rely on undocumented paths will need updates.</p> <p>"If your project or CI queries the build directory in any way, now is the time to test," the Cargo team emphasized. Feedback should be reported on the <a href="https://github.com/rust-lang/cargo/issues/16147">tracking issue #16147</a>. The team expects to evaluate the default change after sufficient community testing.</p> <p>Outcomes of this call include: fixing local issues, reporting upstream problems (with a note on the tracking issue), and providing general feedback on the proposal.</p>