diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index e5f5efb8fb0..3d992ca058e 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -377,11 +377,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> { invalid ), }; - self.layout(unit.kind) - .build_dir() - .artifact() - .join(dir) - .join(kind) + self.layout(unit.kind).build_dir().artifact(&dir, kind) } /// Returns the directory where information about running a build script diff --git a/src/cargo/core/compiler/layout.rs b/src/cargo/core/compiler/layout.rs index 664c273a6c5..0316c7b3950 100644 --- a/src/cargo/core/compiler/layout.rs +++ b/src/cargo/core/compiler/layout.rs @@ -383,8 +383,12 @@ impl BuildDirLayout { } } /// Fetch the artifact path. - pub fn artifact(&self) -> &Path { - &self.artifact + pub fn artifact(&self, pkg_dir: &str, kind: &str) -> PathBuf { + if self.is_new_layout { + self.build_unit(pkg_dir).join("artifact").join(kind) + } else { + self.artifact.join(pkg_dir).join(kind) + } } /// Fetch the build unit path pub fn build_unit(&self, pkg_dir: &str) -> PathBuf { diff --git a/tests/testsuite/build_dir.rs b/tests/testsuite/build_dir.rs index edd02a8ca8d..e2350e7324d 100644 --- a/tests/testsuite/build_dir.rs +++ b/tests/testsuite/build_dir.rs @@ -1119,6 +1119,104 @@ fn template_should_handle_reject_unmatched_brackets() { .run(); } +#[cargo_test] +fn artifact_deps() { + let p = project() + .file( + ".cargo/config.toml", + r#" + [build] + target-dir = "target-dir" + build-dir = "build-dir" + "#, + ) + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + edition = "2015" + authors = [] + resolver = "2" + + [dependencies] + bar = { path = "bar/", artifact = ["bin:bar"] } + "#, + ) + .file( + "src/main.rs", + r#" + fn main() { + println!("CARGO_BIN_DIR_BAR={}", env!("CARGO_BIN_DIR_BAR")); + println!("CARGO_BIN_FILE_BAR_bar={}", env!("CARGO_BIN_FILE_BAR_bar")); + } + "#, + ) + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + edition = "2015" + authors = [] + + [[bin]] + name = "bar" + "#, + ) + .file("bar/src/main.rs", "fn main() {}") + .build(); + + p.cargo("run -Zbuild-dir-new-layout -Z bindeps") + .masquerade_as_nightly_cargo(&["bindeps", "build-dir-new-layout"]) + .enable_mac_dsym() + .with_stderr_data(str![[r#" +[LOCKING] 1 package to latest compatible version +[COMPILING] bar v0.1.0 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target-dir/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +CARGO_BIN_DIR_BAR=[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin +CARGO_BIN_FILE_BAR_bar=[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..][EXE] + +"#]]) + .run(); + + p.root().join("build-dir").assert_build_dir_layout(str![[r#" +[ROOT]/foo/build-dir/.rustc_info.json +[ROOT]/foo/build-dir/CACHEDIR.TAG +[ROOT]/foo/build-dir/debug/.cargo-lock +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/bin-bar +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/bin-bar.json +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/dep-bin-bar +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/fingerprint/invoked.timestamp +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/bin-foo +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/bin-foo.json +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/dep-bin-foo +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..][EXE] +[ROOT]/foo/build-dir/debug/build/bar/[HASH]/artifact/bin/bar[..].d +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE] +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d + +"#]]); + + p.root() + .join("target-dir") + .assert_build_dir_layout(str![[r#" +[ROOT]/foo/target-dir/CACHEDIR.TAG +[ROOT]/foo/target-dir/debug/.cargo-lock +[ROOT]/foo/target-dir/debug/foo[EXE] +[ROOT]/foo/target-dir/debug/foo.d + +"#]]); +} + fn parse_workspace_manifest_path_hash(hash_dir: &PathBuf) -> PathBuf { // Since the hash will change between test runs simply find the first directories and assume // that is the hash dir. The format is a 2 char directory followed by the remaining hash in the diff --git a/tests/testsuite/build_dir_legacy.rs b/tests/testsuite/build_dir_legacy.rs index bd539b58bc7..754281bba80 100644 --- a/tests/testsuite/build_dir_legacy.rs +++ b/tests/testsuite/build_dir_legacy.rs @@ -1027,6 +1027,104 @@ fn template_should_handle_reject_unmatched_brackets() { .run(); } +#[cargo_test] +fn artifact_deps() { + let p = project() + .file( + ".cargo/config.toml", + r#" + [build] + target-dir = "target-dir" + build-dir = "build-dir" + "#, + ) + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + edition = "2015" + authors = [] + resolver = "2" + + [dependencies] + bar = { path = "bar/", artifact = ["bin:bar"] } + "#, + ) + .file( + "src/main.rs", + r#" + fn main() { + println!("CARGO_BIN_DIR_BAR={}", env!("CARGO_BIN_DIR_BAR")); + println!("CARGO_BIN_FILE_BAR_bar={}", env!("CARGO_BIN_FILE_BAR_bar")); + } + "#, + ) + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + edition = "2015" + authors = [] + + [[bin]] + name = "bar" + "#, + ) + .file("bar/src/main.rs", "fn main() {}") + .build(); + + p.cargo("run -Z bindeps") + .masquerade_as_nightly_cargo(&["bindeps"]) + .enable_mac_dsym() + .with_stderr_data(str![[r#" +[LOCKING] 1 package to latest compatible version +[COMPILING] bar v0.1.0 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target-dir/debug/foo[EXE]` + +"#]]) + .with_stdout_data(str![[r#" +CARGO_BIN_DIR_BAR=[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin +CARGO_BIN_FILE_BAR_bar=[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..][EXE] + +"#]]) + .run(); + + p.root().join("build-dir").assert_build_dir_layout(str![[r#" +[ROOT]/foo/build-dir/.rustc_info.json +[ROOT]/foo/build-dir/CACHEDIR.TAG +[ROOT]/foo/build-dir/debug/.cargo-lock +[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/bin-bar +[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/bin-bar.json +[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/dep-bin-bar +[ROOT]/foo/build-dir/debug/.fingerprint/bar-[HASH]/invoked.timestamp +[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/bin-foo +[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/bin-foo.json +[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/dep-bin-foo +[ROOT]/foo/build-dir/debug/.fingerprint/foo-[HASH]/invoked.timestamp +[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..][EXE] +[ROOT]/foo/build-dir/debug/deps/artifact/bar-[HASH]/bin/bar[..].d +[ROOT]/foo/build-dir/debug/deps/foo[..][EXE] +[ROOT]/foo/build-dir/debug/deps/foo[..].d + +"#]]); + + p.root() + .join("target-dir") + .assert_build_dir_layout(str![[r#" +[ROOT]/foo/target-dir/CACHEDIR.TAG +[ROOT]/foo/target-dir/debug/.cargo-lock +[ROOT]/foo/target-dir/debug/foo[EXE] +[ROOT]/foo/target-dir/debug/foo.d + +"#]]); +} + fn parse_workspace_manifest_path_hash(hash_dir: &PathBuf) -> PathBuf { // Since the hash will change between test runs simply find the first directories and assume // that is the hash dir. The format is a 2 char directory followed by the remaining hash in the