#cargo #github-actions #crates-io #search #cache #version #optimized

bin+lib cargo-search2

cargo search, optimized for CI caching in GitHub Actions and elsewhere

5 unstable releases

0.2.2 Oct 11, 2021
0.2.1 Oct 10, 2021
0.1.1 Oct 4, 2021
0.0.5 Oct 4, 2021

#576 in Cargo plugins


170 lines


cargo-search2 on crates.io Documentation (latest release) Documentation (main) License License

A binary utility that provides a more convenient version of cargo search.


Grab pre-built binaries for your platform from the releases page.

To grab releases in CI or other automation:

curl -LsSf https://github.com/sunshowers/cargo-search2/releases/latest/download/cargo-search2-{platform}.zip | tar xzf - -C ~/.cargo/bin

Install manually:

cargo install cargo-search2


$ cargo search2 serde
# output:
serde 1.0.130 (hash: blake2b24:2e6117acae4f6f2d2d698c9fc0b43de60ac26556f44ad96b)

$ cargo search2 serde --message-format toml
serde = "1.0.130"

$ cargo search2 serde --message-format json

# Get an exact version or semver range
$ cargo search2 serde --req '=1.0.120'
serde 1.0.120 (hash: blake2b24:f79131f50c298569f841e47287c3b0a443c29cfda3ffd475)

# Use --cache-version/-c to invalidate caches
$ cargo run -- serde --req '=1.0.120' -c1
serde 1.0.120 (hash: blake2b24:168778241e3b0e96f5547fba1eb4b4b84efa8291c3c14b37)
$ cargo run -- serde --req '=1.0.120' -c2
serde 1.0.120 (hash: blake2b24:344d8a8d08a16dbce8c4e0d90fd6aad513631ca081185ea8)

# Step outputs for GitHub Actions
$ cargo search2 serde --message-format github
::set-output name=crate-name::serde
::set-output name=version::1.0.120
::set-output name=hash::blake2b24:f79131f50c298569f841e47287c3b0a443c29cfda3ffd475

For an example GitHub Action, see .github/workflows/example.yml.


People sometimes use cargo search to generate cache keys for tools. This is an easier way to achieve the same goal with a couple more features.

cargo search2 supports:

  • looking for exact versions and semver ranges
  • producing results in plain, JSON, and GitHub Actions formats
  • easy cache invalidation through the --cache-version option

Hash contents

The hashes produced by cargo search2 are derived from:

  • The name of the crate
  • The exact version number
  • The cache version

Notably, the operating system and other parts of the environment are not part of the hash.

Stability guarantees

Within a semver range, the command-line interface is append-only, and hashes stay the same.


Pull requests are welcome! Please follow the code of conduct.


This project is available under the terms of either the Apache 2.0 license or the MIT license.


~463K SLoC