Skip to content

Commit fc0770b

Browse files
committed
initial implementation of per target config
1 parent 3909e18 commit fc0770b

11 files changed

Lines changed: 1987 additions & 37 deletions

File tree

Cargo.lock

Lines changed: 41 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ color-eyre = "0.6"
7878
cargo_metadata = "0.23"
7979
itertools = "0.14"
8080
regex = "1.11"
81+
cfg-expr = "0.20"
8182

8283
# serde
8384
serde = "1"

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,73 @@ allow_feature_sets = [
144144
# When enabled, never include the empty feature set (no `--features`), even if
145145
# it would otherwise be generated.
146146
no_empty_feature_set = true
147+
148+
# Optional: additional metadata merged into `cargo fc matrix` output
149+
matrix = { kind = "ci" }
150+
```
151+
152+
#### Target-specific configuration
153+
154+
You can override configuration for specific targets using Cargo-style `cfg(...)` expressions.
155+
Overrides are configured under:
156+
157+
```toml
158+
[package.metadata.cargo-feature-combinations.target.'cfg(...)']
159+
```
160+
161+
Example (exclude different features per OS):
162+
163+
```toml
164+
[package.metadata.cargo-feature-combinations]
165+
exclude_features = ["default"]
166+
167+
[package.metadata.cargo-feature-combinations.target.'cfg(target_os = "linux")']
168+
exclude_features = { add = ["metal"] }
169+
170+
[package.metadata.cargo-feature-combinations.target.'cfg(target_os = "macos")']
171+
exclude_features = { add = ["cuda"] }
172+
```
173+
174+
Patch semantics for collection-like keys such as `exclude_features`, `include_features`,
175+
`only_features`, `*_feature_sets`:
176+
177+
- **Array syntax is always an override**
178+
- `exclude_features = ["cuda"]` replaces the entire value.
179+
- This is equivalent to `exclude_features = { override = ["cuda"] }`.
180+
- **Patch object syntax is explicit**
181+
- Override (replace the entire value):
182+
- `exclude_features = { override = ["cuda"] }`
183+
- Add (union with the base value):
184+
- `exclude_features = { add = ["cuda"] }`
185+
- Remove (subtract from the base value):
186+
- `exclude_features = { remove = ["cuda"] }`
187+
188+
When multiple target override sections match (e.g. `cfg(unix)` and `cfg(target_os = "linux")`),
189+
they are merged deterministically. Conflicting `override` values result in an error.
190+
191+
##### `replace = true`
192+
193+
If a matching target override sets `replace = true`, resolution starts from a fresh default
194+
configuration (instead of inheriting from the base config). To avoid confusion, when
195+
`replace = true` is set, patchable fields must not use `add` or `remove` (only override
196+
is allowed).
197+
198+
Example (using array shorthand, i.e. override):
199+
200+
```toml
201+
[package.metadata.cargo-feature-combinations]
202+
exclude_features = ["default"]
203+
isolated_feature_sets = [
204+
["gpu"],
205+
["ui"],
206+
]
207+
skip_optional_dependencies = true
208+
209+
[package.metadata.cargo-feature-combinations.target.'cfg(target_os = "linux")']
210+
replace = true
211+
# Start from a fresh default config on Linux: `isolated_feature_sets` and
212+
# `skip_optional_dependencies` are not inherited from the base config.
213+
exclude_features = ["default", "cuda"]
147214
```
148215

149216
<details>

0 commit comments

Comments
 (0)