Skip to content

Commit 0cff515

Browse files
committed
feat: Stablize build-dir layout v2
1 parent 6fc2526 commit 0cff515

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+861
-927
lines changed

src/cargo/core/features.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ const STABILIZED_BUILD_DIR: &str = "build.build-dir is now always enabled.";
10011001

10021002
const STABILIZED_CONFIG_INCLUDE: &str = "The `include` config key is now always available";
10031003

1004+
const STABILIZED_BUILD_DIR_NEW_LAYOUT: &str = "build.build-dir-new-layout is now always enabled.";
1005+
10041006
fn deserialize_comma_separated_list<'de, D>(
10051007
deserializer: D,
10061008
) -> Result<Option<Vec<String>>, D::Error>
@@ -1389,6 +1391,7 @@ impl CliUnstable {
13891391
"package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE),
13901392
"build-dir" => stabilized_warn(k, "1.91", STABILIZED_BUILD_DIR),
13911393
"config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE),
1394+
"build-dir-new-layout" => stabilized_warn(k, "1.97", STABILIZED_BUILD_DIR_NEW_LAYOUT),
13921395

13931396
// Unstable features
13941397
// Sorted alphabetically:
@@ -1399,7 +1402,6 @@ impl CliUnstable {
13991402
"binary-dep-depinfo" => self.binary_dep_depinfo = parse_empty(k, v)?,
14001403
"bindeps" => self.bindeps = parse_empty(k, v)?,
14011404
"build-analysis" => self.build_analysis = parse_empty(k, v)?,
1402-
"build-dir-new-layout" => self.build_dir_new_layout = parse_empty(k, v)?,
14031405
"build-std" => self.build_std = Some(parse_list(v)),
14041406
"build-std-features" => self.build_std_features = Some(parse_list(v)),
14051407
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,
@@ -1545,6 +1547,11 @@ impl CliUnstable {
15451547
}
15461548

15471549
fn implicitly_enable_features_if_needed(&mut self) {
1550+
// build_dir_new_layout was stabilized and the feature flag is only being kept during the
1551+
// period on nightly to make rolling back easier if it's needed.
1552+
// This flag should be cleaned up after the stabilization hits the stable channel.
1553+
self.build_dir_new_layout = true;
1554+
15481555
#[expect(
15491556
clippy::disallowed_methods,
15501557
reason = "Temporary opt out that is not part of the public interface"

tests/testsuite/artifact_dep.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -620,25 +620,25 @@ fn build_script_with_bin_artifacts() {
620620
assert_e2e().eq(
621621
&build_script_output,
622622
str![[r#"
623-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/baz[EXE]
624-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/staticlib/bar-[HASH].lib
625-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/cdylib/bar.dll
626-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin
627-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/bar[EXE]
628-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/bar[EXE]
623+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/baz[EXE]
624+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/staticlib/bar-[HASH].lib
625+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/cdylib/bar.dll
626+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin
627+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/bar[EXE]
628+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/bar[EXE]
629629
630630
"#]],
631631
);
632632
} else {
633633
assert_e2e().eq(
634634
&build_script_output,
635635
str![[r#"
636-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/baz-[HASH][EXE]
637-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/staticlib/libbar-[HASH].a
638-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/cdylib/[..]bar.[..]
639-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin
640-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/bar-[HASH][EXE]
641-
[ROOT]/foo/target/debug/deps/artifact/bar-[HASH]/bin/bar-[HASH][EXE]
636+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/baz[EXE]
637+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/staticlib/libbar-[HASH].a
638+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/cdylib/[..]bar.[..]
639+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin
640+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/bar[EXE]
641+
[ROOT]/foo/target/debug/build/bar/[HASH]/artifact/bin/bar[EXE]
642642
643643
"#]],
644644
);
@@ -810,17 +810,17 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {
810810
assert_e2e().eq(
811811
&build_script_output,
812812
str![[r#"
813-
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[HASH]/bin
814-
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[HASH]/bin/baz_suffix[EXE]
813+
[ROOT]/foo/target/debug/build/bar-baz/[HASH]/artifact/bin
814+
[ROOT]/foo/target/debug/build/bar-baz/[HASH]/artifact/bin/baz_suffix[EXE]
815815
816816
"#]],
817817
);
818818
} else {
819819
assert_e2e().eq(
820820
&build_script_output,
821821
str![[r#"
822-
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[HASH]/bin
823-
[ROOT]/foo/target/debug/deps/artifact/bar-baz-[HASH]/bin/baz_suffix-[HASH][EXE]
822+
[ROOT]/foo/target/debug/build/bar-baz/[HASH]/artifact/bin
823+
[ROOT]/foo/target/debug/build/bar-baz/[HASH]/artifact/bin/baz_suffix[EXE]
824824
825825
"#]],
826826
);
@@ -904,7 +904,7 @@ fn lib_with_selected_dashed_bin_artifact_and_lib_true() {
904904
!p.bin("bar").is_file(),
905905
"artifacts are located in their own directory, exclusively, and won't be lifted up"
906906
);
907-
assert_artifact_executable_output(&p, "debug", "bar", "baz_suffix");
907+
assert_artifact_executable_output(&p, "debug", "bar-baz", "baz_suffix");
908908
}
909909

910910
#[cargo_test]
@@ -947,7 +947,7 @@ fn allow_artifact_and_no_artifact_dep_to_same_package_within_different_dep_categ
947947
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
948948
[COMPILING] foo v0.0.0 ([ROOT]/foo)
949949
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
950-
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
950+
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
951951
[DOCTEST] foo
952952
953953
"#]])
@@ -1296,7 +1296,7 @@ fn cross_doctests_works_with_artifacts() {
12961296
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
12971297
[COMPILING] foo v0.0.1 ([ROOT]/foo)
12981298
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1299-
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/deps/foo-[HASH][EXE])
1299+
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
13001300
[DOCTEST] foo
13011301
13021302
"#]])
@@ -1320,7 +1320,7 @@ fn cross_doctests_works_with_artifacts() {
13201320
[RUNNING] `rustc --crate-name foo [..]
13211321
[RUNNING] `rustc --crate-name foo [..]
13221322
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1323-
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/deps/foo-[HASH][EXE]`
1323+
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH][EXE]`
13241324
[DOCTEST] foo
13251325
[RUNNING] `rustdoc [..]--test src/lib.rs --test-run-directory [ROOT]/foo --target [ALT_TARGET] [..]
13261326
@@ -1426,7 +1426,7 @@ fn profile_override_basic() {
14261426
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=1 [..]`
14271427
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=3 [..]`
14281428
[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`
1429-
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1429+
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build_script_build`
14301430
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
14311431
[COMPILING] foo v0.0.1 ([ROOT]/foo)
14321432
@@ -2210,8 +2210,8 @@ fn env_vars_and_build_products_for_various_build_targets() {
22102210
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
22112211
[COMPILING] foo v0.0.0 ([ROOT]/foo)
22122212
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2213-
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
2214-
[RUNNING] tests/main.rs (target/debug/deps/main-[HASH][EXE])
2213+
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
2214+
[RUNNING] tests/main.rs (target/debug/build/foo/[HASH]/out/main-[HASH][EXE])
22152215
[DOCTEST] foo
22162216
22172217
"#]])
@@ -2419,7 +2419,11 @@ fn doc_lib_true() {
24192419

24202420
// Verify that it emits rmeta for the bin and lib dependency.
24212421
assert_eq!(p.glob("target/debug/artifact/*.rlib").count(), 0);
2422-
assert_eq!(p.glob("target/debug/deps/libbar-*.rmeta").count(), 2);
2422+
assert_eq!(
2423+
p.glob("target/debug/build/bar/*/out/libbar-*.rmeta")
2424+
.count(),
2425+
2
2426+
);
24232427

24242428
p.cargo("doc -Z bindeps")
24252429
.masquerade_as_nightly_cargo(&["bindeps"])
@@ -2511,7 +2515,7 @@ fn assert_artifact_executable_output(
25112515
if cfg!(target_env = "msvc") {
25122516
assert_eq!(
25132517
p.glob(format!(
2514-
"target/{}/deps/artifact/{}-*/bin/{}{}",
2518+
"target/{}/build/{}/*/artifact/bin/{}{}",
25152519
target_name,
25162520
dep_name,
25172521
bin_name,
@@ -2524,7 +2528,7 @@ fn assert_artifact_executable_output(
25242528
} else {
25252529
assert_eq!(
25262530
p.glob(format!(
2527-
"target/{}/deps/artifact/{}-*/bin/{}-*{}",
2531+
"target/{}/build/{}/*/artifact/bin/{}{}",
25282532
target_name,
25292533
dep_name,
25302534
bin_name,
@@ -2541,7 +2545,7 @@ fn assert_artifact_executable_output(
25412545

25422546
fn build_script_output_string(p: &Project, package_name: &str) -> String {
25432547
let paths = p
2544-
.glob(format!("target/debug/build/{}-*/output", package_name))
2548+
.glob(format!("target/debug/build/{}/*/run/stdout", package_name))
25452549
.collect::<Result<Vec<_>, _>>()
25462550
.unwrap();
25472551
assert_eq!(paths.len(), 1);
@@ -2825,7 +2829,7 @@ fn with_assumed_host_target_and_optional_build_dep() {
28252829
[COMPILING] d1 v0.0.1 ([ROOT]/foo/d1)
28262830
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
28272831
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
2828-
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
2832+
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build_script_build`
28292833
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
28302834
[FINISHED] `dev` profile [..]
28312835
[COMPILING] foo v0.0.1 ([ROOT]/foo)
@@ -3492,7 +3496,7 @@ fn artifact_dep_target_does_not_propagate_to_deps_of_build_script() {
34923496
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
34933497
[COMPILING] foo v0.0.1 ([ROOT]/foo)
34943498
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3495-
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
3499+
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
34963500
34973501
"#]])
34983502
.masquerade_as_nightly_cargo(&["bindeps"])
@@ -3584,7 +3588,7 @@ fn artifact_dep_target_does_not_propagate_to_proc_macro() {
35843588
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
35853589
[COMPILING] foo v0.0.1 ([ROOT]/foo)
35863590
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3587-
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
3591+
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
35883592
35893593
"#]])
35903594
.masquerade_as_nightly_cargo(&["bindeps"])

0 commit comments

Comments
 (0)