Software Tools

Testing the New Cargo Build Directory Layout v2: Your Questions Answered

2026-05-01 17:26:39

Welcome to our guide on the upcoming changes to Cargo's build directory layout. This Q&A covers everything you need to know about the v2 layout, how to test it, potential pitfalls, and what stays the same. Dive in to get clear, actionable insights.

What is the new Cargo build directory layout v2?

The new layout shifts from organizing build artifacts by content type (like .fingerprint, build, deps) to grouping them by package name and a hash of the build unit and its inputs. Instead of a flat structure under build-dir/debug/, you'll see subdirectories named after each package (e.g., lib-[hash], bin-[hash]), each containing all artifacts for that package. This change improves caching and reduces conflicts, but it may break tools that rely on the old internal layout.

Testing the New Cargo Build Directory Layout v2: Your Questions Answered
Source: blog.rust-lang.org

How can I test the new build directory layout?

You need a nightly Rust toolchain dated at least 2026-03-10. Then, run your usual build, test, or release commands with the -Zbuild-dir-new-layout flag. For example:

$ cargo test -Zbuild-dir-new-layout

You can also separate where intermediate and final artifacts go using CARGO_BUILD_BUILD_DIR=build (available since Cargo 1.91). To isolate issues, first test without the flag, then with it. Report any failures you find, noting that the problem might not be specific to the new layout.

What are the known failure modes and how to fix them?

Three common issues have been identified:

Which tools/libraries currently support the new layout?

As of publication, here's the status for common testing and utility crates:

If you maintain or use other tools, test them and report issues upstream.

What is not changing in the new layout?

Two important aspects remain the same:

Why is this change needed and what are the expected outcomes?

The build dir layout was always intended to be internal, but many projects have come to rely on its specific structure due to missing features in Cargo. The v2 layout improves correctness and performance, but it requires tools and processes to adapt. The community's testing can lead to:

What should I do if I encounter issues during testing?

If you see failures when using -Zbuild-dir-new-layout, first determine whether the issue is specific to the new layout (try running without the flag). If it is, check the tracking issue for known problems. Then:

Your contribution helps make the v2 layout reliable for everyone.

Explore

Understanding the Latest Linux Security Patches Across Multiple Distributions 10 Fascinating Facts About NASA Goddard's Greenbelt Visitor Center at 50 Years Rust 1.94.0 Released: Array Windows, Smarter Cargo Config, and TOML 1.1 10 Stunning Satellite Views of SpaceX's Falcon Heavy Comeback Launch Homebuilder PulteGroup Boosts Incentives to 10.9% as Affordability Challenges Persist