Cargo features allow conditional compilation, so the final build will have just specific groups of features which can be filtered by the final user.
Now depending on the complexity of a library crate, you may end with several features forming a dependency tree, something like:
[features]
banana = []
avocado = []
pineapple = ["avocado"]
orange = ["pineapple", "banana"]
It's natural that, beyond cargo check|test --all-features
, I will want to run cargo check|test --features banana
on each one of the individual features, to ensure they can live on their own. Currently I'm doing this with a crude shell script, manually fed with the features. If I add a new feature and I forget to add it to the script, I'm in trouble.
FEATS=(banana avocado pineapple orange)
for FEAT in "${FEATS[@]}" ; do
echo "$FEAT..."
cargo check --features "$FEAT"
#cargo test --features "$FEAT"
done
So, is there any automated way to run cargo check|test --features banana
on each feature, one by one, then report the warnings/errors which have been found?
cargo
. I guess you'd a script that parses yourCargo.toml
and collects all the features automatically. I bet you can whip that up in Python in a couple of lines. – Maladapted