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

Allows specifying which features to build, test and lint #151

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

xfbs
Copy link

@xfbs xfbs commented Dec 20, 2023

Rust has the ability to specify optional features (think #ifdef in C/C++), as well as default features. When running any of the tooling without additional options (cargo test, cargo build, cargo clippy), only the default features are activated, which means that the code that is behind the other features goes untested, unlinted and unbuilt.

In an ideal world, we would thus run unit tests for every possible subset of the set of possible features. This is possible with cargo hack, although it leads to long CI times and is thus undesireable.

A good tradeoff is this:

  • Test and lint with --all-features
  • Use cargo hack to just check all possible features to make sure they at least are compileable

This workflow catches the vast majority of issues related to working with feature-gated code. However, this workflow is currently not easily possible because we do not enable --all-features on our cargo_test and cargo_clippy tasks.

What this PR does is add some handles that allow us to enable --all-features (or specific features) on our test and clippy
tasks.

Specifically, this gives us some fine control over which features are enabled:

# default features
cargo_clippy(features = CargoBuildFeatures())

# no default features, but activate a and b
cargo_clippy(features = CargoBuildFeatures(features = ["a", "b"], default = False))

# enable all features
cargo_clippy(features = CargoBuildFeatures(all = True))

The idea is that at some point (after perhaps discussing it), we could change autoconf() to setting the features to CargoBuildFeatures(all = True) for the test and clippy tasks by default, to make sure that we really do run all tests in CI, and not just the ones for the features that happen to be enabled by default.

@xfbs xfbs force-pushed the pe/cargo-features branch from eefbcf5 to 1cae8c6 Compare December 20, 2023 13:45
@xfbs xfbs force-pushed the pe/cargo-features branch from 1cae8c6 to ec34bb9 Compare December 20, 2023 14:37
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