-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix cargo hack job for bin target #4
Conversation
`cargo hack --feature-powerset check --lib --tests` failed for workspace that contains a package with only bin target(s). `--all-targets` flag resolves this
The I think a comment would at least be useful for this step explaining that it should be removed if you don't have library crates. Where it gets weird is if you have a workspace with two crates, only one of which has a lib. In that case, I honestly don't know what the right way to achieve this is beyond going and calling this command once in every sub-crate with automation to decide which ones to skip. In a sense, it feels wrong for cargo to fail here in the first place. Curious to hear your take on this @taiki-e? Also, from memory, I used to have this as |
There seem to be several different issues/questions here. Should cargo-hack (or cargo?) prevent the --lib flag from passing to a crate without the library part?
The current behavior is not to allow it anyway (error is emitted by cargo). Perhaps the preferable behavior would be to:
Should we do a feature check even on binary crate?
I think it may be true that many binary crates do not have feature flags, but I don't know of any justification for not doing a feature check on a binary crate with feature flags. That said, I noticed that I'm also using Which build targets do we need to do a feature check on? (--lib/--bins vs --tests vs --all-targets, etc.)IMO, only libraries and binaries (with feature flags) need (strict) feature check in CI. (In other words, only the parts published on crates.io and used by users in the usual way (as dependencies or as binaries installed by cargo install)) I have explained several times in the past why I do not do feature checks for tests: crossbeam-rs/crossbeam#840 (comment), rust-lang/futures-rs#2216 (TL;DR: I don't see any way to properly check it or a sufficient reason for doing it) Also, at least for v1 resolver, the feature checks for build targets that enable dev-dependencies must be separate from the feature checks for library or binary. Otherwise (even with cargo-hack) feature checks for library or binary will not function properly due to feature unification. EDIT: Therefore, I think a reasonable default is to not pass any build target flags. |
Thank you for the detailed analysis! I do think Cargo's behavior could be improved here. At least to me, this is similar to rust-lang/cargo#10508; if the user isn't specifying a particular name (e.g., As for feature checking binaries, I honestly can't remember what I ran into. I suspect it was because I was also passing Your point about not checking tests is new to me, but I think I agree it makes sense. Which is all to say, I agree. Let's update the invocation to just be
Not sure if And then if someone wants a different behavior for a particular package they can just override. |
Fyi, i'm trying to demote this error into just a warn, which will solve the root problem altogether: rust-lang/cargo#14163 upstream bug: rust-lang/cargo#10958 that said, I'd say these philosophical discussions were interesting to me: #4 (comment) |
cargo hack --feature-powerset check --lib --tests
failed for workspace that contains a package with only bin target(s).--all-targets
flag resolves thisExample of error: