Skip to content

Commit 40733f7

Browse files
authored
Swift Android build 6.2 (#2)
* Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Start splitting NDK out from the rest of the SDK * Start splitting NDK out from the rest of the SDK * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2
1 parent 412e6b0 commit 40733f7

File tree

3 files changed

+123
-60
lines changed

3 files changed

+123
-60
lines changed

.github/workflows/pull_request.yml

+23-27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ env:
88
jobs:
99
build:
1010
name: Build Docker images
11+
# disabled for CI testing
12+
if: false
1113
runs-on: ubuntu-latest
1214
steps:
1315
- name: Checkout repository
@@ -24,6 +26,8 @@ jobs:
2426
2527
static-linux-build:
2628
name: Build Static Linux image
29+
# disabled for CI testing
30+
if: false
2731
runs-on: ubuntu-latest
2832
steps:
2933
- name: Checkout repository
@@ -33,7 +37,7 @@ jobs:
3337
run: ./build
3438

3539
android-build:
36-
name: Build Android ${{ matrix.arch }} SDK
40+
name: Build Android ${{ matrix.swift-version }} ${{ matrix.arch }} SDK
3741
strategy:
3842
fail-fast: false
3943
matrix:
@@ -43,8 +47,18 @@ jobs:
4347
#arch: ['x86_64']
4448
# build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs
4549
arch: ['x86_64', '']
50+
swift-version: ['release', 'devel', 'trunk']
4651
runs-on: ubuntu-24.04
4752
steps:
53+
- name: Free Disk Space
54+
run: |
55+
df -h
56+
# brings available space from 25G to 32G
57+
# otherwise we sometimes run out of space during the build
58+
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/CodeQL
59+
sudo docker image prune --all --force
60+
sudo docker builder prune -a
61+
df -h
4862
- name: Checkout repository
4963
uses: actions/checkout@v4
5064
- name: Install Dependencies
@@ -53,7 +67,7 @@ jobs:
5367
- name: Build Android SDK
5468
working-directory: swift-ci/sdks/android
5569
run: |
56-
TARGET_ARCHS=${{ matrix.arch }} ./build
70+
BUILD_VERSION=${{ matrix.swift-version }} TARGET_ARCHS=${{ matrix.arch }} ./build
5771
- name: Get artifact info
5872
id: info
5973
shell: bash
@@ -82,28 +96,8 @@ jobs:
8296
# swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip
8397
echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
8498
85-
# validate some required paths in the artifactbundle
86-
pushd ${ARTIFACT_BUILD}/*/*/usr
87-
ls lib/swift/android
88-
ls lib/swift/android/*
89-
ls lib/swift/android/*/swiftrt.o
90-
ls lib/*-linux-android/*/crtbegin_dynamic.o
91-
92-
ls lib/swift_static-*
93-
ls lib/swift_static-*/android
94-
ls lib/swift_static-*/android/libFoundationEssentials.a
95-
96-
ls lib/*-linux-android/libFoundationEssentials.so
97-
ls lib/*-linux-android/libFoundationNetworking.so
98-
ls lib/*-linux-android/libFoundationInternationalization.so
99-
ls lib/*-linux-android/lib_FoundationICU.so
100-
ls lib/*-linux-android/libFoundationXML.so
101-
ls lib/*-linux-android/libTesting.so
102-
103-
ls lib/swift/clang/lib
104-
ls lib/swift/clang/lib/linux
105-
ls lib/swift/clang/lib/linux/*/libunwind.a
106-
popd
99+
# show an abridged tree
100+
tree ${ARTIFACT_BUILD} --filesfirst --prune -P 'Android.swiftmodule' -P 'libswiftAndroid.*' -P 'libFoundation.*' -P 'swiftrt.o' -P 'swift*.json' -P 'info.json' -P 'api-level.h' -P 'android.modulemap' -P 'SwiftAndroidNDK.h' -P 'bridging.modulemap' -P 'linux' -P 'libclang*.a' -P 'libunwind.a' -P 'libclang_rt.builtins-*-android.a'
107101
- name: Upload SDK artifactbundle
108102
uses: actions/upload-artifact@v4
109103
with:
@@ -113,7 +107,9 @@ jobs:
113107
- name: Cleanup
114108
run: |
115109
# need to free up some space or else when installing we get: No space left on device
110+
df -h
116111
rm -rf ${{ runner.temp }}/swift-android-sdk/{build,src}
112+
df -h
117113
- name: Install artifactbundle
118114
shell: bash
119115
run: |
@@ -138,10 +134,10 @@ jobs:
138134
echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift
139135
echo 'import Android' >> Sources/DemoProject/DemoProject.swift
140136
- name: Test Demo Project on Android
141-
uses: skiptools/swift-android-action@v2
137+
uses: skiptools/swift-android-action@main
142138
with:
143139
# only test for the complete arch SDK build to speed up CI
144-
run-tests: ${{ matrix.arch == '' }}
140+
#run-tests: ${{ matrix.arch == '' }}
145141
package-path: ${{ runner.temp }}/DemoProject
146142
installed-sdk: ${{ steps.info.outputs.sdk-id }}
147143
installed-swift: ${{ steps.info.outputs.swift-root }}
@@ -152,7 +148,7 @@ jobs:
152148
repository: apple/swift-algorithms
153149
path: swift-algorithms
154150
- name: Test swift-algorithms
155-
uses: skiptools/swift-android-action@v2
151+
uses: skiptools/swift-android-action@main
156152
with:
157153
run-tests: ${{ matrix.arch == '' }}
158154
package-path: swift-algorithms

swift-ci/sdks/android/build

+25-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ mkdir -p ${SDKROOT}
1313
# Install a Swift host toolchain if it isn't already present
1414
SWIFT_ROOT=${SDKROOT}/host-toolchain
1515
HOST_OS=ubuntu$(lsb_release -sr)
16-
SWIFT_VERSION=6.1
17-
SWIFT_TAG="swift-${SWIFT_VERSION}-RELEASE"
18-
SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-release"
16+
17+
#BUILD_VERSION='release'
18+
#BUILD_VERSION='trunk'
19+
BUILD_VERSION=${BUILD_VERSION:-'devel'}
20+
21+
if [ "${BUILD_VERSION}" = 'release' ]; then
22+
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-6.1 | cut -d- -f2)
23+
SWIFT_TAG="swift-${LATEST_TOOLCHAIN_VERSION}-RELEASE"
24+
SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-release"
25+
elif [ "${BUILD_VERSION}" = 'devel' ]; then
26+
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/tags | grep -m1 swift-6.2-DEV | cut -d- -f8-10)
27+
SWIFT_TAG="swift-6.2-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
28+
SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-branch"
29+
else
30+
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/tags | grep -m1 swift-DEV | cut -d- -f7-9)
31+
SWIFT_TAG="swift-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
32+
SWIFT_BRANCH="development"
33+
fi
34+
1935
SWIFT_BASE=$SWIFT_TAG-$HOST_OS
2036

21-
if [[ ! -d $SWIFT_ROOT ]]; then
37+
if [[ ! -d "$SWIFT_ROOT/$SWIFT_BASE" ]]; then
2238
mkdir -p $SWIFT_ROOT
2339
pushd $SWIFT_ROOT
2440

@@ -75,7 +91,11 @@ if [[ ! -d ${PATCHDIR} ]]; then
7591
# swift-android-ci.patch is not needed, since it is only used for llbuild, etc.
7692
#git apply -C1 $PATCHDIR/swift-android-ci.patch
7793
#git apply -v $PATCHDIR/swift-android-ci-release.patch
78-
git apply -v $PATCHDIR/swift-android-testing-release.patch
94+
if [ "${BUILD_VERSION}" = 'release' ]; then
95+
git apply -v $PATCHDIR/swift-android-testing-release.patch
96+
else
97+
git apply -v $PATCHDIR/swift-android-testing-except-release.patch
98+
fi
7999

80100
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
81101
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)

swift-ci/sdks/android/scripts/build.sh

+75-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
# Swift SDK for Android: Build Script
3-
set -e
3+
set -ex
4+
5+
# temporary for splitting out NDK installation from the rest of the SDK
6+
#NDK_LOCATION=${NDK_LOCATION:-"merged"}
7+
NDK_LOCATION=${NDK_LOCATION:-"external"}
48

59
# Docker sets TERM to xterm if using a pty; we probably want
610
# xterm-256color, otherwise we only get eight colors
@@ -188,7 +192,7 @@ if [[ $swift_version == swift-* ]]; then
188192
fi
189193

190194
if [[ -z "$sdk_name" ]]; then
191-
sdk_name=swift-${swift_version}_android-${android_sdk_version}
195+
sdk_name=swift-${swift_version}-android-${android_sdk_version}
192196
fi
193197

194198
libxml2_version=$(versionFromTag ${source_dir}/libxml2)
@@ -212,14 +216,13 @@ header "Swift Android SDK build script"
212216
swift_dir=$(realpath $(dirname "$swiftc")/..)
213217
HOST=linux-x86_64
214218
#HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
215-
ndk_toolchain=$ndk_home/toolchains/llvm/prebuilt/$HOST
216-
219+
ndk_installation=$ndk_home/toolchains/llvm/prebuilt/$HOST
217220

218221
echo "Swift found at ${swift_dir}"
219222
echo "Host toolchain found at ${host_toolchain}"
220223
${host_toolchain}/bin/swift --version
221224
echo "Android NDK found at ${ndk_home}"
222-
${ndk_toolchain}/bin/clang --version
225+
${ndk_installation}/bin/clang --version
223226
echo "Building for ${archs}"
224227
echo "Sources are in ${source_dir}"
225228
echo "Build will happen in ${build_dir}"
@@ -387,7 +390,7 @@ for arch in $archs; do
387390
# need to remove symlink that gets created in the NDK to the previous arch's build
388391
# or else we get errors like:
389392
# error: could not find module '_Builtin_float' for target 'x86_64-unknown-linux-android'; found: aarch64-unknown-linux-android, at: /home/runner/work/_temp/swift-android-sdk/ndk/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/swift/android/_Builtin_float.swiftmodule
390-
rm -f $ndk_toolchain/sysroot/usr/lib/swift
393+
rm -f $ndk_installation/sysroot/usr/lib/swift
391394
quiet_popd
392395
groupend
393396
done
@@ -425,12 +428,22 @@ EOF
425428
mkdir -p $sdk_base
426429
quiet_pushd $sdk_base
427430

428-
#sysroot_path="ndk-sysroot"
429-
#sysroot_path="android-27c-sysroot"
430-
sysroot_path="sysroot"
431-
cp -a ${ndk_toolchain}/sysroot ${sysroot_path}
431+
cp -a ${build_dir}/sdk_root ${sdk_staging}
432+
433+
if [ "${NDK_LOCATION}" = "external" ]; then
434+
swift_res_root="swift-resources"
435+
ndk_sysroot="ndk-sysroot"
436+
cp -a ${ndk_installation}/sysroot ${ndk_sysroot}
437+
else
438+
merged_sysroot_path="sysroot"
439+
swift_res_root=${merged_sysroot_path}
440+
ndk_sysroot=${merged_sysroot_path}
441+
cp -a ${ndk_installation}/sysroot ${ndk_sysroot}
442+
fi
432443

433-
cat > $sysroot_path/SDKSettings.json <<EOF
444+
mkdir -p ${swift_res_root}
445+
446+
cat > $swift_res_root/SDKSettings.json <<EOF
434447
{
435448
"DisplayName": "Swift Android SDK",
436449
"Version": "${android_sdk_version}",
@@ -439,10 +452,10 @@ cat > $sysroot_path/SDKSettings.json <<EOF
439452
}
440453
EOF
441454

442-
cp -a ${build_dir}/sdk_root ${sdk_staging}
443455
# Copy necessary headers and libraries from the toolchain and NDK clang resource directories
444-
mkdir -p $sysroot_path/usr/lib/swift/clang/lib
445-
cp -r $host_toolchain/lib/clang/*/include $sysroot_path/usr/lib/swift/clang
456+
mkdir -p $swift_res_root/usr/lib/swift/clang/lib
457+
cp -r $host_toolchain/lib/clang/*/include $swift_res_root/usr/lib/swift/clang
458+
446459

447460
for arch in $archs; do
448461
quiet_pushd ${sdk_staging}/${arch}/usr
@@ -455,26 +468,50 @@ for arch in $archs; do
455468
arch_triple="arm-linux-androideabi"
456469
fi
457470

458-
mkdir lib/${arch_triple}
459-
mv lib/pkgconfig lib/swift/android/lib*.{a,so} lib/${arch_triple}
471+
rm -r lib/swift{,_static}/clang
472+
if [ "${NDK_LOCATION}" = "external" ]; then
473+
#mkdir lib/swift-$arch
474+
#mv lib/pkgconfig lib/swift/android/lib*.{a,so} lib/swift-$arch
475+
mv lib/swift lib/swift-$arch
476+
ln -s ../swift/clang lib/swift-$arch/clang
477+
else
478+
mkdir lib/${arch_triple}
479+
mv lib/pkgconfig lib/swift/android/lib*.{a,so} lib/${arch_triple}
480+
fi
460481

461482
mv lib/swift_static lib/swift_static-$arch
462483
mv lib/lib*.a lib/swift_static-$arch/android
463484

464-
rm -r lib/swift{,_static-$arch}/clang
485+
ln -sv ../swift/clang lib/swift_static-$arch/clang
465486

466-
mkdir -p lib/swift/clang/lib
467-
cp -a ${ndk_toolchain}/lib/clang/*/lib/linux lib/swift/clang/lib
468-
ln -s ../swift/clang lib/swift_static-$arch/clang
487+
# copy the clang libraries that we need to build for each architecture
488+
aarch=${arch/armv7/arm}
489+
mkdir -p lib/swift/clang/lib/linux/${aarch}
490+
491+
# match clang version 21, 22, etc.
492+
cp -av ${ndk_installation}/lib/clang/[0-9]*/lib/linux/libclang_rt.builtins-${aarch}-android.a lib/swift/clang/lib/linux/
493+
cp -av ${ndk_installation}/lib/clang/[0-9]*/lib/linux/${aarch}/libunwind.a lib/swift/clang/lib/linux/${aarch}/
469494
quiet_popd
470495

471-
# now sync the massaged sdk_root into the sysroot_path
472-
rsync -a ${sdk_staging}/${arch}/usr ${sysroot_path}
496+
# now sync the massaged sdk_root into the swift_res_root
497+
rsync -a ${sdk_staging}/${arch}/usr ${swift_res_root}
473498
done
474499

475-
rm -r ${sysroot_path}/usr/share/{doc,man}
476-
rm -r ${sysroot_path}/usr/{include,lib}/{i686,riscv64}-linux-android
477-
rm -r ${sysroot_path}/usr/lib/swift/clang/lib/linux/*{i[36]86,riscv64}*
500+
if [ "${NDK_LOCATION}" = "external" ]; then
501+
# need to manually copy over swiftrt.o or else:
502+
# error: link command failed with exit code 1 (use -v to see invocation)
503+
# clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a-android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o'
504+
# see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807
505+
for arch in $archs; do
506+
mkdir -p ${ndk_sysroot}/usr/lib/swift/android/${arch}
507+
ln -srv ${swift_res_root}/usr/lib/swift-${arch}/android/${arch}/swiftrt.o ${ndk_sysroot}/usr/lib/swift/android/${arch}/swiftrt.o
508+
done
509+
else
510+
rm -r ${swift_res_root}/usr/{include,lib}/{i686,riscv64}-linux-android
511+
rm -r ${swift_res_root}/usr/lib/swift/clang/lib/linux/*{i[36]86,riscv64}*
512+
fi
513+
514+
rm -r ${swift_res_root}/usr/share/{doc,man}
478515
rm -r ${sdk_staging}
479516

480517
cat > swift-sdk.json <<EOF
@@ -497,13 +534,23 @@ for api in $(eval echo "{$android_api..36}"); do
497534
},
498535
EOF
499536
fi
537+
538+
if [ "${NDK_LOCATION}" = "external" ]; then
539+
SWIFT_RES_DIR="swift-${arch}"
540+
else
541+
SWIFT_RES_DIR="swift"
542+
fi
543+
SWIFT_STATIC_RES_DIR="swift_static-${arch}"
544+
500545
cat >> swift-sdk.json <<EOF
501546
"${arch}-unknown-linux-android${api}": {
502-
"sdkRootPath": "${sysroot_path}",
503-
"swiftResourcesPath": "${sysroot_path}/usr/lib/swift",
504-
"swiftStaticResourcesPath": "${sysroot_path}/usr/lib/swift_static-${arch}",
547+
"sdkRootPath": "${ndk_sysroot}",
548+
"swiftResourcesPath": "${swift_res_root}/usr/lib/${SWIFT_RES_DIR}",
549+
"swiftStaticResourcesPath": "${swift_res_root}/usr/lib/${SWIFT_STATIC_RES_DIR}",
505550
"toolsetPaths": [ "swift-toolset.json" ]
506551
EOF
552+
#"librarySearchPaths": [ "${swift_res_root}/usr/lib/swift-x86_64/android/x86_64" ],
553+
#"includeSearchPaths": [ "${ndk_sysroot}/usr/include" ],
507554
done
508555
done
509556

0 commit comments

Comments
 (0)