Skip to content

Commit

Permalink
Fix panic when running cargo tree on a package with a cross compile…
Browse files Browse the repository at this point in the history
…d bindep
  • Loading branch information
rukai authored and elchukc committed Oct 11, 2024
1 parent ab71ba9 commit 5c5ea78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
30 changes: 26 additions & 4 deletions src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,32 @@ fn add_pkg(
let dep_pkg = graph.package_map[&dep_id];

for dep in deps {
let dep_features_for = if dep.is_build() || dep_pkg.proc_macro() {
FeaturesFor::HostDep
} else {
features_for
let dep_features_for = match dep
.artifact()
.and_then(|artifact| artifact.target())
.and_then(|target| target.to_resolved_compile_target(requested_kind))
{
// Dependency has a `{ …, target = <triple> }`
Some(target) => FeaturesFor::ArtifactDep(target),
// Get the information of the dependent crate from `features_for`.
// If a dependent crate is
//
// * specified as an artifact dep with a `target`, or
// * a host dep,
//
// its transitive deps, including build-deps, need to be built on that target.
None if features_for != FeaturesFor::default() => features_for,
// Dependent crate is a normal dep, then back to old rules:
//
// * normal deps, dev-deps -> inherited target
// * build-deps -> host
None => {
if dep.is_build() || dep_pkg.proc_macro() {
FeaturesFor::HostDep
} else {
features_for
}
}
};
let dep_index = add_pkg(
graph,
Expand Down
13 changes: 6 additions & 7 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,15 +1568,14 @@ fn artifact_dep_target_specified() {
.with_status(0)
.run();

// TODO: This command currently fails due to a bug in cargo but it should be fixed so that it succeeds in the future.
p.cargo("tree -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stdout_data("")
.with_stderr_data(r#"...
[..]did not find features for (PackageId { name: "bindep", version: "0.0.0", source: "[..]" }, NormalOrDev) within activated_features:[..]
...
"#)
.with_status(101)
.with_stdout_data(str![[r#"
foo v0.0.0 ([ROOT]/foo)
└── bindep v0.0.0 ([ROOT]/foo/bindep)
"#]])
.with_status(0)
.run();
}

Expand Down

0 comments on commit 5c5ea78

Please sign in to comment.