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

Add --must-have-and-exclude-feature option. #262

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xStrom
Copy link
Contributor

@xStrom xStrom commented Dec 10, 2024

Summary

This new option allows for more precise testing of packages that support no_std.

The goal

I want to be able to properly test all packages that support no_std. The problem is tricky because I would like the command to be copy-pastable across 20 repositories and there's quite a bit of variation.

Old solution

cargo hack clippy
    --workspace
    --locked
    --target x86_64-unknown-none
    --optional-deps
    --each-feature
    --ignore-unknown-features
    --features libm
    --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }}

This kind of works, but has problems:

  • It requires a per-workspace configuration variable to track features which depend on std.
  • As packages grow in size, so do the odds that different packages in a workspace have an identically named feature, but only one of those actually requires std.
  • The workspace can't easily have members which can't be compiled without std due to the use of --target x86_64-unknown-none. It is possible to overcome this, but it requires yet another per-workspace package exclusion configuration variable.

New solution in this PR

--must-have-and-exclude-feature <FEATURE>

  Require the specified feature to be present but excluded.

  Exclude the specified feature and all other features which depend on it.
  Exclude packages which don't have the specified feature.

  This is useful for doing no_std testing with --must-have-and-exclude-feature std.

With this new option, there is no longer a need for any configuration variables and the following command is universal:

cargo hack clippy
    --workspace
    --locked
    --target x86_64-unknown-none
    --optional-deps
    --each-feature
    --ignore-unknown-features
    --features libm
    --must-have-and-exclude-feature std

Now cargo-hack will make sure to only select packages which actually have a feature called std and it will also make sure to not enable any feature which would indirectly require std.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant