cargo-hack icon indicating copy to clipboard operation
cargo-hack copied to clipboard

cargo hack ... --features X requires feature X on all workspace crates

Open leighmcculloch opened this issue 2 years ago • 3 comments

Running cargo-hack on a workspace requesting a specific feature to be enabled will require the feature to be enabled on every crate, and will cause an error when a crate doesn't have that feature.

It's unclear if this is the intended behavior, so this might be a feature request, or it might not be and then this might be a bug.

I expected when I use the --features X option that it would apply to the crates that have the feature and not to the ones that don't have it.

For example, if a repo has multiple crates, some with a testutils feature, and the developer wishes to run all tests with the testutils feature enabled, you might think the following command would work:

cargo hack test --features testutils

But it will result in:

info: running `cargo test --features testutils` on crate_a (2/14)
error: none of the selected packages contains these features: testutils

leighmcculloch avatar Aug 16 '22 22:08 leighmcculloch

You need to use --ignore-unknown-features flag

https://github.com/taiki-e/cargo-hack#--ignore-unknown-features

Skip passing --features to cargo if that feature does not exist.

taiki-e avatar Aug 17 '22 02:08 taiki-e

Ahh. Thank you. Sorry for the noise!

leighmcculloch avatar Aug 17 '22 03:08 leighmcculloch

This error happens when using --group-features regardless of whether --ignore-unknown-features is passed, so it seems like this issue isn't fully resolved. I don't see an existing issue for this, so reopening this one.

For a command that looks like:

cargo hack --feature-powerset --ignore-unknown-features --group-features testutils,serde --group-features hostfn_log_fmt_values,hostfn_create_x_from_ed25519 check

Displays a warning like:

warning: --ignore-unknown-features for --group-features is not fully implemented and may not work as intended

Displays an error like:

info: running `cargo check --no-default-features --features testutils,serde` on soroban-test-wasms (10/40)
error: none of the selected packages contains these features: serde, testutils

leighmcculloch avatar Sep 27 '22 21:09 leighmcculloch