Optional dependencies#
Scenario: a store crate has two optional storage backends and one real compression feature. Cargo turns each optional dependency into an implicit feature (redis-backend, sled-backend), which would multiply the matrix — but you only want to vary compression.
[package]
name = "store"
version = "0.1.0"
edition = "2024"
[features]
compression = []
[dependencies]
redis-backend = { path = "../redis-backend", optional = true }
sled-backend = { path = "../sled-backend", optional = true }
[package.metadata.cargo-fc]
# Don't vary the implicit features of the optional backends.
skip_optional_dependencies = trueWith skip_optional_dependencies = true, the implicit redis-backend and sled-backend features are removed from the matrix; only the real compression feature is varied. Checking just the store package shows two combinations:
$ cargo fc -p store --summary-only check Checking [1/2] store ( features = [] ) Checking [2/2] store ( features = [compression] ) Finished 2 feature combinations for 1 package in 0.00s PASS store ( 0 errors, 0 warnings, features = [] ) PASS store ( 0 errors, 0 warnings, features = [compression] )
Without the flag, the same crate would vary all three features (redis-backend, sled-backend, compression) — 2³ = 8 combinations. (This applies to optional crates.io dependencies too, not just local path crates.)
Still testing a few dependency combinations#
If you do want specific combinations that include an optional dependency, pin them explicitly — they’re added back regardless of skip_optional_dependencies:
[package.metadata.cargo-fc]
skip_optional_dependencies = true
include_feature_sets = [
["compression", "redis-backend"],
]