Cargo subcommand to provide various options useful for testing and continuous integration.
Cargo subcommand to provide various options useful for testing and continuous integration.
Cargo subcommand to provide various options useful for testing and continuous integration.
Complete list of options (click to show)
…cargo-hack is basically wrapper of cargo that propagates subcommand and most
of the passed flags to cargo, but provides additional flags and changes the
behavior of some existing flags.
Perform for each feature which includes default features and
--no-default-features of the package.
This is useful to check that each feature is working properly. (When used for
this purpose, it is recommended to use with --no-dev-deps to avoid
cargo#4866.)
cargo hack check --each-feature --no-dev-depsSee also Options for adjusting the behavior of --each-feature and --feature-powerset section.
Perform for the feature powerset which includes --no-default-features and
default features of the package.
This is useful to check that every combination of features is working
properly. (When used for this purpose, it is recommended to use with
--no-dev-deps to avoid cargo#4866.)
cargo hack check --feature-powerset --no-dev-depscargo-hack deduplicate any fully equivalent feature combinations based on how the cargo features work. Therefore, it may be more efficient than checking all feature combinations in other ways.
[!TIP] When using this flag results in a very large number of feature combinations, consider using
--depthoption.
See also Options for adjusting the behavior of --each-feature and --feature-powerset section.
The following flags can be used with --each-feature and --feature-powerset.
Use optional dependencies as features.
This flag treats all option dependencies as features by default. To treat only specific dependencies as features, pass a space or comma separated list.
cargo hack check --feature-powerset --optional-deps deps1,deps2Space or comma separated list of features to exclude.
cargo hack check --feature-powerset --exclude-features feature1,feature2
cargo hack check --feature-powerset --skip feature1,feature2Specify a max number of simultaneous feature flags of --feature-powerset.
If the number is set to 1, --feature-powerset is equivalent to
--each-feature.
Space or comma separated list of features to group.
This treats the specified features as if it were a single feature.
To specify multiple groups, use this option multiple times:
--group-features a,b --group-features c,d
Perform commands on the Rust version of package.rust-version field in Cargo.toml
Perform commands on a specified (inclusive) range of Rust versions.
$ cargo hack check --version-range 1.46..=1.47
info: running `rustup run 1.46 cargo check` on cargo-hack (1/2)
...
info: running `rustup run 1.47 cargo check` on cargo-hack (2/2)
...(We use rustup run cargo instead of cargo + to work around a rustup bug.)
This might be useful for catching issues like [termcolor#35], regex#685, [rust-clippy#6324].
If the upper bound of the range is omitted, the latest stable compiler is used as the upper bound.
If the lower bound of the range is omitted, the value of the rust-version field in Cargo.toml is used as the lower bound.
You can specify the version interval by using --version-step.
Perform without dev-dependencies.
This is a workaround for an issue that dev-dependencies leaking into normal build (cargo#4866).
Also, this can be used as a workaround for an issue that cargo does not
allow publishing a package with cyclic dev-dependencies. (cargo#4242)
cargo hack publish --no-dev-deps --dry-run --allow-dirty[!NOTE] Currently, using
--no-dev-depsflag removes dev-dependencies from real manifest while cargo-hack is running and restores it when finished. Any changes you made to those files during running will not be preserved. See cargo#4242 for why this is necessary. Also, this behavior may change in the future on some subcommands. See also #15.
Equivalent to --no-dev-deps except for does not restore the original
Cargo.toml after execution.
This is useful to know what Cargo.toml that cargo-hack is actually using
with --no-dev-deps.
This flag also works without subcommands.
Skip to perform on publish = false crates.
Perform without publish = false crates. This is similar to --ignore-private, but is more powerful because this also prevents private crates from affecting lockfile and metadata.
[!NOTE]
--no-privateflag modifiesCargo.tomlwhile cargo-hack is running and restores it when finished. Any changes you made to those files during running will not be preserved.
Skip passing --features to cargo if that feature does not exist.
Remove artifacts for that package before running the command.
This also works as a workaround for rust-clippy#4612.
cargo-hack changes the behavior of the following existing flags.
Unlike cargo (cargo#3620, cargo#4106, cargo#4463, cargo#4753,
cargo#5015, cargo#5364, cargo#6195), it can also be applied to
sub-crates.
Perform command for all packages in the workspace.
Unlike cargo, it does not compile all members at once.
For example, running cargo hack check --all in a workspace with members
foo and bar behaves almost the same as the following script:
# If you use cargo-hack, you don't need to maintain this list manually.
members=("foo" "bar")
for member in "${members[@]}"; do
cargo check --manifest-path "${member}/Cargo.toml"
doneWorkspace members will be performed according to the order of the 'packages'
fields of cargo metadata.
cargo +stable install cargo-hack --lockedCurrently, installing cargo-hack requires rustc 1.85+.
cargo-hack is usually runnable with Cargo versions older than the Rust version
required for installation (e.g., cargo +1.31 hack check). Currently, to run
cargo-hack requires Cargo 1.26+.
You can download prebuilt binaries from the Release page. Prebuilt binaries are available for Linux (x86_64 gnu/musl, aarch64 gnu/musl, powerpc64le gnu/musl, riscv64gc gnu/musl, and s390x gnu, musl binaries are static executable), macOS (x86_64, aarch64, and universal), Windows (x86_64 and aarch64, static executable), FreeBSD (x86_64), and illumos (x86_64). All releases are immutable and releases since 0.6.44 publish artifact attestations.
Example of script to install from the Release page with verifications (click to show)
…gh release -R .. verify-asset should output messages like the following (//`` contains the actual SHA-256 digest of the downloaded file / the actual SHA-1 digest of tag / the actual version number):
Calculated digest for cargo-hack.tar.gz: sha256:
Resolved tag v to sha1:
Loaded attestation from GitHub API
✓ Verification succeeded! cargo-hack.tar.gz is present in release vgh attestation verify should output messages like the following (`` contains the actual SHA-256 digest of the downloaded file):
…Example of script to install from the Release page without verification (click to show)
# Get host target.
host=$(rustc -vV | grep '^host:' | cut -d' ' -f2)
# Download binary and install to $CARGO_HOME/bin (or $HOME/.cargo/bin if CARGO_HOME is unset).
curl --proto '=https' --tlsv1.2 -fsSL "https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-$host.tar.gz" \
| tar xzf - -C "${CARGO_HOME:-"$HOME/.cargo"}"/binYou can use taiki-e/install-action to install prebuilt binaries on Linux, macOS, and Windows. This makes the installation faster and may avoid the impact of problems caused by upstream changes.
- uses: taiki-e/install-action@cargo-hackYou can install cargo-hack from homebrew-core (x86_64/AArch64 macOS, x86_64/AArch64 Linux):
brew install cargo-hackAlternatively, you can also install from the Homebrew tap maintained by us (x86_64/AArch64 macOS, x86_64/AArch64 Linux):
brew install taiki-e/tap/cargo-hackYou can install cargo-hack from the Scoop bucket maintained by us:
scoop bucket add taiki-e https://github.com/taiki-e/scoop-bucket
scoop install cargo-hackYou can install cargo-hack using cargo-binstall:
cargo binstall cargo-hackYou can install cargo-hack from the extra repository:
pacman -S cargo-hackYou can install cargo-hack from the official ports:
pkg install cargo-hack-Z minimal-versions.No open issues yet, or sync has not completed.