actions-rust-lang / setup-rust-toolchain

Setup a specific Rust toolchain with extra features like problem matchers
MIT License
193 stars 33 forks source link

Add support for self-hosted windows runners #45

Open dceddia opened 1 month ago

dceddia commented 1 month ago

I'm building a Tauri app on a self-hosted Windows runner. Here's the relevant bit of the action yaml:

name: 'publish'

on:
  push:
    branches:
      - release

jobs:
  publish-tauri:
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: 'macos-latest' # for Arm and Intel based macs
            args: '--target universal-apple-darwin'
          - platform: 'windows-latest'
            args: ''
          #- platform: 'ubuntu-22.04' # for Tauri v1 you could replace this with ubuntu-20.04.
          #  args: ''

    runs-on: [self-hosted, "${{ matrix.platform }}"]
    steps:
      - uses: actions/checkout@v4

      # ... sets up node and stuff here ...

      - name: install Rust stable
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          # Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
          targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

      - name: Rust cache
        uses: swatinem/rust-cache@v2
        with:
          workspaces: './src-tauri -> target'

The output from the action looks like:

Warning: Unexpected input(s) 'targets', valid inputs are ['toolchain', 'target', 'components', 'cache', 'cache-workspaces', 'cache-directories', 'cache-on-failure', 'cache-key', 'matcher', 'rustflags', 'override']
Run actions-rust-lang/setup-rust-toolchain@v1
  with:
    cache: true
    cache-on-failure: true
    matcher: true
    rustflags: -D warnings
    override: true
  env:
    PNPM_HOME: C:\Windows\ServiceProfiles\NetworkService\setup-pnpm\node_modules\.bin
Run : construct rustup command line
  : construct rustup command line
  echo "targets=$(for t in ${targets//,/ }; do echo -n ' --target' $t; done)" >> $GITHUB_OUTPUT
  echo "components=$(for c in ${components//,/ }; do echo -n ' --component' $c; done)" >> $GITHUB_OUTPUT
  echo "downgrade=" >> $GITHUB_OUTPUT
  Error: bash: command not found

It looks like this repo's action.yml handles Windows in a couple spots but maybe not all, and I think the Github-hosted runners do actually have bash installed so this works fine there.

I'd also be fine with adding a step to install bash if that seems better, though the answer here makes that sound like it might not be the right path.

jonasbb commented 1 month ago

In the current state the action mainly targets the official GitHub runners. I am happy to accept PRs to expand the support here, but I have no way to test it. Besides installing bash, you also have to figure out how to install rustup. There is some support for installing rustup (https://github.com/actions-rust-lang/setup-rust-toolchain/blob/4d1965c9142484e48d40c19de54b5cba84953a06/action.yml#L125-L132), which comes from https://github.com/dtolnay/rust-toolchain/pull/8 but excludes windows.

The requirements could be better documented. A bash that is not ancient and currently an installed version of rustup. With the rustup installation fixed/updated this might be traded with curl support.

dceddia commented 1 month ago

Ahh yep ok that makes sense.

I was hoping to set up the Github Action such that it would be able to bootstrap an otherwise clean Windows install into a build machine, but that seems pretty difficult to pull off.

I ended up installing git (which came with bash) and rustup (which first required an install of Visual Studio via a GUI installer) and for my use case I also need signtool and a vendor-specific tool for accessing a hardware signing token. So I think I'm just going to accept that this needs some manual setup, and leave myself a trail of documentation.