Skip to content

Commit 0ec0838

Browse files
committed
feat(install-toolchain): support Windows, incl. windows-11-arm
windows-11-arm ships no Rust (actions/partner-runner-images#77), and the Unix sh.rustup.rs installer doesn't apply there. When no rustup is present on Windows, fetch the arch-appropriate rustup-init.exe instead - reading the true machine arch from PROCESSOR_ARCHITE(W6432), since git-bash's `uname -m` lies under x64 emulation. Add a windows-latest + windows-11-arm self-test leg.
1 parent 24ee5e6 commit 0ec0838

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

‎.github/actions/install-toolchain/action.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Install Rust toolchain
22
description: >-
33
Install Rust via rustup (toolchain, components, targets) and put
4-
~/.cargo/bin on PATH. Avoids third-party toolchain actions so behaviour does
5-
not drift with the runner image.
4+
~/.cargo/bin on PATH. Works on Linux, macOS and Windows — including
5+
windows-11-arm, which ships no preinstalled Rust. Avoids third-party
6+
toolchain actions so behaviour does not drift with the runner image.
67
78
inputs:
89
toolchain:

‎.github/actions/install-toolchain/install-toolchain.sh‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@ if command -v rustup >/dev/null 2>&1; then
99
rustup toolchain install "$TOOLCHAIN" --profile minimal
1010
rustup default "$TOOLCHAIN"
1111
else
12-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
13-
| sh -s -- -y --default-toolchain "$TOOLCHAIN" --profile minimal --no-modify-path
14-
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
15-
export PATH="$HOME/.cargo/bin:$PATH"
12+
case "$(uname -s)" in
13+
MINGW* | MSYS* | CYGWIN*)
14+
# Windows runners — notably windows-11-arm — can ship no Rust at all, and the Unix
15+
# sh.rustup.rs installer doesn't apply here. Fetch the arch-appropriate rustup-init.exe.
16+
# git-bash's `uname -m` can't be trusted under x64 emulation, so read the true machine arch
17+
# from Windows' own PROCESSOR_ARCHITE(W6432) variables.
18+
winarch="${PROCESSOR_ARCHITEW6432:-${PROCESSOR_ARCHITECTURE:-$(uname -m)}}"
19+
case "$winarch" in
20+
ARM64 | arm64 | aarch64) host=aarch64-pc-windows-msvc ;;
21+
*) host=x86_64-pc-windows-msvc ;;
22+
esac
23+
curl --proto '=https' --tlsv1.2 -sSfL \
24+
"https://static.rust-lang.org/rustup/dist/$host/rustup-init.exe" -o rustup-init.exe
25+
./rustup-init.exe -y --default-toolchain "$TOOLCHAIN" --profile minimal --no-modify-path
26+
# GITHUB_PATH wants a Windows path (later steps may run in pwsh); this script continues in
27+
# git-bash, where the cargo bin dir is $HOME/.cargo/bin.
28+
printf '%s\\.cargo\\bin\n' "${USERPROFILE:-$HOME}" >> "$GITHUB_PATH"
29+
export PATH="$HOME/.cargo/bin:$PATH"
30+
;;
31+
*)
32+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
33+
| sh -s -- -y --default-toolchain "$TOOLCHAIN" --profile minimal --no-modify-path
34+
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
35+
export PATH="$HOME/.cargo/bin:$PATH"
36+
;;
37+
esac
1638
fi
1739

1840
if [ -n "$COMPONENTS" ]; then

‎.github/workflows/selftest.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ jobs:
113113
working-directory: fixtures/sample-crate
114114
expected-version: "0.1.0"
115115

116+
# install-toolchain must also work on Windows. windows-latest exercises the rustup-present path;
117+
# windows-11-arm ships no Rust at all, exercising the rustup-init.exe bootstrap. Building the
118+
# fixture proves the toolchain is usable, not merely installed (and, on arm64, that the image
119+
# provides the MSVC arm64 link tools).
120+
selftest-windows:
121+
name: install-toolchain · ${{ matrix.runner }}
122+
strategy:
123+
fail-fast: false
124+
matrix:
125+
runner: [windows-latest, windows-11-arm]
126+
runs-on: ${{ matrix.runner }}
127+
steps:
128+
- uses: actions/checkout@v6
129+
- uses: ./.github/actions/install-toolchain
130+
with:
131+
components: clippy
132+
- name: toolchain is installed + on PATH
133+
shell: bash
134+
run: rustc --version && cargo --version && cargo clippy --version
135+
- name: build the fixture
136+
shell: bash
137+
working-directory: fixtures/sample-crate
138+
run: cargo build --locked
139+
116140
# rust-cache must OBEY an explicit CARGO_INCREMENTAL (not force it off): set it at job level and
117141
# confirm the action leaves it untouched for the build steps that would follow.
118142
selftest-cache-passthrough:

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ During bring-up, pin `@main`; once the interface is stable we cut a `v1` tag plu
1212
### `install-toolchain`
1313

1414
Installs Rust via rustup — toolchain, components, and targets — and puts `~/.cargo/bin` on `PATH`.
15+
Works on Linux, macOS and Windows; when a runner ships no Rust at all (e.g. `windows-11-arm`) it bootstraps the arch-appropriate `rustup-init` instead of failing.
1516

1617
```yaml
1718
- uses: gronke/cicd-rust/.github/actions/install-toolchain@main

0 commit comments

Comments
 (0)