Skip to content
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

duplicate feature runs when default feature defined #155

Closed
leighmcculloch opened this issue Jul 20, 2022 · 4 comments
Closed

duplicate feature runs when default feature defined #155

leighmcculloch opened this issue Jul 20, 2022 · 4 comments
Labels
C-question Category: A question

Comments

@leighmcculloch
Copy link

leighmcculloch commented Jul 20, 2022

When I use cargo hack --feature-power with a crate that has a default feature defined, cargo-hack runs the default feature set, as well as the features defined in the default feature set, and the same feature set is run twice.

For example, with the following features defined:

[features]
default = ["std"]
std = ["alloc"]
alloc = []

A cargo hack --feature-powerset will run the following combinations:

❯ cargo hack check --feature-powerset 2>&1 | grep 'info:'
info: running `cargo check --no-default-features` on ... (1/4)
info: running `cargo check --no-default-features --features alloc` on ... (2/4)
info: running `cargo check --no-default-features --features default` on ... (3/4)
info: running `cargo check --no-default-features --features std` on ... (4/4)

The std and default feature set are the same, and yet it runs them both. This problem has a larger impact when more feature sets are defined where many jobs are repeated.

It would be ideal if the feature powerset feature identified when the default and another featureset overlap, and then only run one of them. For example, it would be ideal if the above command resulted in the following output:

❯ cargo hack check --feature-powerset 2>&1 | grep 'info:'
info: running `cargo check --no-default-features` on ... (1/3)
info: running `cargo check --no-default-features --features alloc` on ... (2/3)
info: running `cargo check --no-default-features --features std` on ... (3/3)
@taiki-e
Copy link
Owner

taiki-e commented Jul 20, 2022

No. If default = [...] is defined in features section, Cargo sets #[cfg(feature = "default")] when default features are enabled, so it is not equal to --no-default-features + --features=std. (e.g., async-std uses it)

@taiki-e taiki-e added the C-question Category: A question label Jul 20, 2022
@taiki-e
Copy link
Owner

taiki-e commented Jul 20, 2022

As discussed in #81, cargo-hack deduplicates any fully equivalent feature combinations based on how the cargo features work.
On the other hand, determining that --features=default and --features=std are equivalent in your case, probably requires something like a heuristic that excludes feature combinations based on how cfg is actually used. (I think it is probably very hard to implement it properly and it takes time because it is necessary to scan all the codes.)

If you can guarantee that default and std features are exactly the same, the currently recommended approach is to use the --exclude-features option to exclude --features=default.
If your crate has many features, the currently recommended approach is to use the --depth option to limit the maximum number of simultaneous feature flags of --feature-powerset (#58).

@taiki-e taiki-e closed this as completed Jul 20, 2022
@leighmcculloch
Copy link
Author

Ah. I had erroneously believed that default was a special feature and that it didn't actually materialize as a feature in cfgs. Thank you for the detailed explanation.

@leighmcculloch
Copy link
Author

(I think it is probably very hard to implement it properly and it takes time because it is necessary to scan all the codes.)

Agreed. This would likely be a capability fraught with endless edge cases. I think cargo-hack is balancing the complexity to benefit spectrum well as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question
Projects
None yet
Development

No branches or pull requests

2 participants