![crates-badge] ![license-badge] ![rustc-badge]
A tool to work around some limitations on cargo.
Cargo is a great tool but has some limitations. This tool provides additional flags to avoid some of these limitations.
sh
cargo install cargo-hack
To install the current cargo-hack requires Rust 1.36 or later.
Note: cargo-hack is currently only tested on Linux and macOS. It may not work well on other platforms. See [#3] for Windows support.
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.
--each-feature
Perform for each feature which includes --no-default-features
and 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
.)
sh
cargo hack check --each-feature --no-dev-deps
This is a workaround for an issue that cargo does not support for --features
and --no-default-features
flags for sub crates ([cargo#3620], [cargo#4106], [cargo#4463], [cargo#4753], [cargo#5015], [cargo#5364], [cargo#6195]).
--no-dev-deps
Perform without dev-dependencies.
This is a workaround for an issue that dev-dependencies leaking into normal build ([cargo#4866]).
--remove-dev-deps
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
.
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])
```sh
cargo hack --remove-dev-deps cargo publish --dry-run --allow-dirty
cargo hack publish --no-dev-deps --dry-run --allow-dirty
```
--ignore-private
Skip to perform on publish = false
packages.
--ignore-unknown-features
Skip passing --features
to cargo
if that feature does not exist.
This is a workaround for an issue that cargo
does not support for --features
with workspace ([cargo#3620], [cargo#4106], [cargo#4463], [cargo#4753], [cargo#5015], [cargo#5364], [cargo#6195]).
This feature was formerly called --ignore-non-exist-features
, but has been renamed. The old name can be used as an alias, but is deprecated.
cargo-hack
changes the behavior of the following existing flags.
--features
, --no-default-features
Unlike cargo
([cargo#3620], [cargo#4106], [cargo#4463], [cargo#4753], [cargo#5015], [cargo#5364], [cargo#6195]), it can also be applied to sub-crate.
--all
, --workspace
Perform command for all packages in the workspace.
For example, running cargo hack check --all
in a workspace with members foo
and bar
behaves almost the same as the following script:
```sh
members=("foo" "bar")
for member in ${members[@]}; do cargo check --manifest-path "${member}" done ```
Note that there is currently no guarantee in which order workspace members will be performed. (This means that cargo hack publish --all --ignore-private
does not necessarily function as you intended.)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.