Skip to content

Commit 364215b

Browse files
committed
Build latest trunk snapshot on self-hosted github runner with latest stable NDK 29
1 parent 27fd504 commit 364215b

File tree

3 files changed

+159
-13
lines changed

3 files changed

+159
-13
lines changed

.github/workflows/pull_request.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,159 @@ jobs:
2525
name: docker-logs
2626
path: |
2727
*.log
28+
29+
android-build:
30+
name: Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} ${{ matrix.runner }} (compiler=${{ matrix.build-compiler }})
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- swift-version: 'tag:swift-DEVELOPMENT-SNAPSHOT-2025-11-03-a'
36+
build-type: 'docker'
37+
build-compiler: '1'
38+
runner: 'self-hosted'
39+
runs-on: ${{ matrix.runner }}
40+
# 16 hour timeout
41+
timeout-minutes: 1080
42+
steps:
43+
- name: Free Disk Space
44+
if: ${{ matrix.runner != 'self-hosted' }}
45+
run: |
46+
df -h
47+
# brings available space from 25G to 32G
48+
# otherwise we sometimes run out of space during the build
49+
sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /opt/ghc /opt/hostedtoolcache /usr/local/graalvm/ /usr/local/.ghcup/ /usr/local/lib/node_modules /usr/local/share/boost
50+
sudo docker image prune --all --force
51+
sudo docker builder prune -a
52+
df -h
53+
- name: Setup
54+
id: config
55+
run: |
56+
# these variabes are used by build-docker and build-local
57+
# to determine which Swift version to build for
58+
echo "SWIFT_VERSION=${{ matrix.swift-version }}" >> $GITHUB_ENV
59+
# pass the build-compiler matrix through to the build script
60+
echo "BUILD_COMPILER=${{ matrix.build-compiler }}" >> $GITHUB_ENV
61+
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV
62+
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
- name: Build Android SDK (Local)
66+
if: ${{ matrix.build-type == 'local' }}
67+
working-directory: swift-ci/sdks/android
68+
run: |
69+
sudo apt install -q patchelf build-essential cmake ninja-build python3 golang git gnupg2 libcurl4-openssl-dev libedit-dev libicu-dev libncurses5-dev libpython3-dev libsqlite3-dev libxml2-dev rsync uuid-dev uuid-runtime tzdata curl unzip
70+
./build-local ${SWIFT_VERSION} ${WORKDIR}
71+
- name: Build Android SDK (Docker)
72+
if: ${{ matrix.build-type == 'docker' }}
73+
working-directory: swift-ci/sdks/android
74+
run: |
75+
./build-docker ${SWIFT_VERSION} ${WORKDIR}
76+
- name: Install Host Toolchain
77+
if: ${{ matrix.build-type == 'docker' }}
78+
working-directory: swift-ci/sdks/android
79+
run: |
80+
# when building in a Docker container, we don't have a local host toolchain,
81+
# but we need one in order to run the SDK validation tests, so we install it now
82+
HOST_OS=ubuntu$(lsb_release -sr)
83+
source ./scripts/toolchain-vars.sh
84+
mkdir -p ${WORKDIR}/host-toolchain
85+
./scripts/install-swift.sh ${WORKDIR}/host-toolchain/$SWIFT_BASE/usr
86+
ls ${WORKDIR}/host-toolchain
87+
${WORKDIR}/host-toolchain/*/usr/bin/swift --version
88+
- name: Get artifact info
89+
id: info
90+
shell: bash
91+
run: |
92+
set -ex
93+
SWIFT_ROOT=$(dirname ${WORKDIR}/host-toolchain/*/usr)
94+
echo "swift-root=${SWIFT_ROOT}" >> $GITHUB_OUTPUT
95+
echo "swift-path=${SWIFT_ROOT}/usr/bin/swift" >> $GITHUB_OUTPUT
96+
97+
ARTIFACT_PATH=$(realpath ${WORKDIR}/products/*.artifactbundle.tar.gz)
98+
echo "artifact-path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT
99+
echo "sdk-id=x86_64-unknown-linux-android28" >> $GITHUB_OUTPUT
100+
101+
ARTIFACT_EXT=".artifactbundle.tar.gz"
102+
ARTIFACT_NAME="$(basename ${ARTIFACT_PATH} ${ARTIFACT_EXT})"
103+
# depending on whether we are building locally or in a container, add a maker to the name
104+
if [[ "${{ matrix.build-type }}" == 'local' ]]; then
105+
ARTIFACT_NAME="${ARTIFACT_NAME}-local"
106+
fi
107+
if [[ "${{ matrix.build-compiler }}" == '1' ]]; then
108+
ARTIFACT_NAME="${ARTIFACT_NAME}-hostbuild"
109+
fi
110+
# artifacts need a unique name so we suffix with the matrix arch(s)
111+
if [[ ! -z "${{ matrix.arch }}" ]]; then
112+
ARTIFACT_NAME="${ARTIFACT_NAME}-$(echo ${{ matrix.arch }} | tr ',' '-')"
113+
fi
114+
ARTIFACT_NAME="${ARTIFACT_NAME}${ARTIFACT_EXT}"
115+
116+
# There is no way to prevent even a single-file artifact from being zipped:
117+
# https://github.com/actions/upload-artifact?tab=readme-ov-file#zip-archives
118+
# so the actual artifact download will look like:
119+
# swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip
120+
echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
121+
- name: Upload SDK artifactbundle
122+
uses: actions/upload-artifact@v4
123+
with:
124+
compression-level: 0
125+
name: ${{ steps.info.outputs.artifact-name }}
126+
path: ${{ steps.info.outputs.artifact-path }}
127+
- name: Cleanup
128+
if: ${{ matrix.runner != 'self-hosted' }}
129+
run: |
130+
# need to free up some space or else when installing we get: No space left on device
131+
df -h
132+
rm -rf ${WORKDIR}/{build,source}
133+
sudo docker image prune --all --force
134+
sudo docker builder prune -a
135+
df -h
136+
- name: Install artifactbundle
137+
if: ${{ matrix.runner != 'self-hosted' }}
138+
shell: bash
139+
run: |
140+
set -ex
141+
${{ steps.info.outputs.swift-path }} sdk install ${{ steps.info.outputs.artifact-path }}
142+
${{ steps.info.outputs.swift-path }} sdk configure --show-configuration $(${{ steps.info.outputs.swift-path }} sdk list | head -n 1) ${{ steps.info.outputs.sdk-id }}
143+
# recent releases require that ANDROID_NDK_ROOT *not* be set
144+
# see https://github.com/swiftlang/swift-driver/pull/1879
145+
echo "ANDROID_NDK_ROOT=" >> $GITHUB_ENV
146+
147+
- name: Create Demo Project
148+
if: ${{ matrix.runner != 'self-hosted' }}
149+
run: |
150+
cd ${{ runner.temp }}
151+
mkdir DemoProject
152+
cd DemoProject
153+
${{ steps.info.outputs.swift-path }} --version
154+
${{ steps.info.outputs.swift-path }} package init
155+
echo 'import Foundation' >> Sources/DemoProject/DemoProject.swift
156+
echo 'import FoundationEssentials' >> Sources/DemoProject/DemoProject.swift
157+
echo 'import FoundationXML' >> Sources/DemoProject/DemoProject.swift
158+
echo 'import FoundationNetworking' >> Sources/DemoProject/DemoProject.swift
159+
echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift
160+
echo 'import Android' >> Sources/DemoProject/DemoProject.swift
161+
- name: Test Demo Project on Android
162+
uses: skiptools/swift-android-action@main
163+
if: ${{ matrix.runner != 'self-hosted' }}
164+
with:
165+
# only test for the complete arch SDK build to speed up CI
166+
#run-tests: ${{ matrix.arch == '' }}
167+
package-path: ${{ runner.temp }}/DemoProject
168+
installed-sdk: ${{ steps.info.outputs.sdk-id }}
169+
installed-swift: ${{ steps.info.outputs.swift-root }}
170+
171+
- name: Checkout swift-algorithms
172+
if: ${{ matrix.runner != 'self-hosted' }}
173+
uses: actions/checkout@v4
174+
with:
175+
repository: apple/swift-algorithms
176+
path: swift-algorithms
177+
- name: Test swift-algorithms
178+
if: ${{ matrix.runner != 'self-hosted' }}
179+
uses: skiptools/swift-android-action@main
180+
with:
181+
package-path: swift-algorithms
182+
installed-sdk: ${{ steps.info.outputs.sdk-id }}
183+
installed-swift: ${{ steps.info.outputs.swift-root }}

swift-ci/sdks/android/build-docker

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
# default architectures to build for
1818
TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
1919

20-
ANDROID_NDK_VERSION=android-ndk-r27d
20+
ANDROID_NDK_VERSION=android-ndk-r29
21+
ANDROID_API=28
2122

2223
BASEPATH=$(dirname $(realpath $0))
2324
cd ${BASEPATH}
@@ -59,5 +60,6 @@ $DOCKER run -i --rm \
5960
--products-dir "/products" \
6061
--host-toolchain "/usr/local/swift" \
6162
--build-compiler "${BUILD_COMPILER}" \
63+
--android-api "${ANDROID_API}" \
6264
--ndk-home "/usr/local/ndk/${ANDROID_NDK_VERSION}" \
6365
--archs "${TARGET_ARCHS}"

swift-ci/sdks/android/scripts/fetch-source.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,9 @@ perl -pi -e 's:"git",:#:' swift/test/Misc/verify-swift-feature-testing.test-sh
172172
# Work around swiftlang/swift-driver#1822 for now
173173
perl -pi -g -we "s#(call rm ... \".\{LIBDISPATCH_BUILD_DIR\}\"\n(\s+)fi\n)#\1\2if [[ -d \"\\\${ANDROID_NDK}\" ]]; then call ln -sf \"\\\${SWIFT_BUILD_PATH}/lib/swift\" \"\\\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib\"; fi#" swift/utils/build-script-impl
174174

175-
# fix optional result value in backtrace() call
176-
perl -pi -e 's;.init\(clamping: addresses.count\)\)\);.init\(clamping: addresses.count\)\) ?? 0\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
177-
178175
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport); will be fixed post 6.2 (in which case only the above patch is needed)
179176
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
180177

181-
182-
# Disable posix_spawnattr_* calls for Android API 23
183-
perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_init;throw NSError\(domain: NSPOSIXErrorDomain, code: .init\(ENOEXEC\), userInfo: [ NSLocalizedFailureReasonErrorKey: "Process unavailable on Android" ]\) //try _throwIfPosixError\(posix_spawnattr_init;g' swift-corelibs-foundation/Sources/Foundation/Process.swift
184-
perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_setflags;//try _throwIfPosixError\(posix_spawnattr_setflags;g' swift-corelibs-foundation/Sources/Foundation/Process.swift
185-
perl -pi -e 's;posix_spawnattr_destroy;//posix_spawnattr_destroy;g' swift-corelibs-foundation/Sources/Foundation/Process.swift
186-
187-
# Stub out getgrgid_r and getgrnam_r missing from Android API 23
188-
perl -pi -e 's;getgrgid_r|getgrnam_r;{ _, _, _, _, _ in 0 };g' swift-foundation/Sources/FoundationEssentials/Platform.swift
189-
190178
popd >/dev/null 2>&1
191179
groupend
192180

0 commit comments

Comments
 (0)