Skip to content

Commit 2b6f4c9

Browse files
committed
Add script to install pre-build packages on Linux and Windows
1 parent f69d3b1 commit 2b6f4c9

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

.github/scripts/prebuild.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See http://swift.org/LICENSE.txt for license information
9+
## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
13+
param (
14+
[switch]$SkipAndroid,
15+
[switch]$InstallCMake
16+
)
17+
18+
# winget isn't easily made available in containers, so use chocolatey
19+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
20+
21+
if ($InstallCMake) {
22+
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System' --apply-install-arguments-to-dependencies
23+
choco install -y ninja
24+
25+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
26+
refreshenv
27+
28+
# Let swiftc find the path to link.exe in the CMake smoke test
29+
$env:Path += ";$(Split-Path -Path "$(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" "-latest" -products Microsoft.VisualStudio.Product.BuildTools -find VC\Tools\MSVC\*\bin\HostX64\x64\link.exe)" -Parent)"
30+
}
31+
32+
if (-not $SkipAndroid) {
33+
choco install -y android-ndk
34+
35+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
36+
refreshenv
37+
38+
# Work around a bug in the package causing the env var to be set incorrectly
39+
$env:ANDROID_NDK_ROOT = $env:ANDROID_NDK_ROOT.replace('-windows.zip','')
40+
}

.github/scripts/prebuild.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the Swift open source project
5+
##
6+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
7+
## Licensed under Apache License v2.0 with Runtime Library Exception
8+
##
9+
## See http://swift.org/LICENSE.txt for license information
10+
## See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
##
12+
##===----------------------------------------------------------------------===##
13+
14+
set -e
15+
16+
if [[ $(uname) == Darwin ]] ; then
17+
if [[ "$INSTALL_CMAKE" == "1" ]] ; then
18+
mkdir -p "$RUNNER_TOOL_CACHE"
19+
if ! command -v cmake >/dev/null 2>&1 ; then
20+
curl -fsSLO https://github.com/Kitware/CMake/releases/download/v4.1.2/cmake-4.1.2-macos-universal.tar.gz
21+
echo '3be85f5b999e327b1ac7d804cbc9acd767059e9f603c42ec2765f6ab68fbd367 cmake-4.1.2-macos-universal.tar.gz' > cmake-4.1.2-macos-universal.tar.gz.sha256
22+
sha256sum -c cmake-4.1.2-macos-universal.tar.gz.sha256
23+
tar -xf cmake-4.1.2-macos-universal.tar.gz
24+
ln -s "$PWD/cmake-4.1.2-macos-universal/CMake.app/Contents/bin/cmake" "$RUNNER_TOOL_CACHE/cmake"
25+
fi
26+
if ! command -v ninja >/dev/null 2>&1 ; then
27+
curl -fsSLO https://github.com/ninja-build/ninja/releases/download/v1.13.1/ninja-mac.zip
28+
echo 'da7797794153629aca5570ef7c813342d0be214ba84632af886856e8f0063dd9 ninja-mac.zip' > ninja-mac.zip.sha256
29+
sha256sum -c ninja-mac.zip.sha256
30+
unzip ninja-mac.zip
31+
rm -f ninja-mac.zip
32+
mv ninja "$RUNNER_TOOL_CACHE/ninja"
33+
fi
34+
fi
35+
elif command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy
36+
export DEBIAN_FRONTEND=noninteractive
37+
38+
apt-get update -y
39+
40+
# Build dependencies
41+
apt-get install -y libsqlite3-dev libncurses-dev
42+
43+
# Debug symbols
44+
apt-get install -y libc6-dbg
45+
46+
if [[ "$INSTALL_CMAKE" == "1" ]] ; then
47+
apt-get install -y cmake ninja-build
48+
fi
49+
50+
# Android NDK
51+
dpkg_architecture="$(dpkg --print-architecture)"
52+
if [[ "$SKIP_ANDROID" != "1" ]] && [[ "$dpkg_architecture" == amd64 ]] ; then
53+
eval "$(cat /etc/os-release)"
54+
case "$VERSION_CODENAME" in
55+
bookworm|jammy)
56+
: # Not available
57+
;;
58+
noble)
59+
apt-get install -y google-android-ndk-r26c-installer
60+
;;
61+
*)
62+
echo "Unable to fetch Android NDK for unknown Linux distribution: $VERSION_CODENAME" >&2
63+
exit 1
64+
esac
65+
else
66+
echo "Skipping Android NDK installation on $dpkg_architecture" >&2
67+
fi
68+
elif command -v dnf >/dev/null 2>&1 ; then # rhel-ubi9
69+
dnf update -y
70+
71+
# Build dependencies
72+
dnf install -y sqlite-devel ncurses-devel
73+
74+
# Debug symbols
75+
dnf debuginfo-install -y glibc
76+
elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
77+
yum update -y
78+
79+
# Build dependencies
80+
yum install -y sqlite-devel ncurses-devel
81+
82+
# Debug symbols
83+
yum install -y yum-utils
84+
debuginfo-install -y glibc
85+
fi

.github/workflows/pull_request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ jobs:
1818
with:
1919
linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]'
2020
linux_swift_versions: '["nightly-main"]'
21-
linux_pre_build_command: 'curl -L https://raw.githubusercontent.com/swiftlang/swift-build/refs/heads/main/.github/scripts/prebuild.sh > prebuild.sh && sh prebuild.sh'
21+
linux_pre_build_command: ./.github/scripts/prebuild.sh
2222
windows_swift_versions: '["nightly-main"]'
23+
windows_pre_build_command: 'Invoke-Program .\.github\scripts\prebuild.ps1'
2324
enable_android_sdk_build: true
2425
android_sdk_build_command: "swift build --build-tests"
2526
android_ndk_versions: '["r27d", "r29"]'

0 commit comments

Comments
 (0)