Skip to content

Commit e1d7746

Browse files
committed
Update doc and config files to 5.9.2 SDK built with NDK 26b
1 parent e3848ef commit e1d7746

4 files changed

+44
-42
lines changed

README.md

+32-30
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,39 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
1010
The CI now builds with both the latest LTS NDK 26 and the last LTS NDK 25c. Now
1111
that Swift 5.9 supports [the new experimental SDK bundle
1212
format](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md),
13-
I plan to distribute an Android SDK bundle for NDK 26 sometime in January. In
14-
the meantime, you can get architecture-specific SDKs supporting either NDK from
15-
the `Artifacts` section of a recent passing CI run and try it out.
13+
I plan to distribute an Android SDK bundle for NDK 26 sometime this month.
14+
15+
If you cannot build against NDK 26 and the Swift 5.9.2 SDK because of the newly
16+
added nullability annotations, use the previous NDK 25c and Swift 5.9 SDK instead,
17+
until you can get your package updated (you can still use the Swift 5.9.2
18+
compiler with the older Swift 5.9 SDK).
1619

1720
## Cross-compiling and testing Swift packages with the Android SDK
1821

19-
To build with the Swift 5.9 SDK, first download [the last Android LTS NDK
20-
25c](https://github.com/android/ndk/wiki/Unsupported-Downloads) and [Swift 5.9.2
22+
To build with the Swift 5.9.2 SDK, first download [the latest Android LTS NDK
23+
26b](https://developer.android.com/ndk/downloads) and [Swift 5.9.2
2124
compiler](https://swift.org/download/#releases) (make sure to install the Swift
2225
compiler's dependencies listed there). Unpack these archives and the SDK.
2326

24-
Change the symbolic link at `swift-5.9-android-24-sdk/usr/lib/swift/clang`
27+
Change the symbolic link at `swift-5.9.2-android-24-sdk/usr/lib/swift/clang`
2528
to point to the clang headers that come with your swift compiler, eg
2629

2730
```
2831
ln -sf /home/yourname/swift-5.9.2-RELEASE-ubuntu22.04/usr/lib/clang/13.0.0
29-
swift-5.9-android-24-sdk/usr/lib/swift/clang
32+
swift-5.9.2-android-24-sdk/usr/lib/swift/clang
3033
```
3134

3235
Next, modify the cross-compilation JSON file `android-aarch64.json` in this repo
3336
similarly:
3437

35-
1. All paths to the NDK should change from `/home/finagolfin/android-ndk-r25c`
36-
to the path to your NDK, `/home/yourname/android-ndk-r25c`.
38+
1. All paths to the NDK should change from `/home/finagolfin/android-ndk-r26b`
39+
to the path to your NDK, `/home/yourname/android-ndk-r26b`.
3740

3841
2. The path to the compiler should change from `/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04`
3942
to the path to your Swift compiler, `/home/yourname/swift-5.9.2-RELEASE-ubi9`.
4043

41-
3. The paths to the Android SDK should change from `/home/finagolfin/swift-5.9-android-24-sdk`
42-
to the path where you unpacked the Android SDK, `/home/yourname/swift-5.9-android-24-sdk`.
44+
3. The paths to the Android SDK should change from `/home/finagolfin/swift-5.9.2-android-24-sdk`
45+
to the path where you unpacked the Android SDK, `/home/yourname/swift-5.9.2-android-24-sdk`.
4346

4447
Now you're ready to cross-compile a Swift package with the cross-compilation
4548
configuration JSON file, `android-aarch64.json`, and run its tests on Android.
@@ -51,7 +54,7 @@ cd swift-argument-parser/
5154
5255
/home/yourname/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/swift build --build-tests
5356
--destination ~/swift-android-sdk/android-aarch64.json
54-
-Xlinker -rpath -Xlinker \$ORIGIN/swift-5.9-android-24-sdk/usr/lib/aarch64-linux-android
57+
-Xlinker -rpath -Xlinker \$ORIGIN/swift-5.9.2-android-24-sdk/usr/lib/aarch64-linux-android
5558
```
5659
This will cross-compile the package for Android aarch64 and produce a test
5760
runner executable with the `.xctest` extension, in this case at
@@ -84,10 +87,10 @@ uname -m # check if you're running on the right architecture, should say `aarch6
8487
cd # move to the Termux app's home directory
8588
pkg install openssh
8689
87-
scp [email protected]:{swift-5.9-android-24-sdk.tar.xz,
90+
scp [email protected]:{swift-5.9.2-android-24-sdk.tar.xz,
8891
swift-argument-parserPackageTests.xctest,generate-manual,math,repeat,roll} .
8992
90-
tar xf swift-5.9-android-24-sdk.tar.xz
93+
tar xf swift-5.9.2-android-24-sdk.tar.xz
9194
9295
./swift-argument-parserPackageTests.xctest
9396
```
@@ -143,30 +146,29 @@ dependencies and include them yourself.
143146

144147
## Building the Android SDKs from source
145148

146-
Download the Swift 5.9.2 compiler and Android NDK 25c as above. Check out this
149+
Download the Swift 5.9.2 compiler and Android NDK 26b as above. Check out this
147150
repo and run
148151
`SWIFT_TAG=swift-5.9.2-RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift`
149152
to get some prebuilt Android libraries and the Swift source to build the SDK. If
150-
you pass in a different tag like `swift-DEVELOPMENT-SNAPSHOT-2023-12-15-a`
153+
you pass in a different tag like `swift-DEVELOPMENT-SNAPSHOT-2024-01-08-a`
151154
for the latest Swift trunk snapshot and pass in the path to the corresponding
152155
prebuilt Swift toolchain to `build-script` below, you can build a Swift trunk
153156
SDK too, as seen on the CI.
154157

155-
Next, add a header to the libdispatch source to work around a recent tightening
156-
in how C headers are imported, apple/swift#64321, and apply a patch to the Swift
157-
source, `swift-android.patch` from this repo, which adds a dependency for the
158-
Foundation core library in this Android SDK:
158+
Next, apply a patch to the Swift source, `swift-android.patch` from this repo,
159+
which adds a dependency for the Foundation core library in this Android SDK, and
160+
two more patches that make modifications for the nullability annotations newly
161+
added in NDK 26:
159162
```
160-
sed -i "s%#include <unistd%#include <signal.h>\n#include <unistd%" swift-corelibs-libdispatch/dispatch/dispatch.h
161-
git apply swift-android.patch
163+
git apply swift-android.patch swift-android-both-ndks.patch swift-android-ndk26.patch
162164
```
163165

164166
After making sure [needed build tools like python 3, CMake, and ninja](https://github.com/apple/swift/blob/release/5.9/docs/HowToGuides/GettingStarted.md#linux)
165167
are installed, run the following `build-script` command with your local paths
166168
substituted instead:
167169
```
168170
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android
169-
--android-ndk /home/finagolfin/android-ndk-r25c/ --android-arch aarch64 --android-api-level 24
171+
--android-ndk /home/finagolfin/android-ndk-r26b/ --android-arch aarch64 --android-api-level 24
170172
--build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
171173
--native-clang-tools-path=/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin/
172174
--host-cc=/usr/bin/clang-13 --host-cxx=/usr/bin/clang++-13
@@ -186,7 +188,7 @@ Finally, copy `libc++_shared.so` from the NDK and modify the cross-compiled
186188
`libdispatch.so` and Swift corelibs to include `$ORIGIN` and other relative
187189
directories in their rpaths:
188190
```
189-
cp /home/yourname/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
191+
cp /home/yourname/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
190192
patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN swift-release-android-aarch64-24-sdk/usr/lib/swift/android/lib*.so
191193
```
192194

@@ -199,7 +201,7 @@ API 24. Specifically, it downloads the libicu, libicu-static, libandroid-spawn,
199201
libcurl, and libxml2 packages from the [Termux package
200202
repository](https://packages.termux.dev/apt/termux-main/pool/main/).
201203

202-
Each one is unpacked with `ar x libicu_73.2_aarch64.deb; tar xf data.tar.xz` and
204+
Each one is unpacked with `ar x libicu_74.1_aarch64.deb; tar xf data.tar.xz` and
203205
the resulting files moved to a newly-created Swift release SDK directory:
204206
```
205207
mkdir swift-release-android-aarch64-24-sdk
@@ -214,14 +216,14 @@ rm swift-release-android-aarch64-24-sdk/usr/bin/*-config
214216
cd swift-release-android-aarch64-24-sdk/usr/lib
215217
216218
rm libicu{io,test,tu}*
217-
patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.73.2 libxml2.so
219+
patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.74.1 libxml2.so
218220
219221
# repeat the following for libicui18n.so and libicudata.so, as needed
220-
rm libicuuc.so libicuuc.so.73
221-
readelf -d libicuuc.so.73.2
222-
mv libicuuc.so.73.2 libicuuc.so
222+
rm libicuuc.so libicuuc.so.74
223+
readelf -d libicuuc.so.74.1
224+
mv libicuuc.so.74.1 libicuuc.so
223225
patchelf --set-soname libicuuc.so libicuuc.so
224-
patchelf --replace-needed libicudata.so.73 libicudata.so libicuuc.so
226+
patchelf --replace-needed libicudata.so.74 libicudata.so libicuuc.so
225227
```
226228
The libcurl and libxml2 packages are [only needed for the FoundationNetworking
227229
and FoundationXML libraries respectively](https://github.com/apple/swift-corelibs-foundation/blob/release/5.9/Docs/ReleaseNotes_Swift5.md),

android-aarch64.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"version": 1,
33
"target": "aarch64-unknown-linux-android24",
44
"toolchain-bin-dir": "/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin",
5-
"sdk": "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
5+
"sdk": "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
66
"extra-cc-flags": [
77
"-fPIC"
88
],
99
"extra-swiftc-flags": [
10-
"-resource-dir", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/swift",
11-
"-tools-directory", "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-L", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/aarch64-linux-android",
10+
"-resource-dir", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/swift",
11+
"-tools-directory", "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin",
12+
"-L", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/aarch64-linux-android",
1313
],
1414
"extra-cpp-flags": [
1515
"-lstdc++"

android-armv7.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"version": 1,
33
"target": "armv7-unknown-linux-androideabi24",
44
"toolchain-bin-dir": "/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin",
5-
"sdk": "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
5+
"sdk": "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
66
"extra-cc-flags": [
77
"-fPIC"
88
],
99
"extra-swiftc-flags": [
10-
"-resource-dir", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/swift",
11-
"-tools-directory", "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-L", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/arm-linux-androideabi",
10+
"-resource-dir", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/swift",
11+
"-tools-directory", "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin",
12+
"-L", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/arm-linux-androideabi",
1313
],
1414
"extra-cpp-flags": [
1515
"-lstdc++"

android-x86_64.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"version": 1,
33
"target": "x86_64-unknown-linux-android24",
44
"toolchain-bin-dir": "/home/finagolfin/swift-5.9.2-RELEASE-ubuntu22.04/usr/bin",
5-
"sdk": "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
5+
"sdk": "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
66
"extra-cc-flags": [
77
"-fPIC"
88
],
99
"extra-swiftc-flags": [
10-
"-resource-dir", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/swift",
11-
"-tools-directory", "/home/finagolfin/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-L", "/home/finagolfin/swift-5.9-android-24-sdk/usr/lib/x86_64-linux-android",
10+
"-resource-dir", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/swift",
11+
"-tools-directory", "/home/finagolfin/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin",
12+
"-L", "/home/finagolfin/swift-5.9.2-android-24-sdk/usr/lib/x86_64-linux-android",
1313
],
1414
"extra-cpp-flags": [
1515
"-lstdc++"

0 commit comments

Comments
 (0)