Setup a specific Rust toolchain with extra features like problem matchers
Find a file
Jean Mertz 70241ab2e9 fixes
2023-05-29 21:27:29 +02:00
.github Check that listed components are installed even with a rust-toolchain file 2023-05-20 16:29:33 +02:00
action.yml fixes 2023-05-29 21:27:29 +02:00
CHANGELOG.md Add changelog 2023-05-29 20:31:27 +02:00
LICENSE Initial commit 2022-04-17 21:06:51 +02:00
README.md allow disabling RUSTFLAGS config 2023-05-29 21:27:29 +02:00
rust.json Add new problem matcher that is aware of color codes 2023-03-18 00:18:20 +01:00

Install Rust Toolchain

This GitHub Action installs a Rust toolchain using rustup. It further integrates into the ecosystem. Caching for Rust tools and build artifacts is enabled. Environment variables are set to optimize the cache hits. Problem Matchers are provided for build messages (cargo, clippy) and formatting (rustfmt).

The action is heavily inspired by dtolnay's https://github.com/dtolnay/rust-toolchain and extends it with further features.

Example workflow

name: "Test Suite"
on:
  push:
  pull_request:

jobs:
  test:
    name: cargo test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - run: cargo test --all-features
 
  # Check formatting with rustfmt
  formatting:
    name: cargo fmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      # Ensure rustfmt is installed and setup problem matcher
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          components: rustfmt
      - name: Rustfmt Check
        uses: actions-rust-lang/rustfmt@v1

Inputs

All inputs are optional. If a toolchain file (i.e., rust-toolchain or rust-toolchain.toml) is found in the root of the repository, its toolchain value takes precedence. First, all items specified in the toolchain file are installed. Afterward, the components and target specified via inputs are installed in addition to the items from the toolchain file.

Name Description Default
toolchain Rustup toolchain specifier e.g. stable, nightly, 1.42.0. stable
target Additional target support to install e.g. wasm32-unknown-unknown
components Comma-separated string of additional components to install e.g. clippy, rustfmt
cache Automatically configure Rust cache (using Swatinem/rust-cache) true
rustflags Set the value of RUSTFLAGS (set to empty string to avoid overwriting existing flags) "-D warnings"

RUSTFLAGS

By default, this action sets the RUSTFLAGS environment variable to -D warnings.

However, rustflags sources are mutually exclusive, so setting this environment variable omits any configuration through target.*.rustflags or build.rustflags.

To prevent this from happening, set the rustflags input to an empty string, which will prevent the action from setting RUSTFLAGS at all, keeping any existing preferences.

You can read more rustflags, and their load order, in the Cargo reference.

Outputs

Name Description
rustc-version Version as reported by rustc --version
cargo-version Version as reported by cargo --version
rustup-version Version as reported by rustup --version

License

The scripts and documentation in this project are released under the MIT License.