-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
install fails earlier when no binaries can be found #9576
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I've been testing locally with the cargo-lock crate, which has a bin target that requires the
with this patch, cargo gives the same error, but has skipped the compile phase, meaning it only takes 1.26s:
|
r? @ehuss Thanks for the PR! Adding compile modes can cause some subtle issues since it is threaded in so many places. I was wondering if it would be possible to just change the filter instead? That is, perhaps somewhere in if !compile_opts.filter.is_specific() {
compile_opts.filter = CompileFilter::new(
LibRule::False,
FilterRule::All,
FilterRule::Just(vec![]),
FilterRule::Just(vec![]),
FilterRule::Just(vec![]),
);
} This should change it so that if all the bins get filtered by As for the test, I would probably just update |
this automatically filters out the lib targets in `cargo install` when no specific targets are provided by the user, so they won't get accidentally built. now when you try to install a crate with no satisfied bin targets, cargo will skip the meat of the compile phase and give the same error message it currently gives when it finds no bin targets at all. a new flag called `warn_unmatched` was also added to `CompileFilter::Only` that can suppress the warning about unmatched target filters. fixes rust-lang#8970
bb54614
to
9a131b5
Compare
heya @ehuss, thanks so much for the review.. I'm finally getting around to this feedback. I ran with your suggestion and tweaked it a bit to make sure a spurious warning wasn't accidentally reported when overriding the I realized there were a lot of tests already covering install with or without the necessary features in I could also see an argument for diving deeper and making sure external dependencies aren't fetched when trying to install a binary that doesn't have a feature requirement met -- this would actually exercise the new behavior more fully. not sure how important that is though, wdyt? |
forgot to mention, I force pushed my changes as a new commit because this was a totally different approach. hope that is OK! |
Hm, so this seems to cause a regression in the error message for trying to install a library. I think we want to try to keep the original error message there, as it contains some important help for new users. In full, it looks like this:
Changing that to Would it be possible to rework the check here to retain that error?
I think that might be too difficult or too complex to be worth attempting.
Yep, that's fine. |
Ping @marshall Just checking in to see if you are still interested in working on this, or if you had any questions. |
@ehuss thanks for the ping, I meant to address this a while ago. I will send an updated patch soon |
the CompileFilter created by cargo install when no targets are specified now has it's own constructor `new_bare_install`, and matching checker `is_bare_install`. `is_bare_install` is now used instead of `is_specific` when outputting a library error message. also added a small doc comment for the new `warn_unmatched` flag
heya @ehuss, I addressed both of your concerns in this latest commit. lmk what you think! |
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.
This doesn't seem to have any tests for the new behavior.
@@ -796,6 +813,21 @@ impl CompileFilter { | |||
} | |||
} | |||
|
|||
pub fn is_bare_install(&self) -> bool { |
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.
I'm a little unclear, why doesn't this just check for the warn_unmatched
value?
☔ The latest upstream changes (presumably #10305) made this pull request unmergeable. Please resolve the merge conflicts. |
Don't error if no binaries were installed ### What does this PR try to resolve? Fixes #10289, which contains a thorough description of the problem. Briefly, if we interpret `cargo install` and `cargo install --bins` as "install the binaries that are available", it should not be considered an error if no binaries ended up being installed due to required features. Instead, this should provide the user with a warning that this may not have been what they intended. ### Additional information Given that #9576 seems to have stalled, I figured I'd try to land this first [after all](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/cargo.20install.20--bins.20when.20no.20binaries.20match).
Ping @marshall, just wondering if you're still interested in working on this or if you had any questions. |
I'm closing this due to inactivity. If you (or anyone else) wants to pick this up again, feel free to open a new PR (it looks like #10842 is currently open). |
fixes #8970
this automatically filters out the lib targets in
cargo install
when no specific targets are provided by the user, so they won't get accidentally built.now when you try to install a crate with no satisfied bin targets, cargo will skip the meat of the compile phase and give the same error message it currently gives when it finds no bin targets at all.
a new flag called
warn_unmatched
was also added toCompileFilter::Only
that can suppress the warning about unmatched target filters.