Skip to content
Merged
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
6 changes: 1 addition & 5 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/cargo/core/compiler/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 98 additions & 0 deletions tests/testsuite/build_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,104 @@ fn template_should_handle_reject_unmatched_brackets() {
.run();
}

#[cargo_test]
fn artifact_deps() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also check those environment variables are pointing to the corret directory layout?

(the directory and bin path one maybe?)

https://doc.rust-lang.org/beta/cargo/reference/unstable.html#artifact-dependencies-environment-variables

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good call out, yeah let me include those in the test

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
Expand Down
98 changes: 98 additions & 0 deletions tests/testsuite/build_dir_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down