GitHub Action to set up a Rust toolchain with sensible CI defaults and caching.
- Installs
rustupand the requested toolchain (or readsrust-toolchain.toml) - Caches the Cargo registry and build artifacts via Swatinem/rust-cache
- Sets CI-optimized environment variables (no incremental builds, sparse registry, etc.)
- Installs extra cargo binaries via pre-compiled binaries (install-action)
- Includes
clippyandrustfmtby default
- uses: crustacean-dev/setup-rust@v1- uses: crustacean-dev/setup-rust@v1
with:
toolchain: nightly
components: clippy,rustfmt,miri
targets: wasm32-unknown-unknown
cargo-bins: cargo-nextest cargo-llvm-cov
rustflags: "-D warnings -A dead_code"When the toolchain input is left empty and a rust-toolchain or rust-toolchain.toml file is present, the action lets rustup read it automatically. Additional components and targets are still installed on top.
- uses: crustacean-dev/setup-rust@v1
with:
components: "" # already defined in rust-toolchain.toml- uses: crustacean-dev/setup-rust@v1
id: rust
- run: echo "Using ${{ steps.rust.outputs.rustc-version }}"| Input | Default | Description |
|---|---|---|
toolchain |
"" |
Rust toolchain to install (e.g. stable, nightly, 1.80.0). Reads rust-toolchain.toml if empty. |
components |
clippy,rustfmt |
Comma-separated list of rustup components to install |
targets |
"" |
Comma-separated list of additional targets to install |
cache |
true |
Enable Cargo caching via Swatinem/rust-cache |
cache-key |
"" |
Additional cache key for differentiation |
cache-shared-key |
"" |
Shared cache key stable across jobs |
cargo-bins |
"" |
Space-separated list of cargo binaries to install (e.g. cargo-nextest cargo-llvm-cov) |
rustflags |
-D warnings |
Value for RUSTFLAGS. Empty string to not override. |
| Output | Description |
|---|---|
rustc-version |
Installed rustc version string |
cargo-version |
Installed cargo version string |
cachekey |
Short hash (12 chars) suitable for cache keying |
The action sets the following environment variables unless they are already defined:
| Variable | Value | Reason |
|---|---|---|
CARGO_INCREMENTAL |
0 |
Incremental compilation is useless in CI and wastes disk |
CARGO_PROFILE_DEV_DEBUG |
0 |
Reduces debug info for faster compilation |
CARGO_TERM_COLOR |
always |
Forces color output in logs |
RUST_BACKTRACE |
short |
Short backtraces on panic |
CARGO_REGISTRIES_CRATES_IO_PROTOCOL |
sparse |
Faster registry index updates |
RUSTFLAGS |
-D warnings |
Denies warnings by default (configurable) |