Skip to content

Commit efb0721

Browse files
committed
feat: Re-stabilize build-dir layout v2
1 parent a9792b4 commit efb0721

56 files changed

Lines changed: 1001 additions & 1236 deletions

Some content is hidden

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

crates/cargo-test-support/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,6 @@ pub trait TestEnvCommandExt: Sized {
14391439
.env("CARGO_INCREMENTAL", "0")
14401440
// Don't read the system git config which is out of our control.
14411441
.env("GIT_CONFIG_NOSYSTEM", "1")
1442-
// See: https://github.com/rust-lang/rust/pull/159857#issuecomment-5119325932
1443-
// This should be removed once the new build-dir layout is stabilized and the old layout
1444-
// is removed.
1445-
.env("__CARGO_TEMPORARY_BUILD_DIR_NEW_LAYOUT_OPT_OUT", "1")
14461442
.env_remove("CI")
14471443
.env_remove("__CARGO_DEFAULT_LIB_METADATA")
14481444
.env_remove("ALL_PROXY")

doc/book/src/reference/build-cache.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ change. Some of these directories are:
7070

7171
Directory | Description
7272
----------|------------
73-
<code style="white-space: nowrap">\<build-dir>/debug/deps/</code> | Dependencies and other artifacts.
7473
<code style="white-space: nowrap">\<build-dir>/debug/incremental/</code> | `rustc` [incremental output], a cache used to speed up subsequent builds.
75-
<code style="white-space: nowrap">\<build-dir>/debug/build/</code> | Output from [build scripts].
74+
<code style="white-space: nowrap">\<build-dir>/debug/build/</code> | Build step results including compilation artifacts and [build script] output.
75+
76+
> **Note**: The build-dir layout was changed in Cargo 1.100.0, thus prior versions use a different layout. (see [#15010](https://github.com/rust-lang/cargo/issues/15010))
7677
7778
## Dep-info files
7879

@@ -107,7 +108,7 @@ configuration][config]. Refer to sccache documentation for more details.
107108
[`cargo doc`]: ../commands/cargo-doc.md
108109
[`cargo package`]: ../commands/cargo-package.md
109110
[`cargo publish`]: ../commands/cargo-publish.md
110-
[build scripts]: ../reference/build-scripts.md
111+
[build script]: ../reference/build-scripts.md
111112
[config]: ../reference/config.md
112113
[def-workspace]: ../appendix/glossary.md#workspace '"workspace" (glossary entry)'
113114
[target]: ../appendix/glossary.md#target '"target" (glossary entry)'

doc/book/src/reference/unstable.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ Each new feature described below should explain how to use it.
8282
* [min-publish-age](#min-publish-age) --- Filters out dependency versions published more recently than a configured minimum age.
8383
* Output behavior
8484
* [artifact-dir](#artifact-dir) --- Adds a directory where artifacts are copied to.
85-
* [build-dir-new-layout](#build-dir-new-layout) --- Enables the new build-dir filesystem layout
8685
* [Different binary name](#different-binary-name) --- Assign a name to the built binary that is separate from the crate name.
8786
* [root-dir](#root-dir) --- Controls the root directory relative to which paths are printed
8887
* Compile behavior
@@ -1735,8 +1734,6 @@ panic = "immediate-abort"
17351734

17361735
Use fine grain locking instead of locking the entire build cache.
17371736

1738-
Note: Fine grain locking implicitly enables [build-dir-new-layout](#build-dir-new-layout) as fine grain locking builds on that directory reoganization.
1739-
17401737
## `[lints.cargo]`
17411738

17421739
* Tracking Issue: [#12235](https://github.com/rust-lang/cargo/issues/12235)
@@ -2005,14 +2002,6 @@ The following commands are available under `-Zbuild-analysis`:
20052002
- `cargo report rebuilds` --- Reports why crates were rebuilt,
20062003
helping diagnose unexpected recompilations.
20072004

2008-
## build-dir-new-layout
2009-
2010-
* Tracking Issue: [#15010](https://github.com/rust-lang/cargo/issues/15010)
2011-
2012-
Enables the new build-dir filesystem layout.
2013-
This layout change unblocks work towards caching and locking improvements.
2014-
2015-
20162005
## compile-time-deps
20172006

20182007
This permanently-unstable flag to only build proc-macros and build scripts (and their required dependencies),
@@ -2465,3 +2454,7 @@ The `build.warnings` config field has been stabilized in Rust 1.97.
24652454

24662455
The `cargo update -Zunstable-options --breaking` flag has been removed in 1.99-nightly.
24672456
See <https://github.com/rust-lang/cargo/pull/17333> fopr the reason for its removal.
2457+
2458+
## build-dir-new-layout
2459+
2460+
The new build-dir filesystem layout was stabilized in the 1.100.0 release.

src/workspace/features.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,7 @@ macro_rules! unstable_cli_options {
838838
),*
839839
};
840840

841-
// Defaults to enabled on nightly unless explicitly opted out.
842-
if !is_new_build_dir_layout_opt_out() {
843-
unstable.build_dir_new_layout =
844-
matches!(crate::version().release_channel.as_deref(), Some("nightly" | "dev"));
845-
}
841+
unstable.build_dir_new_layout = !is_new_build_dir_layout_opt_out();
846842

847843
return unstable;
848844
}
@@ -1023,6 +1019,8 @@ const STABILIZED_LOCKFILE_PATH: &str = "The `lockfile-path` config key is now al
10231019

10241020
const STABILIZED_WARNINGS: &str = "The `build.warnings` config key is now always available";
10251021

1022+
const STABILIZED_BUILD_DIR_NEW_LAYOUT: &str = "build.build-dir-new-layout is now always enabled.";
1023+
10261024
fn deserialize_comma_separated_list<'de, D>(
10271025
deserializer: D,
10281026
) -> Result<Option<Vec<String>>, D::Error>
@@ -1423,6 +1421,7 @@ impl CliUnstable {
14231421
"config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE),
14241422
"lockfile-path" => stabilized_warn(k, "1.97", STABILIZED_LOCKFILE_PATH),
14251423
"warnings" => stabilized_warn(k, "1.97", STABILIZED_WARNINGS),
1424+
"build-dir-new-layout" => stabilized_warn(k, "1.100", STABILIZED_BUILD_DIR_NEW_LAYOUT),
14261425

14271426
// Unstable features
14281427
// Sorted alphabetically:
@@ -1433,7 +1432,6 @@ impl CliUnstable {
14331432
"binary-dep-depinfo" => self.binary_dep_depinfo = parse_empty(k, v)?,
14341433
"bindeps" => self.bindeps = parse_empty(k, v)?,
14351434
"build-analysis" => self.build_analysis = parse_empty(k, v)?,
1436-
"build-dir-new-layout" => self.build_dir_new_layout = parse_empty(k, v)?,
14371435
"build-std" => self.build_std = Some(parse_list(v)),
14381436
"build-std-features" => self.build_std_features = Some(parse_list(v)),
14391437
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,

tests/build-std/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ fn basic() {
168168
[COMPILING] [..]
169169
...
170170
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
171-
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/deps/foo-[HASH])
172-
[RUNNING] unittests src/main.rs (target/[HOST_TARGET]/debug/deps/foo-[HASH])
173-
[RUNNING] tests/smoke.rs (target/[HOST_TARGET]/debug/deps/smoke-[HASH])
171+
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH])
172+
[RUNNING] unittests src/main.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH])
173+
[RUNNING] tests/smoke.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/out/smoke-[HASH])
174174
[DOCTEST] foo
175175
176176
"#]])
@@ -180,9 +180,9 @@ fn basic() {
180180
let deps_dir = Path::new("target")
181181
.join(rustc_host())
182182
.join("debug")
183-
.join("deps");
184-
assert!(p.glob(deps_dir.join("*.rlib")).count() > 0);
185-
assert_eq!(p.glob(deps_dir.join("*.dylib")).count(), 0);
183+
.join("build");
184+
assert!(p.glob(deps_dir.join("**/*.rlib")).count() > 0);
185+
assert_eq!(p.glob(deps_dir.join("**/*.dylib")).count(), 0);
186186
}
187187

188188
#[cargo_test(build_std_real)]
@@ -432,7 +432,7 @@ fn test_proc_macro() {
432432
...
433433
[COMPILING] foo v0.0.0 ([ROOT]/foo)
434434
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
435-
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH])
435+
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/out/foo-[HASH])
436436
437437
"#]])
438438
.run();

tests/testsuite/artifact_dep.rs

Lines changed: 35 additions & 31 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
);
@@ -830,7 +830,7 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {
830830
!p.bin("bar").is_file(),
831831
"artifacts are located in their own directory, exclusively, and won't be lifted up"
832832
);
833-
assert_artifact_executable_output(&p, "debug", "bar", "baz_suffix");
833+
assert_artifact_executable_output(&p, "debug", "bar-baz", "baz_suffix");
834834
}
835835

836836
#[cargo_test]
@@ -900,7 +900,7 @@ fn lib_with_selected_dashed_bin_artifact_and_lib_true() {
900900
!p.bin("bar").is_file(),
901901
"artifacts are located in their own directory, exclusively, and won't be lifted up"
902902
);
903-
assert_artifact_executable_output(&p, "debug", "bar", "baz_suffix");
903+
assert_artifact_executable_output(&p, "debug", "bar-baz", "baz_suffix");
904904
}
905905

906906
#[cargo_test]
@@ -943,7 +943,7 @@ fn allow_artifact_and_no_artifact_dep_to_same_package_within_different_dep_categ
943943
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
944944
[COMPILING] foo v0.0.0 ([ROOT]/foo)
945945
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
946-
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
946+
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
947947
[DOCTEST] foo
948948
949949
"#]])
@@ -1292,7 +1292,7 @@ fn cross_doctests_works_with_artifacts() {
12921292
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
12931293
[COMPILING] foo v0.0.1 ([ROOT]/foo)
12941294
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1295-
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/deps/foo-[HASH][EXE])
1295+
[RUNNING] unittests src/lib.rs (target/[HOST_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
12961296
[DOCTEST] foo
12971297
12981298
"#]])
@@ -1316,7 +1316,7 @@ fn cross_doctests_works_with_artifacts() {
13161316
[RUNNING] `rustc --crate-name foo [..]
13171317
[RUNNING] `rustc --crate-name foo [..]
13181318
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1319-
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/deps/foo-[HASH][EXE]`
1319+
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/build/foo/[HASH]/out/foo-[HASH][EXE]`
13201320
[DOCTEST] foo
13211321
[RUNNING] `rustdoc [..]--test src/lib.rs --test-run-directory [ROOT]/foo --target [ALT_TARGET] [..]
13221322
@@ -1422,7 +1422,7 @@ fn profile_override_basic() {
14221422
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=1 [..]`
14231423
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..] -C opt-level=3 [..]`
14241424
[RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]`
1425-
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1425+
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build_script_build`
14261426
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
14271427
[COMPILING] foo v0.0.1 ([ROOT]/foo)
14281428
@@ -2207,8 +2207,8 @@ fn env_vars_and_build_products_for_various_build_targets() {
22072207
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
22082208
[COMPILING] foo v0.0.0 ([ROOT]/foo)
22092209
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2210-
[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH][EXE])
2211-
[RUNNING] tests/main.rs (target/debug/deps/main-[HASH][EXE])
2210+
[RUNNING] unittests src/lib.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
2211+
[RUNNING] tests/main.rs (target/debug/build/foo/[HASH]/out/main-[HASH][EXE])
22122212
[DOCTEST] foo
22132213
22142214
"#]])
@@ -2416,7 +2416,11 @@ fn doc_lib_true() {
24162416

24172417
// Verify that it emits rmeta for the bin and lib dependency.
24182418
assert_eq!(p.glob("target/debug/artifact/*.rlib").count(), 0);
2419-
assert_eq!(p.glob("target/debug/deps/libbar-*.rmeta").count(), 2);
2419+
assert_eq!(
2420+
p.glob("target/debug/build/bar/*/out/libbar-*.rmeta")
2421+
.count(),
2422+
2
2423+
);
24202424

24212425
p.cargo("doc -Z bindeps")
24222426
.masquerade_as_nightly_cargo(&["bindeps"])
@@ -2508,7 +2512,7 @@ fn assert_artifact_executable_output(
25082512
if cfg!(target_env = "msvc") {
25092513
assert_eq!(
25102514
p.glob(format!(
2511-
"target/{}/deps/artifact/{}-*/bin/{}{}",
2515+
"target/{}/build/{}/*/artifact/bin/{}{}",
25122516
target_name,
25132517
dep_name,
25142518
bin_name,
@@ -2521,7 +2525,7 @@ fn assert_artifact_executable_output(
25212525
} else {
25222526
assert_eq!(
25232527
p.glob(format!(
2524-
"target/{}/deps/artifact/{}-*/bin/{}-*{}",
2528+
"target/{}/build/{}/*/artifact/bin/{}{}",
25252529
target_name,
25262530
dep_name,
25272531
bin_name,
@@ -2538,7 +2542,7 @@ fn assert_artifact_executable_output(
25382542

25392543
fn build_script_output_string(p: &Project, package_name: &str) -> String {
25402544
let paths = p
2541-
.glob(format!("target/debug/build/{}-*/output", package_name))
2545+
.glob(format!("target/debug/build/{}/*/run/stdout", package_name))
25422546
.collect::<Result<Vec<_>, _>>()
25432547
.unwrap();
25442548
assert_eq!(paths.len(), 1);
@@ -2822,7 +2826,7 @@ fn with_assumed_host_target_and_optional_build_dep() {
28222826
[COMPILING] d1 v0.0.1 ([ROOT]/foo/d1)
28232827
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
28242828
[RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..]
2825-
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
2829+
[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build_script_build`
28262830
[RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..]
28272831
[FINISHED] `dev` profile [..]
28282832
[COMPILING] foo v0.0.1 ([ROOT]/foo)
@@ -3638,7 +3642,7 @@ fn artifact_dep_target_does_not_propagate_to_deps_of_build_script() {
36383642
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
36393643
[COMPILING] foo v0.0.1 ([ROOT]/foo)
36403644
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3641-
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
3645+
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
36423646
36433647
"#]])
36443648
.masquerade_as_nightly_cargo(&["bindeps"])
@@ -3730,7 +3734,7 @@ fn artifact_dep_target_does_not_propagate_to_proc_macro() {
37303734
[COMPILING] artifact v0.0.1 ([ROOT]/foo/artifact)
37313735
[COMPILING] foo v0.0.1 ([ROOT]/foo)
37323736
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3733-
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
3737+
[RUNNING] unittests src/main.rs (target/debug/build/foo/[HASH]/out/foo-[HASH][EXE])
37343738
37353739
"#]])
37363740
.masquerade_as_nightly_cargo(&["bindeps"])

0 commit comments

Comments
 (0)