πŸ’ΈSave up to $132K/month in CI costs!πŸ‘‰ Try Free✨
Skip to main content
← Back to workflows

How to Install and Configure Rust Toolchains with GitHub Actions

actions-rs-toolchain -
GitHub Action
v1.0.6
588
Contributors
Contributor - svartalfContributor - thomaseizinger
Categories

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: build
on: [push]

jobs:
check:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check

rust-toolchain-action logo

rust-toolchain-action

This action installs and configures Rust toolchains with support for additional targets, components, and profiles.


What is rust-toolchain-action?​

The rust-toolchain-action allows you to install Rust toolchains in your CI/CD workflows using rustup. It supports setting up custom toolchains, installing additional components, and configuring profiles to optimize the installation process.

How to Install a Specific Toolchain​

To install a specific Rust toolchain (e.g., stable, nightly), use the toolchain input:

with:
toolchain: stable

You can specify different versions, such as nightly-2021-09-10 or a stable version like 1.32.0.

How to Add Additional Targets​

If you need to install additional targets (e.g., for cross-compilation), specify them using the target input:

with:
toolchain: stable
target: x86_64-apple-darwin

How to Set a Toolchain as Default​

To set the installed toolchain as the default globally, use the default input:

with:
toolchain: stable
default: true

How to Set a Toolchain for the Current Directory​

To override the toolchain for the current directory, use the override input:

with:
toolchain: nightly
override: true

How to Use Profiles​

You can use rustup profiles to speed up the installation by installing only the minimal components required. To use the minimal profile, for example:

with:
profile: minimal
toolchain: nightly

This skips the installation of extra components like documentation, reducing installation time.

How to Install Additional Components​

To install extra components like clippy or rustfmt, use the components input:

with:
toolchain: stable
components: rustfmt, clippy

For nightly builds, this action will automatically find the most recent nightly version that includes the requested components.

How to Use a Toolchain File​

If your repository includes a rust-toolchain file, the action will automatically use it unless you specify a toolchain input. If both are present, the input takes priority.

How to Retrieve Output Information​

The action provides several output variables that you can use in subsequent steps of your workflow:

  • rustc: Rust compiler version (e.g., 1.40.0)
  • rustc_hash: Rust compiler version hash (useful for caching)
  • cargo: Cargo version
  • rustup: Rustup version

Here’s an example of how to access these outputs:

steps:
- name: Install toolchain
id: rust_install
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- run: echo "Rust version: ${{ steps.rust_install.outputs.rustc }}"