Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Cargo subcommand to provide various options useful for testing and continuous integration.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

taiki-e/cargo-hack

crates.iolicensegithub actions

Cargo subcommand to provide various options useful for testing and continuousintegration.

Usage

Complete list of options (click to show)
$cargo hack --helpcargo-hackCargo subcommand to provide various options useful for testing and continuous integration.USAGE:    cargo hack [OPTIONS] [SUBCOMMAND]Use -h for short descriptions and --help for more details.OPTIONS:    -p, --package <SPEC>...            Package(s) to check.        --all            Alias for --workspace.        --workspace            Perform command for all packages in the workspace.        --exclude <SPEC>...            Exclude packages from the check.        --manifest-path <PATH>            Path to Cargo.toml.        --locked            Require Cargo.lock is up to date.    -F, --features <FEATURES>...            Space or comma separated list of features to activate.        --each-feature            Perform for each feature of the package.            This also includes runs with just --no-default-features flag, and default features.            When this flag is not used together with --exclude-features (--skip) and            --include-features and there are multiple features, this also includes runs with just            --all-features flag.        --feature-powerset            Perform for the feature powerset of the package.            This also includes runs with just --no-default-features flag, and default features.            When this flag is used together with --depth or namespaced features (-Z            namespaced-features) and not used together with --exclude-features (--skip) and            --include-features and there are multiple features, this also includes runs with just            --all-features flag.        --optional-deps [DEPS]...            Use optional dependencies as features.            If DEPS are not specified, all optional dependencies are considered as features.            This flag can only be used together with either --each-feature flag or            --feature-powerset flag.        --skip <FEATURES>...            Alias for --exclude-features.        --exclude-features <FEATURES>...            Space or comma separated list of features to exclude.            To exclude run of default feature, using value `--exclude-features default`.            To exclude run of just --no-default-features flag, using --exclude-no-default-features            flag.            To exclude run of just --all-features flag, using --exclude-all-features flag.            This flag can only be used together with either --each-feature flag or            --feature-powerset flag.        --exclude-no-default-features            Exclude run of just --no-default-features flag.            This flag can only be used together with either --each-feature flag or            --feature-powerset flag.        --exclude-all-features            Exclude run of just --all-features flag.            This flag can only be used together with either --each-feature flag or            --feature-powerset flag.        --depth <NUM>            Specify a max number of simultaneous feature flags of --feature-powerset.            If NUM is set to 1, --feature-powerset is equivalent to --each-feature.            This flag can only be used together with --feature-powerset flag.        --group-features <FEATURES>...            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`            This flag can only be used together with --feature-powerset flag.        --target <TRIPLE>            Build for specified target triple.            Comma-separated lists of targets are not supported, but you can specify the whole            --target option multiple times to do multiple targets.            This is actually not a cargo-hack option, it is interpreted by Cargo itself.        --mutually-exclusive-features <FEATURES>...            Space or comma separated list of features to not use together.            To specify multiple groups, use this option multiple times:            `--mutually-exclusive-features a,b --mutually-exclusive-features c,d`            This flag can only be used together with --feature-powerset flag.        --at-least-one-of <FEATURES>...            Space or comma separated list of features. Skips sets of features that don't enable any            of the features listed.            To specify multiple groups, use this option multiple times: `--at-least-one-of a,b            --at-least-one-of c,d`            This flag can only be used together with --feature-powerset flag.        --include-features <FEATURES>...            Include only the specified features in the feature combinations instead of package            features.            This flag can only be used together with either --each-feature flag or            --feature-powerset flag.        --no-dev-deps            Perform without dev-dependencies.            Note that this flag removes dev-dependencies from real `Cargo.toml` while cargo-hack is            running and restores it when finished.        --remove-dev-deps            Equivalent to --no-dev-deps flag except for does not restore the original `Cargo.toml`            after performed.        --no-private            Perform without `publish = false` crates.        --ignore-private            Skip to perform on `publish = false` packages.        --ignore-unknown-features            Skip passing --features flag to `cargo` if that feature does not exist in the package.            This flag can be used with --features, --include-features, or --group-features.        --rust-version            Perform commands on `package.rust-version`.            This cannot be used with --version-range.        --version-range [START]..[=END]            Perform commands on a specified (inclusive) range of Rust versions.            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.            Note that ranges are always inclusive ranges.        --version-step <NUM>            Specify the version interval of --version-range (default to `1`).            This flag can only be used together with --version-range flag.        --clean-per-run            Remove artifacts for that package before running the command.            If used this flag with --workspace, --each-feature, or --feature-powerset, artifacts            will be removed before each run.            Note that dependencies artifacts will be preserved.        --clean-per-version            Remove artifacts per Rust version.            Note that dependencies artifacts will also be removed.            This flag can only be used together with --version-range flag.        --keep-going            Keep going on failure.        --partition <M/N>            Partition runs and execute only its subset according to M/N.        --log-group <KIND>            Log grouping: none, github-actions.            If this option is not used, the environment will be automatically detected.        --print-command-list            Print commands without run (Unstable).        --no-manifest-path            Do not pass --manifest-path option to cargo (Unstable).    -v, --verbose            Use verbose output.        --color <WHEN>            Coloring: auto, always, never.            This flag will be propagated to cargo.    -h, --help            Prints help information.    -V, --version            Prints version information.Some common cargo commands are (see all commands with --list):    build       Compile the current package    check       Analyze the current package and report errors, but don't build object files    run         Run a binary or example of the local package    test        Run the tests

cargo-hack is basically wrapper ofcargo that propagates subcommand and mostof the passed flags tocargo, but provides additional flags and changes thebehavior of some existing flags.

--each-feature

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 forthis purpose, it is recommended to use with--no-dev-deps to avoidcargo#4866.)

cargo hack check --each-feature --no-dev-deps

See alsoOptions for adjusting the behavior of --each-feature and --feature-powerset section.

--feature-powerset

Perform for the feature powerset which includes--no-default-features anddefault features of the package.

This is useful to check that every combination of features is workingproperly. (When used for this purpose, it is recommended to use with--no-dev-deps to avoidcargo#4866.)

cargo hack check --feature-powerset --no-dev-deps

cargo-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--depth option.

See alsoOptions for adjusting the behavior of --each-feature and --feature-powerset section.

Options for adjusting the behavior of --each-feature and --feature-powerset

The following flags can be used with--each-feature and--feature-powerset.

--optional-deps

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,deps2

--exclude-features, --skip

Space or comma separated list of features to exclude.

cargo hack check --feature-powerset --exclude-features feature1,feature2cargo hack check --feature-powerset --skip feature1,feature2

--depth

Specify a max number of simultaneous feature flags of--feature-powerset.

If the number is set to 1,--feature-powerset is equivalent to--each-feature.

--group-features

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

--rust-version

Perform commands on the Rust version ofpackage.rust-version field inCargo.toml

--version-range

Perform commands on a specified (inclusive) range of Rust versions.

$cargo hack check --version-range 1.46..=1.47info: 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 userustup run <toolchain> cargo instead ofcargo +<toolchain> to work around arustup bug.)

This might be useful for catching issues liketermcolor#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 therust-version field inCargo.toml is used as the lower bound.

You can specify the version interval by using--version-step.

--no-dev-deps

Perform without dev-dependencies.

This is a workaround for an issue that dev-dependencies leaking into normalbuild (cargo#4866).

Also, this can be used as a workaround for an issue thatcargo does notallow publishing a package with cyclic dev-dependencies. (cargo#4242)

cargo hack publish --no-dev-deps --dry-run --allow-dirty

Note

Currently, using--no-dev-deps flag removes dev-dependencies fromreal manifest while cargo-hack is running and restores it when finished.Any changes you made to those files during running will not be preserved.Seecargo#4242 for why this is necessary.Also, this behavior may change in the future on some subcommands. See also#15.

--remove-dev-deps

Equivalent to--no-dev-deps except for does not restore the originalCargo.toml after execution.

This is useful to know what Cargo.toml that cargo-hack is actually usingwith--no-dev-deps.

This flag also works without subcommands.

--ignore-private

Skip to perform onpublish = false crates.

--no-private

Perform withoutpublish = 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-private flag modifiesCargo.toml while cargo-hack is running and restores it when finished. Any changes you made to those files during running will not be preserved.

--ignore-unknown-features

Skip passing--features tocargo if that feature does not exist.

--clean-per-run

Remove artifacts for that package before running the command.

This also works as a workaround forrust-clippy#4612.

Improvement of the behavior of existing cargo flags

cargo-hack changes the behavior of the following existing flags.

--features, --no-default-features

Unlikecargo (cargo#3620,cargo#4106,cargo#4463,cargo#4753,cargo#5015,cargo#5364,cargo#6195), it can also be applied tosub-crates.

--all, --workspace

Perform command for all packages in the workspace.

Unlike cargo, it does not compile all members at once.

For example, runningcargo hack check --all in a workspace with membersfoo andbar 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")formemberin"${members[@]}";do    cargo check --manifest-path"${member}/Cargo.toml"done

Workspace members will be performed according to the order of the 'packages'fields ofcargo metadata.

Installation

From source

cargo +stable install cargo-hack --locked

Currently, installing cargo-hack requires rustc 1.70+.

cargo-hack is usually runnable with Cargo versions older than the Rust versionrequired for installation (e.g.,cargo +1.31 hack check). Currently, to runcargo-hack requires Cargo 1.26+.

From prebuilt binaries

You can download prebuilt binaries from theRelease page.Prebuilt binaries are available for macOS, Linux (gnu and musl), Windows (static executable), FreeBSD, and illumos.

Example of script to install from the Release page (click to show)
# Get host targethost=$(rustc -vV| grep'^host:'| cut -d'' -f2)# Download binary and install to $HOME/.cargo/bincurl --proto'=https' --tlsv1.2 -fsSL"https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-$host.tar.gz" \| tar xzf - -C"$HOME/.cargo/bin"

On GitHub Actions

You can usetaiki-e/install-action to install prebuilt binaries on Linux, macOS, and Windows.This makes the installation faster and may avoid the impact ofproblems caused by upstream changes.

-uses:taiki-e/install-action@cargo-hack

Via Homebrew

You can install cargo-hack fromhomebrew-core (x86_64/AArch64 macOS, x86_64 Linux):

brew install cargo-hack

Alternatively, you can also install from theHomebrew tap maintained by us (x86_64/AArch64 macOS, x86_64/AArch64 Linux):

brew install taiki-e/tap/cargo-hack

Via Scoop (Windows)

You can install cargo-hack from theScoop bucket maintained by us:

scoop bucket add taiki-e https://github.com/taiki-e/scoop-bucketscoop install cargo-hack

Via cargo-binstall

You can install cargo-hack usingcargo-binstall:

cargo binstall cargo-hack

Via pacman (Arch Linux)

You can install cargo-hack from theextra repository:

pacman -S cargo-hack

Via ports (FreeBSD)

You can install cargo-hack from theofficial ports:

pkg install cargo-hack

Via other package managers

Packaging status

Related Projects

License

Licensed under either ofApache License, Version 2.0 orMIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.

About

Cargo subcommand to provide various options useful for testing and continuous integration.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp