@@ -4,10 +4,12 @@ name: "Hyperlight Workflow Setup"
44description : " Common setup steps for GitHub workflows in the Hyperlight project"
55
66inputs :
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