Setup a Rust environment with the right toolchain and build caching. 🧰
- name: Set up Rust
uses: Systemcluster/actions@setup-rust-v0
with:
channel: stable
components: rustfmt,clippy
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
binaries:
- cargo-nextest
- cargo-insta
sccache: true
- Installs Rust detecting the desired toolchain by reading the
RUSTUP_TOOLCHAIN
environment variable,rust-toolchain.toml
andrust-toolchain
files, or by manual specification - Caches the Cargo registry and build artifacts to speed up build and dependency installation
- Installs sccache and sets up GitHub Actions integration
- Adds problem matchers for
rustc
,rustfmt
and runtime panics
Name | Type | Description | Default | Required |
---|---|---|---|---|
channel |
String | Version of Rust to install. Can be a channel like stable , beta , nightly , or a specific version like 1.54.0 or nightly-2021-08-01 . |
Read from the RUSTUP_TOOLCHAIN environment variable, rust-toolchain or rust-toolchain.toml file, and falling back to stable . |
✗ |
components |
String[] | List of components to install. Can be a list of component names like rustfmt , clippy , or rust-src . |
Read from the rust-toolchain.toml file. |
✗ |
targets |
String[] | List of targets to install. Can be a list of target names like wasm32-unknown-unknown , x86_64-unknown-linux-gnu , or x86_64-apple-darwin . |
Read from the rust-toolchain.toml file. |
✗ |
profile |
String | Profile to install. Can be minimal , default , or complete . |
Read from the rust-toolchain.toml file and falling back to minimal . |
✗ |
binaries |
String[] | List of binaries to install. Can be a list of binary names like cargo-nextest or specific versions like cargo-insta@1.32.0 . |
✗ | |
directory |
String | Directory containing the Rust project. Used for detecting Rust version and configuration and for caching build artifacts. | . |
✗ |
sccache |
Boolean | Whether to set up sccache with GitHub Actions integration. |
true |
✗ |
cache |
Boolean | Whether to cache and restore the Cargo registry and the build artifacts in the target directory. | true |
✗ |
cache-profile |
String | The build profile to cache. Can be debug , release , or any custom profile. If not specified, all profiles are cached. Requires cache to be true . |
✗ | |
cache-sweep |
Boolean | Whether to run cargo sweep before saving the cache. Requires cache to be true . |
false |
✗ |
cache-key-job |
Boolean | Whether to consider the Job ID when generating the cache key. Set to true to prevent sharing the cache across jobs. Requires cache to be true . |
false |
✗ |
cache-key-env |
String[] | List of environment variables to consider when generating the cache key. Requires cache to be true . |
✗ |
Name | Type | Description |
---|---|---|
rust-version |
String | Version of Rust that was installed. |
rust-version-hash |
String | Commit hash of the Rust version that was installed. |
cache-hit |
Boolean | Whether the Cargo registry and build artifact cache was restored. |
The desired Rust toolchain channel is detected in the following order:
- Using the
channel
input if specified - Read from the
RUSTUP_TOOLCHAIN
environment variable if present - Read from a
rust-toolchain.toml
if present indirectory
- Read from a
rust-toolchain
file if present indirectory
- Falling back to
stable
The chosen toolchain is installed with rustup
and set as the default toolchain.
The desired toolchain components, targets, and profile are detected in the following order:
- Using the
components
,targets
, andprofile
inputs if specified - Read from the
rust-toolchain.toml
file if present indirectory
- Falling back to the
minimal
profile and no components or targets
Both targets
and components
can alternatively be specified as a single string with values separated by ,
or ;
, for example x86_64-unknown-linux-gnu;wasm32-unknown-unknown
or rustfmt,clippy
.
If targets
and components
are specified in multiple places, the lists are merged.
Binaries are installed with cargo-binstall
. cargo-cache
and cargo-sweep
are installed by default when cache
is true
.
If binaries
is empty and both cache
and sccache
are false
, the installation of cargo-binstall
is skipped.
When the cache
input is true
, the Cargo store and build artifacts are cached and restored using actions/cache.
The cache key is generated based on the following inputs:
- The
Cargo.lock
files indirectory
and all subdirectories - The
dependencies
andworkspace.dependencies
fields inCargo.toml
files indirectory
and all subdirectories - The
GITHUB_JOB
environment variable ifcache-key-job
istrue
- The environment variables specified in
cache-key-env
- The
os.platform()
andos.arch()
of the runner
In case of a cache key miss, a cache matching the os.platform()
and os.arch()
of the runner is restored.
The following directories are cached:
- The Cargo registry (
~/.cargo/registry
)- Before caching, the registry is cleaned with
cargo cache --autoclean
and any.cache
directories are removed
- Before caching, the registry is cleaned with
- The build artifacts (
target
)- Before caching, the target directory is cleaned with
cargo sweep --installed
ifcache-sweep
istrue
, and theexamples
andincremental
directories as well as all dep-info files (*.d
) are removed - If
cache-profile
is specified, all other profile directories are removed
- Before caching, the target directory is cleaned with
When the sccache
input is true
, sccache
is installed and set up with GitHub Actions integration by setting the following environment variables:
ACTIONS_CACHE_URL
is set to the cache URL provided to the actionACTIONS_RUNTIME_TOKEN
is set to the token provided to the actionSCCACHE_PATH
is set to the path to thesccache
binarySCCACHE_GHA_ENABLED
is set totrue
RUSTC_WRAPPER
is set tosccache