Skip to content

Commit ce4df26

Browse files
authored
Store artifact deps in build unit dir (#16519)
### What does this PR try to resolve? This spawned out of #16502 (comment) when I noticed artifact dependencies are not using the new build-dir layout. This PR moves them from `<build-dir>/<profile>/deps/artifact/$pkgname-$META` (old layout) to `<build-dir>/<profile>/build/$pkgname/$META/deps/artifact/<kind>` when `-Zbuild-dir-new-layout` is enabled. cc tracking issue: #15010 ### How to test and review this PR? Added new test specifically for artifact deps r? @epage
2 parents 1e741ee + 67aaf3b commit ce4df26

4 files changed

Lines changed: 203 additions & 7 deletions

File tree

src/cargo/core/compiler/build_runner/compilation_files.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
377377
invalid
378378
),
379379
};
380-
self.layout(unit.kind)
381-
.build_dir()
382-
.artifact()
383-
.join(dir)
384-
.join(kind)
380+
self.layout(unit.kind).build_dir().artifact(&dir, kind)
385381
}
386382

387383
/// Returns the directory where information about running a build script

src/cargo/core/compiler/layout.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,12 @@ impl BuildDirLayout {
383383
}
384384
}
385385
/// Fetch the artifact path.
386-
pub fn artifact(&self) -> &Path {
387-
&self.artifact
386+
pub fn artifact(&self, pkg_dir: &str, kind: &str) -> PathBuf {
387+
if self.is_new_layout {
388+
self.build_unit(pkg_dir).join("artifact").join(kind)
389+
} else {
390+
self.artifact.join(pkg_dir).join(kind)
391+
}
388392
}
389393
/// Fetch the build unit path
390394
pub fn build_unit(&self, pkg_dir: &str) -> PathBuf {

tests/testsuite/build_dir.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,104 @@ fn template_should_handle_reject_unmatched_brackets() {
11191119
.run();
11201120
}
11211121

1122+
#[cargo_test]
1123+
fn artifact_deps() {
1124+
let p = project()
1125+
.file(
1126+
".cargo/config.toml",
1127+
r#"
1128+
[build]
1129+
target-dir = "target-dir"
1130+
build-dir = "build-dir"
1131+
"#,
1132+
)
1133+
.file(
1134+
"Cargo.toml",
1135+
r#"
1136+
[package]
1137+
name = "foo"
1138+
version = "0.0.0"
1139+
edition = "2015"
1140+
authors = []
1141+
resolver = "2"
1142+
1143+
[dependencies]
1144+
bar = { path = "bar/", artifact = ["bin:bar"] }
1145+
"#,
1146+
)
1147+
.file(
1148+
"src/main.rs",
1149+
r#"
1150+
fn main() {
1151+
println!("CARGO_BIN_DIR_BAR={}", env!("CARGO_BIN_DIR_BAR"));
1152+
println!("CARGO_BIN_FILE_BAR_bar={}", env!("CARGO_BIN_FILE_BAR_bar"));
1153+
}
1154+
"#,
1155+
)
1156+
.file(
1157+
"bar/Cargo.toml",
1158+
r#"
1159+
[package]
1160+
name = "bar"
1161+
version = "0.1.0"
1162+
edition = "2015"
1163+
authors = []
1164+
1165+
[[bin]]
1166+
name = "bar"
1167+
"#,
1168+
)
1169+
.file("bar/src/main.rs", "fn main() {}")
1170+
.build();
1171+
1172+
p.cargo("run -Zbuild-dir-new-layout -Z bindeps")
1173+
.masquerade_as_nightly_cargo(&["bindeps", "build-dir-new-layout"])
1174+
.enable_mac_dsym()
1175+
.with_stderr_data(str![[r#"
1176+
[LOCKING] 1 package to latest compatible version
1177+
[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
1178+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
1179+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1180+
[RUNNING] `target-dir/debug/foo[EXE]`
1181+
1182+
"#]])
1183+
.with_stdout_data(str![[r#"
1184+
CARGO_BIN_DIR_BAR=[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin
1185+
CARGO_BIN_FILE_BAR_bar=[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..][EXE]
1186+
1187+
"#]])
1188+
.run();
1189+
1190+
p.root().join("build-dir").assert_build_dir_layout(str![[r#"
1191+
[ROOT]/foo/build-dir/.rustc_info.json
1192+
[ROOT]/foo/build-dir/CACHEDIR.TAG
1193+
[ROOT]/foo/build-dir/debug/.cargo-lock
1194+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/bin-bar
1195+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/bin-bar.json
1196+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/dep-bin-bar
1197+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/invoked.timestamp
1198+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp
1199+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/bin-foo
1200+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/bin-foo.json
1201+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/dep-bin-foo
1202+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..][EXE]
1203+
[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..].d
1204+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE]
1205+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d
1206+
1207+
"#]]);
1208+
1209+
p.root()
1210+
.join("target-dir")
1211+
.assert_build_dir_layout(str![[r#"
1212+
[ROOT]/foo/target-dir/CACHEDIR.TAG
1213+
[ROOT]/foo/target-dir/debug/.cargo-lock
1214+
[ROOT]/foo/target-dir/debug/foo[EXE]
1215+
[ROOT]/foo/target-dir/debug/foo.d
1216+
1217+
"#]]);
1218+
}
1219+
11221220
fn parse_workspace_manifest_path_hash(hash_dir: &PathBuf) -> PathBuf {
11231221
// Since the hash will change between test runs simply find the first directories and assume
11241222
// that is the hash dir. The format is a 2 char directory followed by the remaining hash in the

tests/testsuite/build_dir_legacy.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,104 @@ fn template_should_handle_reject_unmatched_brackets() {
10271027
.run();
10281028
}
10291029

1030+
#[cargo_test]
1031+
fn artifact_deps() {
1032+
let p = project()
1033+
.file(
1034+
".cargo/config.toml",
1035+
r#"
1036+
[build]
1037+
target-dir = "target-dir"
1038+
build-dir = "build-dir"
1039+
"#,
1040+
)
1041+
.file(
1042+
"Cargo.toml",
1043+
r#"
1044+
[package]
1045+
name = "foo"
1046+
version = "0.0.0"
1047+
edition = "2015"
1048+
authors = []
1049+
resolver = "2"
1050+
1051+
[dependencies]
1052+
bar = { path = "bar/", artifact = ["bin:bar"] }
1053+
"#,
1054+
)
1055+
.file(
1056+
"src/main.rs",
1057+
r#"
1058+
fn main() {
1059+
println!("CARGO_BIN_DIR_BAR={}", env!("CARGO_BIN_DIR_BAR"));
1060+
println!("CARGO_BIN_FILE_BAR_bar={}", env!("CARGO_BIN_FILE_BAR_bar"));
1061+
}
1062+
"#,
1063+
)
1064+
.file(
1065+
"bar/Cargo.toml",
1066+
r#"
1067+
[package]
1068+
name = "bar"
1069+
version = "0.1.0"
1070+
edition = "2015"
1071+
authors = []
1072+
1073+
[[bin]]
1074+
name = "bar"
1075+
"#,
1076+
)
1077+
.file("bar/src/main.rs", "fn main() {}")
1078+
.build();
1079+
1080+
p.cargo("run -Z bindeps")
1081+
.masquerade_as_nightly_cargo(&["bindeps"])
1082+
.enable_mac_dsym()
1083+
.with_stderr_data(str![[r#"
1084+
[LOCKING] 1 package to latest compatible version
1085+
[COMPILING] bar v0.1.0 ([ROOT]/foo/bar)
1086+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
1087+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1088+
[RUNNING] `target-dir/debug/foo[EXE]`
1089+
1090+
"#]])
1091+
.with_stdout_data(str![[r#"
1092+
CARGO_BIN_DIR_BAR=[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin
1093+
CARGO_BIN_FILE_BAR_bar=[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..][EXE]
1094+
1095+
"#]])
1096+
.run();
1097+
1098+
p.root().join("build-dir").assert_build_dir_layout(str![[r#"
1099+
[ROOT]/foo/build-dir/.rustc_info.json
1100+
[ROOT]/foo/build-dir/CACHEDIR.TAG
1101+
[ROOT]/foo/build-dir/debug/.cargo-lock
1102+
[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/bin-bar
1103+
[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/bin-bar.json
1104+
[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/dep-bin-bar
1105+
[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/invoked.timestamp
1106+
[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/bin-foo
1107+
[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/bin-foo.json
1108+
[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/dep-bin-foo
1109+
[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/invoked.timestamp
1110+
[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..][EXE]
1111+
[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..].d
1112+
[ROOT]/foo/build-dir/debug/deps/foo[..][EXE]
1113+
[ROOT]/foo/build-dir/debug/deps/foo[..].d
1114+
1115+
"#]]);
1116+
1117+
p.root()
1118+
.join("target-dir")
1119+
.assert_build_dir_layout(str![[r#"
1120+
[ROOT]/foo/target-dir/CACHEDIR.TAG
1121+
[ROOT]/foo/target-dir/debug/.cargo-lock
1122+
[ROOT]/foo/target-dir/debug/foo[EXE]
1123+
[ROOT]/foo/target-dir/debug/foo.d
1124+
1125+
"#]]);
1126+
}
1127+
10301128
fn parse_workspace_manifest_path_hash(hash_dir: &PathBuf) -> PathBuf {
10311129
// Since the hash will change between test runs simply find the first directories and assume
10321130
// that is the hash dir. The format is a 2 char directory followed by the remaining hash in the

0 commit comments

Comments
 (0)