Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

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@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v2
      - run: cargo test --all-features

  # Check formatting with rustfmt
  formatting:
    name: cargo fmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      # Ensure rustfmt is installed and setup problem matcher
      - uses: actions-rust-lang/setup-rust-toolchain@v2
        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 and no toolchain value is provided, all items specified in the toolchain file will be installed. If a toolchain value is provided, the toolchain file will be ignored. If no toolchain value or toolchain file is present, it will default to stable. 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.

NameDescriptionDefault
toolchainComma-separated list of Rustup toolchain specifier e.g. stable, nightly, 1.42.0. The last version is the default.stable
targetAdditional target support to install e.g. wasm32-unknown-unknown
build-warningsSets the build.warnings config via the CARGO_BUILD_WARNINGS variable. (set to empty string to avoid overwriting existing flags)deny
componentsComma-separated string of additional components to install e.g. clippy, rustfmt
cacheAutomatically configure Rust cache (using Swatinem/rust-cache)true
cache-directoriesPropagates the value to Swatinem/rust-cache
cache-workspacesPropagates the value to Swatinem/rust-cache. Influenced by the value of rust-src-dir.
cache-on-failurePropagates the value to Swatinem/rust-cachetrue
cache-keyPropagates the value to Swatinem/rust-cache as key
cache-shared-keyPropagates the value to Swatinem/rust-cache as shared-key
cache-binPropagates the value to Swatinem/rust-cache as cache-bintrue
cache-providerPropagates the value to Swatinem/rust-cache as cache-provider'github'
cache-all-cratesPropagates the value to Swatinem/rust-cache as cache-all-cratesfalse
cache-workspace-cratesPropagates the value to Swatinem/rust-cache as cache-workspace-cratesfalse
cache-save-ifPropagates the value to Swatinem/rust-cache as save-iftrue
cache-targetsPropagates the value to Swatinem/rust-cache as cache-targetstrue
matcherEnable problem matcher to surface build messages and formatting issuestrue
rustflagsSet the value of RUSTFLAGS (set to empty string to avoid overwriting existing flags)""
overrideSetup the last installed toolchain as the default via rustup overridetrue
rust-src-dirPath from root directory to directory with the Rust source directory (if its not in the root of the repository). Sets a default value for cache-workspaces that enables caching.

Outputs

NameDescription
rustc-versionVersion as reported by rustc --version
cargo-versionVersion as reported by cargo --version
rustup-versionVersion as reported by rustup --version
cachekeyA short hash of the installed rustc version

Dependencies

The action works best on the GitHub-hosted runners, but can work on self-hosted ones too, provided the necessary dependencies are available. PRs to add support for more environments are welcome.

  • bash 5
  • brew (macOS only)
  • rustup or curl
  • using other node actions

License

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

关于 About

Setup a specific Rust toolchain with extra features like problem matchers
cigithub-actionshacktoberfestproblem-matcherrustrust-langrustuptoolchain

语言 Languages

Rust100.0%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
39
Total Commits
峰值: 6次/周
Less
More

核心贡献者 Contributors