actions-rust-lang/setup-rust-toolchain

setup-rust-toolchain always uses toolchain file from repo root

Rahix opened this issue · 2 comments

Rahix commented

(From #14.)

In avr-hal, there is a rust-toolchain.toml at the root of the repository which is used for building most things. However, one component (ravedude) is built with a different toolchain which is specified in a rust-toolchain.toml file in the relevant subdirectory.

setup-rust-toolchain always uses the toolchain from the root rust-toolchain.toml which means that ravedude is also built using that toolchain instead of the one specified in its own rust-toolchain.toml file. Additionally, because a rust-toolchain.toml file always takes precedence over a toolchain specified in the CI job definition, there is no way to override the toolchain in the CI manifest.

Yes, this action only looks at the root rust-toolchain.toml, but besides a slight inefficiency, this should not matter when using it. cargo and rustc are rustup proxies. If they detect that there is a rust-toolchain.toml file and the toolchain is not installed, it gets installed when needed. As long as you execute cargo inside the ravedude directory, I think everything should work out.

However, in your CI you execute cargo from the repository root, so the root rust-toolchain.toml will take priority here.
https://github.com/Rahix/avr-hal/blob/3c02df9df80e7585765644a87076680a2d99b29a/.github/workflows/ci.yml#L112-L123

    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Install Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
      - name: Install libudev
        run: sudo apt-get update && sudo apt-get install -y libudev-dev
      - name: Check ravedude
        run: |
          cargo check --manifest-path ravedude/Cargo.toml

If you change the last line to cd ravedude && cargo check the correct rust-toolchain.toml should be selected.


How would you suggest to improve this action? Add a directory component to this toolchain check and let it default to ./?

if [[ -f "rust-toolchain" || -f "rust-toolchain.toml" ]]

Even with this change, you would still need to fix the CI workflow. But you would speed it up a little bit, because the toolchain from the root rust-toolchain.toml would not be installed.

Since this seems to be a usage problem and there is no comment on how to improve the current status, I will close the issue. You are welcome to provide additional information later.