Fix panic when running cargo tree on a package with a cross compiled bindep#13207
Fix panic when running cargo tree on a package with a cross compiled bindep#13207rukai wants to merge 1 commit intorust-lang:masterfrom
cargo tree on a package with a cross compiled bindep#13207Conversation
|
r? @epage (rustbot has picked a reviewer for you, use r? to override) |
|
probably makes sense for |
weihanglo
left a comment
There was a problem hiding this comment.
Sorry for the way too long delay of the review 😞.
| ) -> Vec<InternedString> { | ||
| self.activated_features_int(pkg_id, features_for) | ||
| .expect("activated_features for invalid package") | ||
| let fk = features_for.apply_opts(&self.opts); |
There was a problem hiding this comment.
Would like to see this refactor being in its own commit, to following atomic commit principle.
| .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.
I might have a rotted memory of artifact dependencies. However, even when target is present the dependency might still be depended as a normal lib (with lib = true). The fix doesn't look 100% correct to me for this reason.
There was a problem hiding this comment.
Okay this looks like an adaption of my own patch... Need to refresh my memory 😅.
| } | ||
|
|
||
| #[cargo_test] | ||
| fn artifact_dep_target_specified() { |
There was a problem hiding this comment.
This test passes even without the patch in ops::tree::graph. We should probably first create a test verifying the current panic behavior in a commit, followed by the other commit fixing both the behavior and the test.
There was a problem hiding this comment.
I did however leave out the
None if features_for != FeaturesFor::default() => features_for, because that seems wrong to me. proc macro and build dependencies of a bindep need to be compiled for the host, regardless of the bindeps target, otherwise the host cant run them to build the bindep.
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.
By default,
build-dependenciesare built for the host, whiledependenciesanddev-dependenciesare built for the target. You can specify thetargetattribute to build for a specific target, such astarget = "wasm32-wasi"; a literaltarget = "target"will build for the target even if specifying a build dependency. (If the target is not available, this will result in an error at build time, just as if building the specified crate with a--targetoption for an unavailable target.)
8ab6462 to
eaa50a9
Compare
eaa50a9 to
77435e0
Compare
Add failing test: artifact_dep_target_specified This PR pulls the failing test out of #13207 [During review](#13207 (comment)), it was requested there be a previous commit with a failing test. It will be a while before I have the time to address the other issues with the PR, so I figured for now we should land this failing test first.
|
☔ The latest upstream changes (presumably #13816) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@rukai are you still interested in fixing this? |
|
I cant afford the time to work on this any time soon. |
…hanglo improve error reporting when feature not found in `activated_features` Pulls the error message refactor out of #14593 (originally #13207) to improve error reporting when we fail to get the list of activated features enabled for the given package. It now fully lists the activated_features hashmap keys too. From the [original author](#13207 (comment)): > I moved `activated_features_int` into `activated_features` and `activated_features_unverified` as I was concerned of the performance cost of generating the full error when its not a fatal error and may occur many times. Old vs new error message: ```diff - activated_features for invalid package: features did not find PackageId { name: "bindep", version: "0.0.0", source: "[ROOT]/foo/bindep" } NormalOrDev + did not find features for (PackageId { name: "bindep", version: "0.0.0", source: "[ROOT]/foo/bindep" }, NormalOrDev) within activated_features: + [ + ( + PackageId { + name: "bindep", + version: "0.0.0", + source: "[ROOT]/foo/bindep", + }, + ArtifactDep( + CompileTarget { + name: "[ALT_TARGET]", + }, + ), + ), + ( + PackageId { + name: "foo", + version: "0.0.0", + source: "[ROOT]/foo", + }, + NormalOrDev, + ), + ] ``` r? weihanglo
…weihanglo Fix panic when running cargo tree on a package with a cross compiled bindep ### What does this PR try to resolve? This is an attempt to close out `@rukai's` [PR](#13207 (comment)) for #12358 and #10593 by adjusting the new integration test and resolving merge conflicts. I have also separated the changes into atomic commits as per [previous review](#13207 (comment)). ### How should we test and review this PR? The integration test that has been edited here is sufficient, plus the new integration test that confirms a more specific case where `cargo tree` throws an error. ### Additional information I have confirmed the test `artifact_dep_target_specified` fails on master branch and succeeds on this branch. The first commit fixes the panic and the integration test. Commits 2 and 3 add other tests that confirm behaviour mentioned in related issues. Commits: 1. [Fix panic when running cargo tree on a package with a cross compiled bindep](5c5ea78) - fixes some panics and changes the integration test to succeed 2. [test: cargo tree panic on artifact dep target deactivated](ed294ab) - adds test to confirm the behaviour for the specific panic from [#10539 (comment)](#10593 (comment))
|
We can probably close this |
|
Yes absolutely. Thank you! |
What does this PR try to resolve?
This PR fixes the
cargo treepanic described in #12358 and #10593How should we test and review this PR?
The new integration test is sufficient.
Additional information
There was discussion of holding off on this until a full design of how to present bindeps in
cargo treeis arrived at.However I think it makes sense to land this PR first as:
cargo treein many more bindeps use cases.So this PR is a good first step towards full support in
cargo tree.The changes to the
activated_featuresmethods are not related to the fix but just the improved error reporting I needed to fully diagnose the issue.I moved
activated_features_intintoactivated_featuresandactivated_features_unverifiedas I was concerned of the performance cost of generating the full error when its not a fatal error and may occur many times.I think this change will bring value in the future but I am happy to remove it if it is undesired.
I actually wrote up the test + fix independently before discovering #10593 (comment) , once I discovered it I copied in some specific parts to improve comments + correctness
I did however leave out the
None if features_for != FeaturesFor::default() => features_for,because that seems wrong to me. proc macro and build dependencies of a bindep need to be compiled for the host, regardless of the bindeps target, otherwise the host cant run them to build the bindep.