-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix panic when running cargo tree
on a package with a cross compiled bindep
#13207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See https://rust-lang.github.io/rfcs/3028-cargo-binary-dependencies.html#reference-level-explanation, so arguably some build deps could be built for a target platform.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,10 +391,20 @@ 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might have a rotted memory of artifact dependencies. However, even when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay this looks like an adaption of my own patch... Need to refresh my memory 😅. |
||
None => { | ||
if dep.is_build() || dep_pkg.proc_macro() { | ||
FeaturesFor::HostDep | ||
} else { | ||
features_for | ||
} | ||
} | ||
}; | ||
let dep_index = add_pkg( | ||
graph, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1497,6 +1497,55 @@ foo v0.0.0 ([CWD]) | |
) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn artifact_dep_target_specified() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test passes even without the patch in |
||
if cross_compile::disabled() { | ||
return; | ||
} | ||
let target = cross_compile::alternate(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
&r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.0" | ||
authors = [] | ||
resolver = "2" | ||
|
||
[dependencies] | ||
bindep = { path = "bindep", artifact = "bin", target = "$TARGET" } | ||
"# | ||
.replace("$TARGET", target), | ||
) | ||
.file("src/lib.rs", "") | ||
.file("bindep/Cargo.toml", &basic_manifest("bindep", "0.0.0")) | ||
.file("bindep/src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("check -Z bindeps") | ||
.masquerade_as_nightly_cargo(&["bindeps"]) | ||
.with_stderr_contains( | ||
r#"[COMPILING] bindep v0.0.0 ([CWD]/bindep) | ||
[CHECKING] foo v0.0.0 ([CWD]) | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]"#, | ||
) | ||
.with_status(0) | ||
.run(); | ||
|
||
p.cargo("tree -Z bindeps") | ||
.masquerade_as_nightly_cargo(&["bindeps"]) | ||
.with_stdout( | ||
"\ | ||
foo v0.0.0 ([CWD]) | ||
└── bindep v0.0.0 ([CWD]/bindep)", | ||
) | ||
.with_status(0) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn targets_are_picked_up_from_non_workspace_artifact_deps() { | ||
if cross_compile::disabled() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like to see this refactor being in its own commit, to following atomic commit principle.