Skip to content

Commit d288a08

Browse files
committed
extra test for dep of artifact dep is platform specified & artifact dep itself is platform-specifeied & platform is not activated
1 parent 691ac31 commit d288a08

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/cargo/ops/tree/graph.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ fn add_pkg(
398398
{
399399
// Dependency has a `{ …, target = <triple> }`
400400
Some(target) => FeaturesFor::ArtifactDep(target),
401+
// Get the information of the dependent crate from `features_for`.
402+
// If a dependent crate is
403+
//
404+
// * specified as an artifact dep with a `target`, or
405+
// * a host dep,
406+
//
407+
// its transitive deps, including build-deps, need to be built on that target.
408+
None if features_for != FeaturesFor::default() => features_for,
409+
// Dependent crate is a normal dep, then back to old rules:
410+
//
411+
// * normal deps, dev-deps -> inherited target
412+
// * build-deps -> host
401413
None => {
402414
if dep.is_build() || dep_pkg.proc_macro() {
403415
FeaturesFor::HostDep

tests/testsuite/artifact_dep.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,76 @@ foo v0.0.0 ([ROOT]/foo)
15791579
.run();
15801580
}
15811581

1582+
#[cargo_test]
1583+
fn rename_this() {
1584+
if cross_compile::disabled() {
1585+
return;
1586+
}
1587+
let target = cross_compile::alternate();
1588+
let p = project()
1589+
.file(
1590+
"Cargo.toml",
1591+
&format!(
1592+
r#"
1593+
[package]
1594+
name = "foo"
1595+
version = "0.1.0"
1596+
edition = "2015"
1597+
1598+
[dependencies]
1599+
bar = {{ path = "bar", artifact = "bin", target = "{target}" }}
1600+
"#,
1601+
),
1602+
)
1603+
.file("src/lib.rs", "")
1604+
.file(
1605+
"bar/Cargo.toml",
1606+
&format!(
1607+
r#"
1608+
[package]
1609+
name = "bar"
1610+
version = "0.1.0"
1611+
1612+
[target.{target}.dependencies]
1613+
baz = {{ path = "../baz" }}
1614+
"#,
1615+
),
1616+
)
1617+
.file("bar/src/lib.rs", "")
1618+
.file(
1619+
"baz/Cargo.toml",
1620+
r#"
1621+
[package]
1622+
name = "baz"
1623+
version = "0.1.0"
1624+
1625+
"#,
1626+
)
1627+
.file("baz/src/lib.rs", "")
1628+
.build();
1629+
1630+
// TODO This command currently fails due to a bug in cargo but it should be fixed so that it succeeds in the future.
1631+
p.cargo("check -Z bindeps")
1632+
.masquerade_as_nightly_cargo(&["bindeps"])
1633+
.with_stderr_data(str![[r#"
1634+
[LOCKING] 2 packages to latest compatible versions
1635+
[ERROR] dependency `bar` in package `foo` requires a `bin` artifact to be present.
1636+
1637+
"#]])
1638+
.with_status(101)
1639+
.run();
1640+
1641+
// TODO This command currently fails due to a bug in cargo but it should be fixed so that it succeeds in the future.
1642+
p.cargo("tree -Z bindeps")
1643+
.masquerade_as_nightly_cargo(&["bindeps"])
1644+
.with_stderr_data(r#"...
1645+
no entry found for key
1646+
...
1647+
"#)
1648+
.with_status(101)
1649+
.run();
1650+
}
1651+
15821652
#[cargo_test]
15831653
fn targets_are_picked_up_from_non_workspace_artifact_deps() {
15841654
if cross_compile::disabled() {

0 commit comments

Comments
 (0)