cargo-matrix
Current Releases
cargo-matrix
CI/CD
cargo-matrix is a Cargo subcommand that runs feature matrices against cargo commands. For each
crate in your workspace it discovers all features, generates every valid combination (the powerset),
and runs the cargo command you give it (e.g. build, check, clippy, test, nextest run,
llvm-cov) against each combination with --no-default-features. Any cargo command that accepts
-p/--package, -F/--features, and --no-default-features works. This ensures your crate
compiles and tests correctly regardless of which subset of features a user enables.
Installation
Usage
cargo matrix runs the cargo command you give it once per feature combination, injecting
-p <package>, --no-default-features, and -F <features> for each one. Any cargo command that
accepts those flags works — there is no fixed list of supported subcommands.
# Check every feature combination across the entire workspace
# Build every combination
# Test every combination
# Multi-token commands work too — just type the full command
# Measure coverage across every combination
# Dry run — print what would be run without executing anything
# Run against a specific package only
# Select a named channel (see Configuration below)
# Point at a workspace that isn't in the current directory
# Split the workspace into chunks for parallel CI jobs (e.g. three jobs, run the second)
The matrix flags (--channel, --dry-run, --manifest-path, --package, --num-chunks,
--chunk) must come before the command. Everything from the command onward is passed to cargo.
Anything after a -- separator is forwarded verbatim to the underlying command, after the injected
matrix flags:
Configuration
Configure each crate via [package.metadata.cargo-matrix] in its Cargo.toml. All fields are
optional — without any configuration cargo-matrix uses the full feature powerset.
Configuration is grouped into named channels, which lets you maintain different filter sets for
different toolchains or purposes (e.g. default, nightly, llvm-cov). Select a channel at
runtime with --channel <name>. When a named channel does not define a field, the value falls back
to the "default" channel.
[]
= "my-crate"
# ...
[]
= []
= []
= ["dep:serde"]
= []
= []
[]
= { = "1", = true }
[]
# ── default channel ────────────────────────────────────────────────────────────
[[]]
= "default"
# Never include these features in any generated combination.
= ["unstable"]
# Always add these features to every combination.
= []
# Drop these exact combinations from the matrix.
= [["foo", "baz"]]
# Feature groups — any combination containing two or more features from the
# same group is excluded. Useful for mutually exclusive backends or runtimes.
= [["foo", "bar"]]
# Override the powerset seed entirely. When set, only these features are
# combined; the package's full feature list is ignored.
# seed = ["foo", "bar"]
# Include features whose names start with "__" (hidden/internal features).
# Defaults to false.
= false
# Automatically include every optional dependency as a feature.
= false
# Include specific optional dependencies as features, independent of
# include_all_optional.
= ["serde"]
# ── nightly channel ────────────────────────────────────────────────────────────
[[]]
= "nightly"
# Override just what differs from the default channel.
= []
= ["unstable"]
= true
Channel field reference
| Field | Type | Description |
|---|---|---|
name |
string |
Channel identifier. "default" is the fallback for all other channels. |
seed |
[string] |
If set, use only these features as the powerset input instead of the package's full feature list. |
always_deny |
[string] |
Features excluded from every generated combination. |
always_include |
[string] |
Features added to every generated combination. |
skip |
[[string]] |
Exact feature sets to drop from the matrix. |
mutually_exclusive |
[[string]] |
Feature groups where at most one member may appear in any combination. |
include_hidden |
bool |
Include __-prefixed features in the powerset. Defaults to false. |
include_all_optional |
bool |
Add every optional dependency as a feature. Defaults to false. |
include_optional |
[string] |
Add specific optional dependencies as features. |
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.