From 0668547a68008792b2af3c98676e3d04ba076b9a Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 28 Nov 2022 13:56:27 +0000 Subject: [PATCH] test(bindeps): target field specified and `optional = true` coexist --- tests/testsuite/artifact_dep.rs | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 0665df649fd5..8a4c1f536b27 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2342,3 +2342,55 @@ fn calc_bin_artifact_fingerprint() { ) .run(); } + +#[cargo_test] +fn build_with_target_and_optional() { + // This is a incorrect behaviour got to be fixed. + // See rust-lang/cargo#10526 + if cross_compile::disabled() { + return; + } + let target = cross_compile::alternate(); + let p = project() + .file( + "Cargo.toml", + &r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2021" + [dependencies] + d1 = { path = "d1", artifact = "bin", optional = true, target = "$TARGET" } + "# + .replace("$TARGET", target), + ) + .file( + "src/main.rs", + r#" + fn main() { + let _b = include_bytes!(env!("CARGO_BIN_FILE_D1")); + } + "#, + ) + .file( + "d1/Cargo.toml", + r#" + [package] + name = "d1" + version = "0.0.1" + edition = "2021" + "#, + ) + .file("d1/src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -Z bindeps -F d1 -v") + .masquerade_as_nightly_cargo(&["bindeps"]) + .with_stderr_contains( + "\ +[ERROR] environment variable `CARGO_BIN_FILE_D1` not defined +", + ) + .with_status(101) + .run(); +}