Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ pub trait TestEnvCommandExt: Sized {
// don't particularly need. Tests that specifically need to check
// the incremental behavior should turn this back on.
.env("CARGO_INCREMENTAL", "0")
.env("CARGO_BUILD_DIR_LAYOUT_V2", "true")
// Don't read the system git config which is out of our control.
.env("GIT_CONFIG_NOSYSTEM", "1")
.env_remove("__CARGO_DEFAULT_LIB_METADATA")
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use tracing::debug;

use super::{BuildContext, BuildRunner, CompileKind, FileFlavor, Layout};
use crate::core::compiler::{CompileMode, CompileTarget, CrateType, FileType, Unit};
use crate::core::features::is_new_build_dir_layout_enabled;
use crate::core::{Target, TargetKind, Workspace};
use crate::util::{self, CargoResult, OnceExt, StableHasher};

Expand Down Expand Up @@ -245,7 +246,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
/// Note that some units may share the same directory, so care should be
/// taken in those cases!
fn pkg_dir(&self, unit: &Unit) -> String {
let separator = match self.ws.gctx().cli_unstable().build_dir_new_layout {
let separator = match is_new_build_dir_layout_enabled(self.ws.gctx()) {
true => "/",
false => "-",
};
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::{Arc, Mutex};
use crate::core::PackageId;
use crate::core::compiler::compilation::{self, UnitOutput};
use crate::core::compiler::{self, Unit, UserIntent, artifact};
use crate::core::features::is_new_build_dir_layout_enabled;
use crate::util::cache_lock::CacheLockMode;
use crate::util::errors::CargoResult;
use annotate_snippets::{Level, Message};
Expand Down Expand Up @@ -467,7 +468,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
.root_output
.insert(kind, artifact_dir.dest().to_path_buf());
}
if self.bcx.gctx.cli_unstable().build_dir_new_layout {
if is_new_build_dir_layout_enabled(self.bcx.gctx) {
for (unit, _) in self.bcx.unit_graph.iter() {
let dep_dir = self.files().deps_dir(unit);
paths::create_dir_all(&dep_dir)?;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

use crate::core::Workspace;
use crate::core::compiler::CompileTarget;
use crate::core::features::is_new_build_dir_layout_enabled;
use crate::util::flock::is_on_nfs_mount;
use crate::util::{CargoResult, FileLock};
use cargo_util::paths;
Expand All @@ -129,7 +130,7 @@ impl Layout {
dest: &str,
must_take_artifact_dir_lock: bool,
) -> CargoResult<Layout> {
let is_new_layout = ws.gctx().cli_unstable().build_dir_new_layout;
let is_new_layout = is_new_build_dir_layout_enabled(ws.gctx());
let mut root = ws.target_dir();
let mut build_root = ws.build_dir();
if let Some(target) = target {
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ use self::unit_graph::UnitDep;
use crate::core::compiler::future_incompat::FutureIncompatReport;
use crate::core::compiler::timings::SectionTiming;
pub use crate::core::compiler::unit::{Unit, UnitInterner};
use crate::core::features::is_new_build_dir_layout_enabled;
use crate::core::manifest::TargetSourcePath;
use crate::core::profiles::{PanicStrategy, Profile, StripInner};
use crate::core::{Feature, PackageId, Target, Verbosity};
Expand Down Expand Up @@ -1825,7 +1826,7 @@ pub fn lib_search_paths(
unit: &Unit,
) -> CargoResult<Vec<OsString>> {
let mut lib_search_paths = Vec::new();
if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
if is_new_build_dir_layout_enabled(build_runner.bcx.gctx) {
let mut map = BTreeMap::new();

// Recursively add all dependency args to rustc process
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,3 +1556,13 @@ pub fn cargo_docs_link(path: &str) -> String {
};
format!("https://doc.rust-lang.org/{url_channel}cargo/{path}")
}

/// Returns true of the new build dir layout is enabled.
#[allow(clippy::disallowed_methods)]
pub fn is_new_build_dir_layout_enabled(gctx: &GlobalContext) -> bool {
match std::env::var("CARGO_BUILD_DIR_LAYOUT_V2").as_deref() {
Ok("true") => true,
Ok("false") => false,
Ok(_) | Err(_) => gctx.cli_unstable().build_dir_new_layout,
}
}
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::core::compiler::{CompileKind, CompileMode, Layout, RustcTargetData};
use crate::core::features::is_new_build_dir_layout_enabled;
use crate::core::profiles::Profiles;
use crate::core::{PackageIdSpec, PackageIdSpecQuery, TargetKind, Workspace};
use crate::ops;
Expand Down Expand Up @@ -196,7 +197,7 @@ fn clean_specs(
clean_ctx.progress = Box::new(CleaningPackagesBar::new(clean_ctx.gctx, packages.len()));
let mut dirs_to_clean = DirectoriesToClean::default();

if clean_ctx.gctx.cli_unstable().build_dir_new_layout {
if is_new_build_dir_layout_enabled(clean_ctx.gctx) {
for pkg in packages {
clean_ctx.progress.on_cleaning_package(&pkg.name())?;

Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,12 @@ enabled = true
Enables the new build-dir filesystem layout.
This layout change unblocks work towards caching and locking improvements.

In addition to `-Zbuild-dir-new-layout`, `CARGO_BUILD_DIR_LAYOUT_V2` also exists as
a way to opt in and out of the new layout during the transition period.
`CARGO_BUILD_DIR_LAYOUT_V2=true` allows users to opt in to the new layout, even on stable.
`CARGO_BUILD_DIR_LAYOUT_V2=false` allows users to opt out to the new layout.
This includes post stabilization but it's important to note that this is a temporary flag and will
eventually be removed. See the tracking issue for the transition plan and updates.

## compile-time-deps

Expand Down
18 changes: 9 additions & 9 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ fn allow_artifact_and_no_artifact_dep_to_same_package_within_different_dep_categ
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/deps/foo-[HASH][EXE])
[DOCTEST] foo

"#]])
Expand Down Expand Up @@ -1296,7 +1296,7 @@ fn cross_doctests_works_with_artifacts() {
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/deps/foo-[HASH][EXE])
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/deps/foo-[HASH][EXE])
[DOCTEST] foo

"#]])
Expand All @@ -1320,7 +1320,7 @@ fn cross_doctests_works_with_artifacts() {
[RUNNING] `rustc --crate-name foo [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/deps/foo-[HASH][EXE]`
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/build/foo/[HASH]/deps/foo-[HASH][EXE]`
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test src/lib.rs --test-run-directory [ROOT]/foo --target [ALT_TARGET] [..]

Expand Down Expand Up @@ -1426,7 +1426,7 @@ fn profile_override_basic() {
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=1 [..]`
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=3 [..]`
[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/build-script/build-script-build`
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
[COMPILING] foo v0.0.1 ([ROOT]/foo)

Expand Down Expand Up @@ -2210,8 +2210,8 @@ fn env_vars_and_build_products_for_various_build_targets() {
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
[RUNNING] tests/main.rs (target/debug/deps/main-[HASH][EXE])
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/deps/foo-[HASH][EXE])
[RUNNING] tests/main.rs (target/debug/build/foo/[HASH]/deps/main-[HASH][EXE])
[DOCTEST] foo

"#]])
Expand Down Expand Up @@ -2825,7 +2825,7 @@ fn with_assumed_host_target_and_optional_build_dep() {
[COMPILING] d1 v0.0.1 ([ROOT]/foo/d1)
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/build-script/build-script-build`
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
[FINISHED] `dev` profile [..]
[COMPILING] foo v0.0.1 ([ROOT]/foo)
Expand Down Expand Up @@ -3492,7 +3492,7 @@ fn artifact_dep_target_does_not_propagate_to_deps_of_build_script() {
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/deps/foo-[HASH][EXE])

"#]])
.masquerade_as_nightly_cargo(&["bindeps"])
Expand Down Expand Up @@ -3584,7 +3584,7 @@ fn artifact_dep_target_does_not_propagate_to_proc_macro() {
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/deps/foo-[HASH][EXE])

"#]])
.masquerade_as_nightly_cargo(&["bindeps"])
Expand Down
Loading
Loading