cargo-hack
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.
Installation
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.
Usage
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-featurePerform for each feature which includes
--no-default-featuresand 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.)This is a workaround for an issue that cargo does not support for
--featuresand--no-default-featuresflags for sub crates (rust-lang/cargo#3620, rust-lang/cargo#4106, rust-lang/cargo#4463, rust-lang/cargo#4753, rust-lang/cargo#5015, rust-lang/cargo#5364, rust-lang/cargo#6195). -
--no-dev-depsPerform without dev-dependencies.
This is a workaround for an issue that dev-dependencies leaking into normal build (rust-lang/cargo#4866).
-
--remove-dev-depsEquivalent to
--no-dev-depsexcept for does not restore the originalCargo.tomlafter 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
cargodoes not allow publishing a package with cyclic dev-dependencies. (rust-lang/cargo#4242)# This flag also works without subcommands. # Equivalent to `cargo hack publish --no-dev-deps --dry-run --allow-dirty` -
--ignore-privateSkip to perform on
publish = falsepackages. -
--ignore-unknown-featuresSkip passing
--featurestocargoif that feature does not exist.This is a workaround for an issue that
cargodoes not support for--featureswith workspace (rust-lang/cargo#3620, rust-lang/cargo#4106, rust-lang/cargo#4463, rust-lang/cargo#4753, rust-lang/cargo#5015, rust-lang/cargo#5364, rust-lang/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.
-
--all,--workspacePerform command for all packages in the workspace.
For example, running
cargo hack check --allin a workspace with membersfooandbarbehaves almost the same as the following shell script:members=("foo" "bar") for; do doneNote that there is currently no guarantee in which order workspace members will be performed. (This means that
cargo hack publish --all --ignore-privatedoes not necessarily function as you intended.) -
--features,--no-default-featuresUnlike
cargo(rust-lang/cargo#3620, rust-lang/cargo#4106, rust-lang/cargo#4463, rust-lang/cargo#4753, rust-lang/cargo#5015, rust-lang/cargo#5364, rust-lang/cargo#6195), it can also be applied to sub-crate.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
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.