cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Automatically install toolchain from `rust-toolchain.toml`

Open npmccallum opened this issue 3 years ago • 4 comments

Do the checklist before filing an issue:

  • [x] Is this related to the actions-rs Actions? If you think it's a problem related to Github Actions in general, use GitHub Community forum instead: https://github.community
  • [x] You've read the Contributing section about feature requests: https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md#feature-requests
  • [ ] Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.

Motivation

Cargo now offers the rust-toolchain.toml file which allows a project to specify what toolchain details it needs. Currently, actions-rs requires you to set up two actions:

  • actions-rs/toolchain@v1 - install the toolchain things you need
  • actions-rs/cargo@v1 - run cargo (i.e. build)

Instead, the actions-rs/cargo@v1 action could detect if no toolchain was manually specified in the actions yml. If not, it should read rust-toolchain.toml and install all the required stuff automatically.

Workflow example

rust-toolchain.toml:

[toolchain]
channel = "nightly-2021-09-30"
targets = ["x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"]
profile = "minimal"

.github/workflows/test.yml:

on: [push]

name: CI

jobs:
  build_and_test:
    name: Rust project
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --all-features

Notice the lack of any reference to actions-rs/toolchain@v1. Instead, actions-rs/cargo@v1 will install everything required as specified in the rust-toolchain.toml file.

Additional context

https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file

npmccallum avatar Oct 01 '21 19:10 npmccallum

Alternatively, you could do:

on: [push]

name: CI

jobs:
  build_and_test:
    name: Rust project
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --all-features

Where the toolchain action gathers all the details from the rust-toolchain.toml file.

npmccallum avatar Oct 01 '21 19:10 npmccallum

Where the toolchain action gathers all the details from the rust-toolchain.toml file.

This doesn't work at all for me. The action just fails with toolchain input was not given and repository does not have a rust-toolchain file.

.github/workflows/release.yml
name: Release
on:
  push:
    tags:
      - "v*.*.*"

jobs:
  build:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
      - name: Build release binary
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: target/release/fstlg.exe
rust-toolchain.toml
[toolchain]
channel = "nightly-2022-08-14"

maroider avatar Aug 15 '22 12:08 maroider

@maroider I believe that @npmccallum is saying that would be an alternative way that the action could behave, not how it behaves currently.


For what it's worth, either of the options above for potential behaviors would be quite useful to me.

zicklag avatar Nov 04 '22 18:11 zicklag

I created a new minimal action specifically for this for anyone who needs it: https://github.com/dsherret/rust-toolchain-file

dsherret avatar Mar 10 '23 00:03 dsherret