dtolnay/rust-toolchain

repository·master·Indexed 23 days ago

https://github.com/dtolnay/rust-toolchain

A GitHub Action for installing Rust toolchains using rustup. It supports concise one-line usage via version tags, custom targets and components, and advanced toolchain selection using time-based or release-based offsets.

Tokens
802
Snippets
2
Records
5
Agent score
32%

What's inside dtolnay/rust-toolchain

  1. Install the Rust toolchain via GitHub Action

    master

    Use dtolnay/rust-toolchain to install a Rust toolchain using rustup in your GitHub Actions workflows. The action can automatically select a toolchain based on the version tag (e.g., @stable, @nightly, or @1.89.0) used in the uses statement.

    name: test suite
    on: [push, pull_request]
    
    jobs:
      test:
        name: cargo test
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v7
          - uses: dtolnay/rust-toolchain@stable
          - run: cargo test --all-features
  2. Use toolchain expressions for sliding window support

    master

    For projects requiring a specific window of compiler support, you can use time-based or release-based expressions with the toolchain input. When using these expressions, you must use dtolnay/rust-toolchain@master as the action revision.

    Time-based offset: Installs the most recent stable toolchain as of a specific time in the past (supports years, months, weeks, or days).

    Release-based offset: Installs the stable toolchain that preceded the most recent one by a specific number of minor versions using the minus X releases syntax.

    # Installs the most recent stable toolchain as of the specified time
    - uses: dtolnay/rust-toolchain@master
      with:
        toolchain: stable 18 months ago
    
    # Installs the stable toolchain which preceded the most recent one by the specified number of minor versions
    - uses: dtolnay/rust-toolchain@master
      with:
        toolchain: stable minus 8 releases
  3. Configure toolchain, targets, and components

    master

    You can customize the installation by providing the following optional inputs. Note that if you provide an explicit toolchain input, you should use dtolnay/rust-toolchain@master as the action revision.

    • toolchain: A rustup toolchain specifier (e.g., stable, nightly, 1.89.0, or nightly-2025-01-01).
    • targets: A comma-separated string of additional targets to install (e.g., wasm32-unknown-unknown).
    • components: A comma-separated string of additional components to install (e.g., clippy, rustfmt).
  4. Pinning the action with a commit SHA

    master
    If you choose to pin the action using a full-length commit SHA for security, ensure the SHA you select is within the history of the master branch. Commits outside the master branch history may be garbage-collected, which will cause your workflows to fail.
  5. Use toolchain outputs for caching and cargo commands

    master

    The action provides two outputs that can be used in subsequent steps:

    • cachekey: A short hash of the installed rustc version, useful for GitHub Actions caching.
    • name: The specific version name used by rustup (e.g., 1.62.0). This is useful for running specific cargo commands via cargo +${{ steps.toolchain.outputs.name }}, though usually unnecessary if the toolchain is already the default.