Skip to content

Commit 5d8eb43

Browse files
simongdaviesCopilot
andcommitted
Support multiple Rust toolchain files
Accept one or two toolchain directories and install the versions, components, and targets declared by their native rustup files. Document the breaking v2 interface and explicit default selection. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 2f4142b commit 5d8eb43

2 files changed

Lines changed: 119 additions & 52 deletions

File tree

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,56 @@ jobs:
99
setup:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v7
1313

14-
- uses: hyperlight-dev/ci-setup-workflow@v1.0.0
15-
with:
16-
rust-toolchain: "1.74.0"
14+
- uses: hyperlight-dev/ci-setup-workflow@v2.0.0
15+
with:
16+
toolchain-directories: |
17+
.
18+
guests
19+
default-directory: .
1720
```
1821
22+
Check out the consumer repository before invoking the action.
23+
1924
## Inputs
2025
2126
### Parameters
2227
2328
| Name | Description |
2429
| ---- | ----------- |
25-
| `rust-toolchain` | The rust toolchain version to use. |
30+
| `toolchain-directories` | One or two newline-separated directories containing `rust-toolchain.toml` or `rust-toolchain`. Required. |
31+
| `default-directory` | One of the listed directories, whose compiler becomes the global default. Defaults to the first entry. |
32+
| `just-version` | Version of Just to install; defaults to `1.41`. |
33+
34+
List each directory whose compiler you need installed. Paths are relative to the
35+
checked-out workspace; absolute paths also work. Blank lines and surrounding
36+
whitespace are ignored.
37+
38+
Rustup reads the version, profile, components, and targets from each directory's
39+
toolchain file. Put required extras such as `clippy`, `rustfmt`,
40+
`x86_64-unknown-none`, or cross-compilation targets in those files.
41+
42+
The selected compiler becomes the global default; no directory override is set.
43+
Consumer toolchain files still select the compiler when building in their directories.
44+
The default must select a channel or named toolchain, not an absolute compiler
45+
`path` inside the toolchain file. Absolute directory inputs are still supported.
2646

2747
## Overview
2848

2949
This action performs the following steps:
3050

31-
- Installs the Rust tool chain at the specified version.
32-
- Installs additional rust components like clippy, rustfmt, ect
33-
- Installs Just
34-
- Sets up the clang toolchain on Linux machines (this should probably get moved into the hosted runner image setup...)
35-
- Installs the `x86_64-pc-windows-msvc` rust target for cross-compilation on Linux machines
51+
- Installs rustup if needed and the toolchains specified by the listed directories.
52+
- Sets the selected default compiler.
53+
- Installs the requested components and targets.
54+
- Installs Just.
55+
- Sets up the clang toolchain on Linux.
56+
- Enables the Windows Hypervisor Platform on Windows.
3657
- Sets up environment variables needed to build / run tests based on the machine's configuration.
3758

59+
Runners need Bash 5 and rustup or curl. The setup action installs rustup when
60+
missing and installs Bash through Homebrew on macOS.
61+
3862
## Code of Conduct
3963

4064
See the [Code of Conduct](./CODE_OF_CONDUCT.md).

action.yml

Lines changed: 85 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ name: "Hyperlight Workflow Setup"
44
description: "Common setup steps for GitHub workflows in the Hyperlight project"
55

66
inputs:
7-
rust-toolchain:
8-
description: "(Default: 1.94.0) Rust toolchain specification to install - see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification"
7+
toolchain-directories:
8+
description: "One or two newline-separated directories containing Rust toolchain files."
9+
required: true
10+
default-directory:
11+
description: "Directory selecting the global default compiler. Defaults to the first listed directory."
912
required: false
10-
default: "1.94.0"
1113
just-version:
1214
description: '(Default: 1.41) Version of just to install.'
1315
required: false
@@ -16,12 +18,87 @@ runs:
1618
using: composite
1719
steps:
1820

19-
- uses: dtolnay/rust-toolchain@master
21+
- name: Validate toolchain directories
22+
id: toolchains
23+
shell: bash
24+
env:
25+
TOOLCHAIN_DIRECTORIES: ${{ inputs.toolchain-directories }}
26+
DEFAULT_DIRECTORY: ${{ inputs.default-directory }}
27+
run: |
28+
fail() { echo "$*" >&2; exit 1; }
29+
trim() { printf '%s\n' "$1" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//'; }
30+
cd "$GITHUB_WORKSPACE"
31+
directories=()
32+
while IFS= read -r directory; do
33+
[[ -n "$directory" ]] || continue
34+
[[ -f "$directory/rust-toolchain.toml" || -f "$directory/rust-toolchain" ]] ||
35+
fail "No toolchain file in directory: $directory"
36+
directories+=("$(cd -- "$directory" && pwd -P)")
37+
done <<< "$(trim "$TOOLCHAIN_DIRECTORIES")"
38+
[[ "${#directories[@]}" -ge 1 && "${#directories[@]}" -le 2 ]] ||
39+
fail "Supply one or two toolchain directories."
40+
first="${directories[0]}"; second="${directories[1]:-}"
41+
# Normalize paths so "." and an absolute path can select the same directory.
42+
default="$(trim "$DEFAULT_DIRECTORY")"
43+
requested_default="${default:-$first}"
44+
default="$(cd -- "$requested_default" && pwd -P)" ||
45+
fail "default-directory not found: $requested_default"
46+
[[ -n "$default" && ( "$default" == "$first" || "$default" == "$second" ) ]] ||
47+
fail "default-directory must be in toolchain-directories."
48+
if [[ "$RUNNER_OS" == Windows ]]; then
49+
first="$(cygpath -m "$first")"
50+
if [[ -n "$second" ]]; then second="$(cygpath -m "$second")"; fi
51+
default="$(cygpath -m "$default")"
52+
fi
53+
printf 'first-directory=%s\nsecond-directory=%s\ndefault-directory=%s\n' \
54+
"$first" "$second" "$default" >> "$GITHUB_OUTPUT"
55+
56+
- name: Install first Rust toolchain
57+
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2
58+
env:
59+
RUSTUP_TOOLCHAIN: ''
60+
RUSTUP_AUTO_INSTALL: '1'
61+
CARGO_PROFILE_DEV_DEBUG: ${{ env.CARGO_PROFILE_DEV_DEBUG || '2' }}
62+
with:
63+
rust-src-dir: ${{ steps.toolchains.outputs.first-directory }}
64+
override: 'false'
65+
cache: 'false'
66+
matcher: 'false'
67+
build-warnings: ''
68+
69+
- name: Install second Rust toolchain
70+
if: ${{ steps.toolchains.outputs.second-directory != '' }}
71+
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2
72+
env:
73+
RUSTUP_TOOLCHAIN: ''
74+
RUSTUP_AUTO_INSTALL: '1'
75+
CARGO_PROFILE_DEV_DEBUG: ${{ env.CARGO_PROFILE_DEV_DEBUG || '2' }}
2076
with:
21-
toolchain: ${{ inputs.rust-toolchain }}
22-
components: clippy, rustfmt
23-
24-
- uses: extractions/setup-just@v4
77+
rust-src-dir: ${{ steps.toolchains.outputs.second-directory }}
78+
override: 'false'
79+
cache: 'false'
80+
matcher: 'false'
81+
build-warnings: ''
82+
83+
- name: Select default Rust toolchain
84+
shell: bash
85+
env:
86+
DEFAULT_DIRECTORY: ${{ steps.toolchains.outputs.default-directory }}
87+
RUSTUP_AUTO_INSTALL: '0'
88+
run: |
89+
unset RUSTUP_TOOLCHAIN
90+
cd -- "$DEFAULT_DIRECTORY"
91+
selected="$(rustup show active-toolchain)"
92+
selected="${selected%% (*}" # Strip the reason suffix, preserving spaces and parens in paths.
93+
case "$selected" in
94+
/*|\\*|[A-Za-z]:[\\/]*)
95+
echo "Path-based toolchains cannot be the global default. Use a channel-based toolchain file." >&2
96+
exit 1 ;;
97+
'') echo "Rustup did not report an active toolchain." >&2; exit 1 ;;
98+
esac
99+
rustup default "$selected"
100+
101+
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4
25102
with:
26103
just-version: ${{ inputs.just-version }}
27104

@@ -87,21 +164,6 @@ runs:
87164
fi
88165
shell: bash
89166

90-
# This is needed to build the rust guests
91-
- name: Install x86_64-unknown-none target
92-
if: ${{ (runner.os == 'Linux') }}
93-
run: |
94-
rustup target add x86_64-unknown-none
95-
shell: bash
96-
97-
# We do this in case there is toolchain skew between repos
98-
- name: Install older rust toolchain(s)
99-
if: ${{ (runner.os == 'Linux') }}
100-
run: |
101-
rustup toolchain install 1.85.0
102-
rustup toolchain install 1.86.0
103-
shell: bash
104-
105167
- name: Set up env vars (Linux)
106168
if: ${{ (runner.os == 'Linux') }}
107169
run: |
@@ -125,25 +187,6 @@ runs:
125187
run: Enable-WindowsOptionalFeature -Online -FeatureName HyperVisorPlatform
126188
shell: pwsh
127189

128-
- name: Install x86_64-pc-windows-msvc target (Windows)
129-
if: ${{ (runner.os == 'Windows') }}
130-
run: |
131-
rustup target add x86_64-pc-windows-msvc
132-
shell: pwsh
133-
134-
- name: Install x86_64-unknown-none target (Windows)
135-
if: ${{ (runner.os == 'Windows') }}
136-
run: |
137-
rustup target add x86_64-unknown-none
138-
shell: pwsh
139-
140-
- name: Install older rust toolchain(s) (Windows)
141-
if: ${{ (runner.os == 'Windows') }}
142-
run: |
143-
rustup toolchain install 1.85.0
144-
rustup toolchain install 1.86.0
145-
shell: pwsh
146-
147190
- name: Set up env vars (Windows)
148191
if: ${{ (runner.os == 'Windows') }}
149192
run: |

0 commit comments

Comments
 (0)