Important
Versions prior to v3.2 will stop working on February 1st, 2025, due to
GitHub changing their cache service APIs. See the @actions/cache
package deprecation notice.
A GitHub Action that runs cargo install and automatically caches the resulting binaries to speed up subsequent builds.
- Install any Rust binary crate from crates.io, git repositories or custom registries
- Automatically cache binaries to avoid repeated compilations
- Version range support to keep crates updated
- Works on Linux, Windows and MacOS runners
The following example steps install the cargo-hack and cargo-sort
crates. Read Quickstart for GitHub Actions to learn more about Actions usage.
- name: Install cargo-hack from crates.io
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-hack
version: '^0.5' # optional semver range (defaults to latest)
- name: Install cargo-sort from git
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-sort
git: https://github.com/devinr528/cargo-sort
tag: v1.0.9 # `branch` and `commit` are also supported
- name: Run cargo hack
run: cargo hack --versionIf no version or branch/tag/commit is specified, the latest version will be
installed. The --locked flag is added by default to avoid breakages due to
unexpected dependencies updates.
crate(required): Name of the crate to installversion: Version to install, supports semver range (default: latest)features: Space or comma-separated list of crate features to enablelocked: Adds--lockedflag to (default: true)args: Extra arguments forcargo installcache-key: Custom string added to the cache key to force-invalidate the cache
When installing from a git repository, the version parameter is ignored.
git: URL of the git repositorybranch: git branch to install fromtag: git tag to install fromcommit/rev: commit hash to install from
branch, tag and commit/rev are mutually exclusive. If none of them are
specified, the latest commit of the default branch will be used.
Version range resolution is only supported when using a sparse registry index with the index parameter. Otherwise, only exact versions can be used.
index: Registry index URLregistry: Registry name from the Cargo configuration (see Using an alternate registry on the Cargo Book)
registry and index are mutually exclusive.
version: Installed crate version (or commit hash for git installations)cache-hit: Boolean indicating whether the crate was restored from cache
Compiled binaries are cached in ~/.cargo-install/<crate-name>. The cache key contains a hash derived from the installation context (command arguments and os version).
Cache entries expire after 7 days of inactivity. For more details, see GitHub's caching documentation.
Installation is done using the cargo binary installed in the runner.
When installing from crates.io or a custom sparse registry, the action resolves the latest version prior to installation. It is recommended to pin exact versions for sensitive workflows.
If using a git repository, the action uses git ls-remote to resolve the
commit hash. The repository is cloned by cargo install.
There is no particular contribution guidelines, feel free to open a new PR to improve the code. If you want to introduce a new feature, please create an issue before.