Skip to content

Rust prebuilt

Rust prebuilt #51

Workflow file for this run

name: Rust prebuilt
on: workflow_dispatch
jobs:
build:
name: Rust [${{matrix.arch}}-${{matrix.os}}-${{matrix.version}}]
runs-on: ${{matrix.runner}}
strategy:
fail-fast: false
matrix:
arch: [ x86_64 ]
os: [ windows, macos, ubuntu-20.04, ubuntu-22.04 ]
version: [ 1.73.0 ]
include:
- os: windows
runner: windows-2022
- os: macos
runner: macos-latest
- os: ubuntu-20.04
runner: ubuntu-20.04
- os: ubuntu-22.04
runner: ubuntu-22.04
steps:
- name: Preflight
shell: pwsh
run: |
$LlvmVersion = "16.0.6"
$LlvmRunId = '${{ github.event.inputs.run_id }}'
if ($LlvmRunId -eq 'latest') {
$LlvmRunId = $(gh run list -w 'LLVM prebuilt' --json 'status,databaseId,conclusion') |
ConvertFrom-Json | Where-Object { ($_.status -eq 'completed') -and ($_.conclusion -eq 'success') } |
Select-Object -First 1 -ExpandProperty databaseId
}
echo "LLVM_VERSION=$LlvmVersion" >> $Env:GITHUB_ENV
echo "LLVM_RUN_ID=$LlvmRunId" >> $Env:GITHUB_ENV
$RustBuildDir = if ($IsWindows) { "C:\rust" } else { "${{runner.temp}}" }
echo "RUST_BUILD_DIR=$RustBuildDir" >> $Env:GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Configure Windows runner
if: runner.os == 'Windows'
shell: pwsh
run: |
choco install --no-progress ninja 7zip wget
Install-Module VsDevShell -Force
docker system prune -a -f # free some space on C:\
New-Item -Path $Env:RUST_BUILD_DIR -ItemType Directory | Out-Null
- name: Configure macOS runner
if: runner.os == 'macOS'
run: |
brew install ninja
echo "MACOSX_DEPLOYMENT_TARGET=10.13" >> $GITHUB_ENV
- name: Configure Linux runner
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install ninja-build xz-utils
sudo apt install g++-aarch64-linux-gnu
- name: Configure Android NDK
if: runner.os == 'linux'
shell: pwsh
run: |
$CargoConfigFile = "~/.cargo/config"
$AndroidToolchain="${Env:ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64"
Get-ChildItem -Path $AndroidToolchain "libunwind.a" -Recurse | ForEach-Object {
$libunwind = $_.FullName
$libgcc = Join-Path $_.DirectoryName "libgcc.a"
if (-Not (Test-Path $libgcc)) {
Write-Host $libgcc
Copy-Item $libunwind $libgcc
}
}
echo "[target.i686-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/i686-linux-android21-clang`"" >> $CargoConfigFile
echo "CC_i686-linux-android=$AndroidToolchain/bin/i686-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_i686-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
Copy-Item "$AndroidToolchain/bin/llvm-ar" "$AndroidToolchain/bin/i686-linux-android21-ar"
echo "[target.x86_64-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/x86_64-linux-android21-clang`"" >> $CargoConfigFile
echo "CC_x86_64-linux-android=$AndroidToolchain/bin/x86_64-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_x86_64-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
Copy-Item "$AndroidToolchain/bin/llvm-ar" "$AndroidToolchain/bin/x86_64-linux-android21-ar"
echo "[target.armv7-linux-androideabi]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/armv7a-linux-androideabi21-clang`"" >> $CargoConfigFile
echo "CC_armv7-linux-androideabi=$AndroidToolchain/bin/armv7a-linux-androideabi21-clang" >> $Env:GITHUB_ENV
echo "AR_armv7-linux-androideabi=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
Copy-Item "$AndroidToolchain/bin/llvm-ar" "$AndroidToolchain/bin/armv7a-linux-androideabi21-ar"
echo "[target.aarch64-linux-android]" >> $CargoConfigFile
echo "linker=`"$AndroidToolchain/bin/aarch64-linux-android21-clang`"" >> $CargoConfigFile
echo "CC_aarch64-linux-android=$AndroidToolchain/bin/aarch64-linux-android21-clang" >> $Env:GITHUB_ENV
echo "AR_aarch64-linux-android=$AndroidToolchain/bin/llvm-ar" >> $Env:GITHUB_ENV
Copy-Item "$AndroidToolchain/bin/llvm-ar" "$AndroidToolchain/bin/aarch64-linux-android21-ar"
- name: Install clang+llvm
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$LlvmPlatform='${{matrix.os}}'
$LlvmArch='x86_64'
$LlvmVersion = $Env:LLVM_VERSION
$LlvmRunId = $Env:LLVM_RUN_ID
$LlvmName="clang+llvm-${LlvmVersion}-${LlvmArch}-${LlvmPlatform}"
& gh run download $LlvmRunId --repo $Env:GITHUB_REPOSITORY -n $LlvmName
if ($IsWindows) {
$TempDir = "C:/temp"
$LLVM_PREFIX = "C:/llvm"
cmd.exe /c "7z.exe x ${LlvmName}.tar.xz -so | 7z x -si -ttar -o`"C:/temp`""
mv "$TempDir/${LlvmName}" $LLVM_PREFIX
$LLVM_CONFIG="$LLVM_PREFIX/bin/llvm-config.exe"
} else {
$TempDir = "/tmp"
$LLVM_PREFIX = "/opt/llvm"
tar -xvf "${LlvmName}.tar.xz" -C $TempDir
sudo mv "$TempDir/${LlvmName}" $LLVM_PREFIX
$LLVM_CONFIG="$LLVM_PREFIX/bin/llvm-config"
}
$LLVM_BIN_PATH="$LLVM_PREFIX/bin"
$LLVM_DIR="$LLVM_PREFIX/lib/cmake/llvm"
echo "LLVM_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "LLVM_CONFIG=$LLVM_CONFIG" >> $Env:GITHUB_ENV
echo "PATH=$LLVM_BIN_PATH$([IO.Path]::PathSeparator)$Env:PATH" >> $Env:GITHUB_ENV
- name: Clone project
uses: actions/checkout@v3
with:
path: llvm-prebuilt
- name: Clone Rust ${{matrix.version}}
uses: actions/checkout@v3
with:
repository: rust-lang/rust
ref: ${{matrix.version}}
submodules: true
fetch-depth: 1
path: rust
- name: Patch Rust
shell: pwsh
run: |
git -C rust apply ../llvm-prebuilt/patches/rust-${{matrix.version}}-disable-filecheck-tool-sanity-checks.patch
if ($IsWindows) {
git -C rust apply ../llvm-prebuilt/patches/rust-${{matrix.version}}-force-windows-msvc-dynamic-runtime-linking.patch
}
- name: Configure Rust
shell: pwsh
working-directory: rust
run: |
$RustBuildDir = "$Env:RUST_BUILD_DIR".Replace('\','\\')
$RustLlvmConfig = $Env:LLVM_CONFIG.Replace('\','\\')
$RustHostArch = '${{matrix.arch}}'
$RustHostPlatform = @{'windows'='pc-windows-msvc';
'macos'='apple-darwin';'linux'='unknown-linux-gnu';}['${{runner.os}}']
$RustHostTarget = "$RustHostArch-$RustHostPlatform"
$RustTargets = @{
'windows' = @('x86_64-pc-windows-msvc', 'aarch64-pc-windows-msvc');
'macos' = @('x86_64-apple-darwin', 'aarch64-apple-darwin',
'x86_64-apple-ios', 'aarch64-apple-ios');
'linux' = @('x86_64-unknown-linux-gnu', 'aarch64-unknown-linux-gnu',
'i686-linux-android', 'armv7-linux-androideabi',
'x86_64-linux-android', 'aarch64-linux-android');
}['${{runner.os}}']
$config = @(
"changelog-seen=2",
"[llvm]",
"download-ci-llvm=false",
"ninja=true",
"link-shared=false",
"static-libstdcpp=false",
"targets=`"X86;ARM;AArch64;WebAssembly`""
"[build]",
"docs=false",
"host=[`"$RustHostTarget`"]",
"target=[$($RustTargets | Join-String -DoubleQuote -Separator ',')]",
"build-dir=`"$RustBuildDir`"",
"[install]",
"[rust]",
"channel=`"stable`"",
"dist-src=false",
"[target.${RustHostTarget}]",
"llvm-config=`"${RustLlvmConfig}`"",
"crt-static=false",
"[dist]",
"src-tarball=false",
"compression-formats=[`"xz`"]"
)
Set-Content -Path .\config.toml -Value $config
- name: Build and package Rust
shell: pwsh
working-directory: rust
run: |
Remove-Item Env:GITHUB_ACTIONS
python x.py dist
- name: Upload Rust
uses: actions/upload-artifact@v3
with:
name: rust-${{matrix.version}}-${{matrix.arch}}-${{matrix.os}}
path: ${{steps.dynamic-variables.outputs.rust-build-dir}}/dist