Repository navigation
353 lines (317 loc) · 12.6 KB
/
Copy pathrust-prebuilt.yml
File metadata and controls
353 lines (317 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
name: Rust prebuilt
on:
workflow_dispatch:
inputs:
llvm_run_id:
description: 'LLVM workflow run id'
default: "latest"
required: true
permissions:
actions: read
contents: read
jobs:
build:
name: Rust ${{ matrix.version }} [${{ matrix.arch }}-${{ matrix.os }}]
runs-on: ${{ matrix.runner }}
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
os: windows
runner: windows-2025
version: 1.99.0
- arch: aarch64
os: macos
runner: macos-26
version: 1.99.0
- arch: x86_64
os: ubuntu-22.04
runner: ubuntu-22.04
version: 1.99.0
- arch: x86_64
os: ubuntu-24.04
runner: ubuntu-24.04
version: 1.99.0
steps:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.14'
- name: Configure runner
shell: pwsh
run: |
$RustBuildDir = Join-Path $Env:RUNNER_TEMP "rust-build"
New-Item -Path $RustBuildDir -ItemType Directory -Force | Out-Null
echo "RUST_BUILD_DIR=$RustBuildDir" >> $Env:GITHUB_ENV
if ($IsMacOS) {
echo "MACOSX_DEPLOYMENT_TARGET=10.13" >> $Env:GITHUB_ENV
} elseif ($IsLinux) {
sudo apt-get update
sudo apt-get install -y g++-aarch64-linux-gnu xz-utils
} elseif ($IsWindows) {
$VcpkgRootDir = Join-Path $Env:RUNNER_TEMP "vcpkg"
git clone --depth 1 --branch 2025.10.17 https://github.com/microsoft/vcpkg.git $VcpkgRootDir
if ($LASTEXITCODE -ne 0) {
throw "Failed to clone vcpkg"
}
& (Join-Path $VcpkgRootDir "bootstrap-vcpkg.bat")
if ($LASTEXITCODE -ne 0) {
throw "Failed to bootstrap vcpkg"
}
$Vcpkg = Join-Path $VcpkgRootDir "vcpkg.exe"
& $Vcpkg install "zlib:x64-windows-static-release" "libxml2[core]:x64-windows-static-release"
if ($LASTEXITCODE -ne 0) {
throw "Failed to install LLVM's Windows link dependencies"
}
$ZlibLibrary = Join-Path $VcpkgRootDir "packages/zlib_x64-windows-static-release/lib/zlib.lib"
$LibXml2Library = Join-Path $VcpkgRootDir "packages/libxml2_x64-windows-static-release/lib/libxml2.lib"
foreach ($Library in @($ZlibLibrary, $LibXml2Library)) {
if (-Not (Test-Path $Library)) {
throw "Expected LLVM link dependency was not found at $Library"
}
}
Copy-Item -LiteralPath $LibXml2Library -Destination (Join-Path (Split-Path $LibXml2Library) "xml2.lib")
$LibraryPaths = Get-ChildItem (Join-Path $VcpkgRootDir "packages") -Directory |
Where-Object { $_.Name -like "*_x64-windows-static-release" } |
ForEach-Object { Join-Path $_.FullName "lib" } |
Where-Object { Test-Path $_ }
$LinkLibraryPaths = @($LibraryPaths)
if ($Env:LIB) {
$LinkLibraryPaths += $Env:LIB
}
$Env:LIB = $LinkLibraryPaths -join ";"
echo "LIB=$Env:LIB" >> $Env:GITHUB_ENV
}
- name: Resolve LLVM workflow run
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$LlvmVersion = "22.1.4"
$LlvmRunId = '${{ inputs.llvm_run_id }}'
if ($LlvmRunId -eq 'latest') {
$LlvmRunId = $(gh run list -R $Env:GITHUB_REPOSITORY -w 'LLVM prebuilt' --json 'status,databaseId,conclusion') |
ConvertFrom-Json | Where-Object { ($_.status -eq 'completed') -and ($_.conclusion -eq 'success') } |
Select-Object -First 1 -ExpandProperty databaseId
}
if (-Not $LlvmRunId) {
throw "No successful LLVM prebuilt workflow run was found"
}
echo "LLVM_VERSION=$LlvmVersion" >> $Env:GITHUB_ENV
echo "LLVM_RUN_ID=$LlvmRunId" >> $Env:GITHUB_ENV
- name: Install clang+llvm
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$LlvmName = "clang+llvm-${Env:LLVM_VERSION}-${{ matrix.arch }}-${{ matrix.os }}"
& gh run download $Env:LLVM_RUN_ID --repo $Env:GITHUB_REPOSITORY -n $LlvmName
if ($LASTEXITCODE -ne 0) {
throw "Failed to download $LlvmName from workflow run $Env:LLVM_RUN_ID"
}
$TempDir = Join-Path $Env:RUNNER_TEMP "llvm-extract"
New-Item -Path $TempDir -ItemType Directory -Force | Out-Null
tar -xf "${LlvmName}.tar.xz" -C $TempDir
if ($LASTEXITCODE -ne 0) {
throw "Failed to extract ${LlvmName}.tar.xz"
}
$LlvmPrefix = Join-Path $Env:RUNNER_TEMP "llvm"
Move-Item (Join-Path $TempDir $LlvmName) $LlvmPrefix
$ExeSuffix = if ($IsWindows) { ".exe" } else { "" }
$LlvmConfig = Join-Path $LlvmPrefix "bin/llvm-config${ExeSuffix}"
if (-Not (Test-Path $LlvmConfig)) {
throw "llvm-config was not found at $LlvmConfig"
}
$LlvmBinPath = Join-Path $LlvmPrefix "bin"
foreach ($Tool in @("llc", "lli", "opt")) {
$Source = Join-Path $LlvmBinPath "llvm-$Tool$ExeSuffix"
$Destination = Join-Path $LlvmBinPath "$Tool$ExeSuffix"
if (-Not (Test-Path $Source)) {
throw "Renamed LLVM tool was not found at $Source"
}
Copy-Item -LiteralPath $Source -Destination $Destination -Force
}
echo "LLVM_CONFIG=$LlvmConfig" >> $Env:GITHUB_ENV
echo "$LlvmBinPath" >> $Env:GITHUB_PATH
- name: Clone project
uses: actions/checkout@v7
with:
path: llvm-prebuilt
- name: Clone Rust ${{ matrix.version }}
uses: actions/checkout@v7
with:
repository: rust-lang/rust
ref: ${{ matrix.version }}
fetch-depth: 1
path: rust
- name: Clone required Rust submodules
shell: pwsh
run: git -C rust submodule update --init --depth 1 src/tools/cargo src/tools/rustc-perf library/backtrace src/llvm-project src/doc/book src/doc/reference
- name: Configure Android NDK
if: runner.os == 'Linux'
shell: pwsh
run: |
$AndroidNdk = if ($Env:ANDROID_NDK_LATEST_HOME) {
$Env:ANDROID_NDK_LATEST_HOME
} else {
$Env:ANDROID_NDK_HOME
}
if (-Not $AndroidNdk) {
throw "No Android NDK installation was found"
}
$AndroidToolchain = Join-Path $AndroidNdk "toolchains/llvm/prebuilt/linux-x86_64"
if (-Not (Test-Path $AndroidToolchain)) {
throw "Android NDK toolchain was not found at $AndroidToolchain"
}
Get-ChildItem -Path $AndroidToolchain -Filter "libunwind.a" -Recurse | ForEach-Object {
$LibGcc = Join-Path $_.DirectoryName "libgcc.a"
if (-Not (Test-Path $LibGcc)) {
Copy-Item $_.FullName $LibGcc
}
}
echo "ANDROID_TOOLCHAIN=$AndroidToolchain" >> $Env:GITHUB_ENV
- name: Configure Rust
shell: pwsh
working-directory: rust
run: |
$RustBuildDir = $Env:RUST_BUILD_DIR -Replace '\\','/'
$RustLlvmConfig = $Env:LLVM_CONFIG -Replace '\\','/'
$RustHostPlatform = if ($IsWindows) {
"pc-windows-msvc"
} elseif ($IsMacOS) {
"apple-darwin"
} else {
"unknown-linux-gnu"
}
$RustHostTarget = "${{ matrix.arch }}-$RustHostPlatform"
$RustTargets = if ($IsWindows) {
@(
"x86_64-pc-windows-msvc",
"aarch64-pc-windows-msvc"
)
} elseif ($IsMacOS) {
@(
"x86_64-apple-darwin",
"aarch64-apple-darwin",
"x86_64-apple-ios",
"aarch64-apple-ios"
)
} else {
@(
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"i686-linux-android",
"armv7-linux-androideabi",
"x86_64-linux-android",
"aarch64-linux-android"
)
}
$QuotedTargets = ($RustTargets | ForEach-Object { "`"$_`"" }) -join ", "
$RustTools = @("cargo", "clippy", "rustdoc", "rustfmt", "rust-analyzer")
if ($IsMacOS -or $IsWindows) {
$RustTools += "analysis"
}
$QuotedTools = ($RustTools | ForEach-Object { "`"$_`"" }) -join ", "
$Config = @(
"profile = `"dist`"",
"",
"[build]",
"build = `"$RustHostTarget`"",
"host = [`"$RustHostTarget`"]",
"target = [$QuotedTargets]",
"build-dir = `"$RustBuildDir`"",
"docs = false",
"extended = true",
"tools = [$QuotedTools]",
"submodules = false",
"",
"[llvm]",
"download-ci-llvm = false",
"link-shared = false",
"static-libstdcpp = false",
"",
"[rust]",
"channel = `"stable`"",
"dist-src = false",
"",
"[target.$RustHostTarget]",
"llvm-config = `"$RustLlvmConfig`"",
"llvm-has-rust-patches = false",
"crt-static = false",
"",
"[dist]",
"src-tarball = false",
"compression-formats = [`"xz`"]",
"compression-profile = `"balanced`""
)
if ($IsLinux) {
$Aarch64Cc = (Get-Command aarch64-linux-gnu-gcc).Source -Replace '\\','/'
$Aarch64Cxx = (Get-Command aarch64-linux-gnu-g++).Source -Replace '\\','/'
$Aarch64Ar = (Get-Command aarch64-linux-gnu-ar).Source -Replace '\\','/'
$Config += @(
"",
"[target.aarch64-unknown-linux-gnu]",
"cc = `"$Aarch64Cc`"",
"cxx = `"$Aarch64Cxx`"",
"ar = `"$Aarch64Ar`"",
"linker = `"$Aarch64Cc`""
)
$AndroidToolchain = $Env:ANDROID_TOOLCHAIN -Replace '\\','/'
$AndroidAr = "$AndroidToolchain/bin/llvm-ar"
$AndroidRanlib = "$AndroidToolchain/bin/llvm-ranlib"
$AndroidTargets = @{
"i686-linux-android" = "i686-linux-android21-clang"
"armv7-linux-androideabi" = "armv7a-linux-androideabi21-clang"
"x86_64-linux-android" = "x86_64-linux-android21-clang"
"aarch64-linux-android" = "aarch64-linux-android21-clang"
}
foreach ($Target in $AndroidTargets.GetEnumerator()) {
$AndroidCc = "$AndroidToolchain/bin/$($Target.Value)"
$AndroidCxx = "$AndroidCc++"
$Config += @(
"",
"[target.$($Target.Key)]",
"cc = `"$AndroidCc`"",
"cxx = `"$AndroidCxx`"",
"ar = `"$AndroidAr`"",
"ranlib = `"$AndroidRanlib`"",
"linker = `"$AndroidCc`""
)
}
}
Set-Content -Path bootstrap.toml -Value $Config
Get-Content bootstrap.toml
- name: Build and package Rust
shell: pwsh
working-directory: rust
run: |
Remove-Item Env:GITHUB_ACTIONS -ErrorAction SilentlyContinue
Remove-Item Env:CI -ErrorAction SilentlyContinue
python x.py dist
if ($LASTEXITCODE -ne 0) {
throw "Rust distribution build failed"
}
- name: Package Rust toolchain
shell: pwsh
run: |
$PackageName = "rust-${{ matrix.version }}-${{ matrix.arch }}-${{ matrix.os }}"
$PackageDir = Join-Path $Env:RUNNER_TEMP $PackageName
New-Item -Path $PackageDir -ItemType Directory -Force | Out-Null
Move-Item (Join-Path $Env:RUST_BUILD_DIR "dist/*.tar.xz") $PackageDir
Push-Location $Env:RUNNER_TEMP
try {
tar -cJf "$Env:GITHUB_WORKSPACE/${PackageName}.tar.xz" $PackageName
if ($LASTEXITCODE -ne 0) {
throw "Failed to create ${PackageName}.tar.xz"
}
} finally {
Pop-Location
}
- name: Upload Rust packages
uses: actions/upload-artifact@v7
with:
name: rust-${{ matrix.version }}-${{ matrix.arch }}-${{ matrix.os }}
path: rust-${{ matrix.version }}-${{ matrix.arch }}-${{ matrix.os }}.tar.xz
if-no-files-found: error