Skip to content

Commit a5bedb3

Browse files
committed
test(bindeps): reveal a bug of the propagation of artifact dependency
Add 2 test cases to reproduce a bug of `-Zbindeps`. Basically, if - a package `foo` has an artifact dependency `artifact` with a specified target TARGET_ARTIFACT different from host TARGET_HOST, - `artifact` depends on proc macro `macro`, - `macro` conditionally depends on `arch` on TARGET_HOST, cargo build would panic on TARGET_HOST with the following error message: ``` did not find features for (PackageId { name: "arch", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/arch" }, ArtifactDep(CompileTarget { name: "x86_64-apple-darwin" })) within activated_features: [ ( PackageId { name: "foo", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo", }, NormalOrDev, ), ( PackageId { name: "macro", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/macro", }, ArtifactDep( CompileTarget { name: "x86_64-apple-darwin", }, ), ), ( PackageId { name: "artifact", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/artifact", }, ArtifactDep( CompileTarget { name: "x86_64-apple-darwin", }, ), ), ] ``` Similar panic happens when - a package `foo` has an artifact dependency `artifact` with a specified target TARGET_ARTIFACT different from host TARGET_HOST, - `artifact` has a build dependency `builder`, - `builder` conditionally depends on `arch` on TARGET_HOST. Signed-off-by: Changyuan Lyu <changyuan.lv@gmail.com>
1 parent 5c03433 commit a5bedb3

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

tests/testsuite/artifact_dep.rs

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,3 +3394,183 @@ staticlib present: true
33943394
"#]],
33953395
);
33963396
}
3397+
3398+
#[should_panic]
3399+
#[cargo_test]
3400+
fn artifact_dep_target_does_not_propagate_to_deps_of_build_script() {
3401+
if cross_compile_disabled() {
3402+
panic!("panic expected");
3403+
}
3404+
let bindeps_target = cross_compile::alternate();
3405+
let native_target = cross_compile::native();
3406+
3407+
let p = project()
3408+
.file(
3409+
"Cargo.toml",
3410+
&r#"
3411+
[package]
3412+
name = "foo"
3413+
version = "0.0.1"
3414+
edition = "2015"
3415+
resolver = "2"
3416+
3417+
[dependencies.artifact]
3418+
path = "artifact"
3419+
artifact = "bin"
3420+
target = "$TARGET"
3421+
"#
3422+
.replace("$TARGET", bindeps_target),
3423+
)
3424+
.file(
3425+
"src/main.rs",
3426+
r#"
3427+
fn main() {
3428+
let _b = include_bytes!(env!("CARGO_BIN_FILE_ARTIFACT"));
3429+
}
3430+
"#,
3431+
)
3432+
.file(
3433+
"artifact/Cargo.toml",
3434+
r#"
3435+
[package]
3436+
name = "artifact"
3437+
version = "0.0.1"
3438+
edition = "2015"
3439+
3440+
[build-dependencies]
3441+
builder = { path = "../builder" }
3442+
"#,
3443+
)
3444+
.file("artifact/src/main.rs", "fn main() { }")
3445+
.file(
3446+
"artifact/build.rs",
3447+
r#"
3448+
extern crate builder;
3449+
fn main() {
3450+
let _ = builder::add(1, 2);
3451+
}
3452+
"#,
3453+
)
3454+
.file(
3455+
"builder/Cargo.toml",
3456+
&r#"
3457+
[package]
3458+
name = "builder"
3459+
version = "0.0.1"
3460+
edition = "2015"
3461+
3462+
[target.'$TARGET'.dependencies]
3463+
arch = { path = "../arch" }
3464+
"#
3465+
.replace("$TARGET", native_target),
3466+
)
3467+
.file(
3468+
"builder/src/lib.rs",
3469+
r#"
3470+
extern crate arch;
3471+
pub fn add(a: i32, b: i32) -> i32 { arch::add(a, b) }
3472+
"#,
3473+
)
3474+
.file(
3475+
"arch/Cargo.toml",
3476+
r#"
3477+
[package]
3478+
name = "arch"
3479+
version = "0.0.1"
3480+
edition = "2015"
3481+
"#,
3482+
)
3483+
.file(
3484+
"arch/src/lib.rs",
3485+
r#"pub fn add(a: i32, b: i32) -> i32 { a + b }"#,
3486+
)
3487+
.build();
3488+
p.cargo("test -Z bindeps")
3489+
.with_stderr_data(str![[""]])
3490+
.masquerade_as_nightly_cargo(&["bindeps"])
3491+
.run();
3492+
}
3493+
3494+
#[should_panic]
3495+
#[cargo_test]
3496+
fn artifact_dep_target_does_not_propagate_to_proc_macro() {
3497+
if cross_compile_disabled() {
3498+
panic!("panic expected");
3499+
}
3500+
let bindeps_target = cross_compile::alternate();
3501+
let native_target = cross_compile::native();
3502+
3503+
let p = project()
3504+
.file(
3505+
"Cargo.toml",
3506+
&r#"
3507+
[package]
3508+
name = "foo"
3509+
version = "0.0.1"
3510+
edition = "2015"
3511+
resolver = "2"
3512+
3513+
[dependencies.artifact]
3514+
path = "artifact"
3515+
artifact = "bin"
3516+
target = "$TARGET"
3517+
"#
3518+
.replace("$TARGET", bindeps_target),
3519+
)
3520+
.file(
3521+
"src/main.rs",
3522+
r#"
3523+
fn main() {
3524+
let _b = include_bytes!(env!("CARGO_BIN_FILE_ARTIFACT"));
3525+
}
3526+
"#,
3527+
)
3528+
.file(
3529+
"artifact/Cargo.toml",
3530+
r#"
3531+
[package]
3532+
name = "artifact"
3533+
version = "0.0.1"
3534+
edition = "2015"
3535+
3536+
[dependencies]
3537+
macro = { path = "../macro" }
3538+
"#,
3539+
)
3540+
.file("artifact/src/main.rs", "fn main() { }")
3541+
.file(
3542+
"macro/Cargo.toml",
3543+
&r#"
3544+
[package]
3545+
name = "macro"
3546+
version = "0.0.1"
3547+
edition = "2015"
3548+
3549+
[lib]
3550+
proc-macro = true
3551+
3552+
[target.'$TARGET'.dependencies]
3553+
arch = { path = "../arch" }
3554+
"#
3555+
.replace("$TARGET", native_target),
3556+
)
3557+
.file("macro/src/lib.rs", "")
3558+
.file(
3559+
"arch/Cargo.toml",
3560+
r#"
3561+
[package]
3562+
name = "arch"
3563+
version = "0.0.1"
3564+
edition = "2015"
3565+
"#,
3566+
)
3567+
.file(
3568+
"arch/src/lib.rs",
3569+
"pub fn add(a: i32, b: i32) -> i32 { a + b }",
3570+
)
3571+
.build();
3572+
p.cargo("test -Z bindeps")
3573+
.with_stderr_data(str![[""]])
3574+
.masquerade_as_nightly_cargo(&["bindeps"])
3575+
.run();
3576+
}

0 commit comments

Comments
 (0)