Skip to content

crustacean-dev/setup-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup Rust

GitHub Action to set up a Rust toolchain with sensible CI defaults and caching.

Features

  • Installs rustup and the requested toolchain (or reads rust-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 clippy and rustfmt by default

Usage

- uses: crustacean-dev/setup-rust@v1

With options

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

Using rust-toolchain.toml

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

Accessing outputs

- uses: crustacean-dev/setup-rust@v1
  id: rust
- run: echo "Using ${{ steps.rust.outputs.rustc-version }}"

Inputs

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.

Outputs

Output Description
rustc-version Installed rustc version string
cargo-version Installed cargo version string
cachekey Short hash (12 chars) suitable for cache keying

CI Environment Variables

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)

License

MIT

About

Optimized Rust environment setup with aggressive caching

Topics

Resources

License

Stars

Watchers

Forks

Contributors