#cargo #subcommand

app cargo-hack

A tool to work around some limitations on cargo

14 releases

✓ Uses Rust 2018 edition

new 0.3.9 May 25, 2020
0.3.5 Apr 24, 2020
0.3.3 Jan 6, 2020
0.3.2 Dec 9, 2019
0.3.1 Nov 20, 2019

#7 in Cargo plugins

Download history 646/week @ 2020-01-25 375/week @ 2020-02-01 293/week @ 2020-02-08 344/week @ 2020-02-15 712/week @ 2020-02-22 663/week @ 2020-02-29 195/week @ 2020-03-07 408/week @ 2020-03-14 605/week @ 2020-03-21 564/week @ 2020-03-28 407/week @ 2020-04-04 504/week @ 2020-04-11 1014/week @ 2020-04-18 786/week @ 2020-04-25 1107/week @ 2020-05-02 1121/week @ 2020-05-09

3,011 downloads per month

Apache-2.0 OR MIT

64KB
1.5K SLoC

cargo-hack

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.

Installation

$ cargo install cargo-hack

To install the current cargo-hack requires Rust 1.36 or later.

Usage

See cargo hack --help for a complete list of options.

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 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 rust-lang/cargo#4866.)

    $ 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 (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).

  • --feature-powerset

    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 rust-lang/cargo#4866.)

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

    Perform without dev-dependencies.

    This is a workaround for an issue that dev-dependencies leaking into normal build (rust-lang/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. (rust-lang/cargo#4242)

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

    Currently, using --no-dev-deps flag removes dev-dependencies from real manifest while cargo-hack is running and restores it when finished. See rust-lang/cargo#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 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.

  • --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 (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.

  • --features, --no-default-features

    Unlike 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-crates.

  • --all, --workspace

    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"
    done
    

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

License

Licensed under either of

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.

Dependencies

~1.2–2MB
~43K SLoC