@@ -10,26 +10,25 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
10
10
The CI now builds with both the latest LTS NDK 26 and the last LTS NDK 25c. Now
11
11
that Swift 5.9 supports [ the new experimental SDK bundle
12
12
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 at some point .
13
+ I plan to distribute an Android SDK bundle for NDK 26 in the coming month .
14
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).
15
+ If you cannot build against NDK 26 because of the newly added nullability
16
+ annotations, you can download a 5.10 SDK built against 25c from a recent run of
17
+ the CI, eg ` sdk-tests-release-aarch64-ndk25c ` under ` Artifacts ` .
19
18
20
19
## Cross-compiling and testing Swift packages with the Android SDK
21
20
22
- To build with the Swift 5.9.2 SDK, first download [ the latest Android LTS NDK
23
- 26c] ( https://developer.android.com/ndk/downloads ) and [ Swift 5.9.2
21
+ To build with the Swift 5.10 SDK, first download [ the latest Android LTS NDK
22
+ 26c] ( https://developer.android.com/ndk/downloads ) and [ Swift 5.10
24
23
compiler] ( https://swift.org/download/#releases ) (make sure to install the Swift
25
24
compiler's dependencies linked there). Unpack these archives and the SDK.
26
25
27
- Change the symbolic link at ` swift-5.9.2 -android-24-sdk/usr/lib/swift/clang `
26
+ Change the symbolic link at ` swift-5.10 -android-24-sdk/usr/lib/swift/clang `
28
27
to point to the clang headers that come with your swift compiler, eg
29
28
30
29
```
31
- ln -sf /home/yourname/swift-5.9.2 -RELEASE-ubuntu22.04/usr/lib/clang/13 .0.0
32
- swift-5.9.2 -android-24-sdk/usr/lib/swift/clang
30
+ ln -sf /home/yourname/swift-5.10 -RELEASE-ubuntu22.04/usr/lib/clang/15 .0.0
31
+ swift-5.10 -android-24-sdk/usr/lib/swift/clang
33
32
```
34
33
35
34
Next, modify the cross-compilation JSON file ` android-aarch64.json ` in this repo
@@ -38,11 +37,11 @@ similarly:
38
37
1 . All paths to the NDK should change from ` /home/finagolfin/android-ndk-r26c `
39
38
to the path to your NDK, ` /home/yourname/android-ndk-r26c ` .
40
39
41
- 2 . The path to the compiler should change from ` /home/finagolfin/swift-5.9.2 -RELEASE-ubuntu22.04 `
42
- to the path to your Swift compiler, ` /home/yourname/swift-5.9.2 -RELEASE-ubi9 ` .
40
+ 2 . The path to the compiler should change from ` /home/finagolfin/swift-5.10 -RELEASE-ubuntu22.04 `
41
+ to the path to your Swift compiler, ` /home/yourname/swift-5.10 -RELEASE-ubi9 ` .
43
42
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 ` .
43
+ 3 . The paths to the Android SDK should change from ` /home/finagolfin/swift-5.10 -android-24-sdk `
44
+ to the path where you unpacked the Android SDK, ` /home/yourname/swift-5.10 -android-24-sdk ` .
46
45
47
46
Now you're ready to cross-compile a Swift package with the cross-compilation
48
47
configuration JSON file, ` android-aarch64.json ` , and run its tests on Android.
@@ -52,9 +51,9 @@ git clone --depth 1 https://github.com/apple/swift-argument-parser.git
52
51
53
52
cd swift-argument-parser/
54
53
55
- /home/yourname/swift-5.9.2 -RELEASE-ubuntu22.04/usr/bin/swift build --build-tests
54
+ /home/yourname/swift-5.10 -RELEASE-ubuntu22.04/usr/bin/swift build --build-tests
56
55
--destination ~/swift-android-sdk/android-aarch64.json
57
- -Xlinker -rpath -Xlinker \$ORIGIN/swift-5.9.2 -android-24-sdk/usr/lib/aarch64-linux-android
56
+ -Xlinker -rpath -Xlinker \$ORIGIN/swift-5.10 -android-24-sdk/usr/lib/aarch64-linux-android
58
57
```
59
58
This will cross-compile the package for Android aarch64 and produce a test
60
59
runner executable with the ` .xctest ` extension, in this case at
@@ -68,13 +67,13 @@ one depends on the example executables `generate-manual`, `math`, `repeat`, and
68
67
data in the repo: I've had success moving this data with the test runner, after
69
68
modifying the test source so it has the path to this test data in the Android
70
69
test environment. See the example of [ swift-crypto on the
71
- CI] ( https://github.com/finagolfin/swift-android-sdk/blob/5.9 /.github/workflows/sdks.yml#L293 ) .
70
+ CI] ( https://github.com/finagolfin/swift-android-sdk/blob/5.10 /.github/workflows/sdks.yml#L317 ) .
72
71
73
72
You can copy these executables and the SDK to [ an emulator or a USB
74
- debugging-enabled device with adb] ( https://github.com/apple/swift/blob/release/5.9 /docs/Android.md#3-deploying-the-build-products-to-the-device ) ,
73
+ debugging-enabled device with adb] ( https://github.com/apple/swift/blob/release/5.10 /docs/Android.md#3-deploying-the-build-products-to-the-device ) ,
75
74
or put them on an Android device with [ a terminal emulator app like Termux] ( https://termux.dev/en/ ) .
76
75
I test aarch64 with Termux so I'll show how to run the test runner there, but
77
- the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/5.9 /.github/workflows/sdks.yml#L328 ) .
76
+ the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/5.10 /.github/workflows/sdks.yml#L355 ) .
78
77
79
78
Copy the test executables to the same directory as the SDK:
80
79
```
@@ -87,10 +86,10 @@ uname -m # check if you're running on the right architecture, should say `aarch6
87
86
cd # move to the Termux app's home directory
88
87
pkg install openssh
89
88
90
- scp [email protected] :{swift-5.9.2 -android-24-sdk.tar.xz,
89
+ scp [email protected] :{swift-5.10 -android-24-sdk.tar.xz,
91
90
swift-argument-parserPackageTests.xctest,generate-manual,math,repeat,roll} .
92
91
93
- tar xf swift-5.9.2 -android-24-sdk.tar.xz
92
+ tar xf swift-5.10 -android-24-sdk.tar.xz
94
93
95
94
./swift-argument-parserPackageTests.xctest
96
95
```
@@ -146,11 +145,11 @@ dependencies and include them yourself.
146
145
147
146
## Building the Android SDKs from source
148
147
149
- Download the Swift 5.9.2 compiler and Android NDK 26c as above. Check out this
148
+ Download the Swift 5.10 compiler and Android NDK 26c as above. Check out this
150
149
repo and run
151
- ` SWIFT_TAG=swift-5.9.2 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
150
+ ` SWIFT_TAG=swift-5.10 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
152
151
to get some prebuilt Android libraries and the Swift source to build the SDK. If
153
- you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2024-03-20 -a `
152
+ you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2024-03-30 -a `
154
153
for the latest Swift trunk snapshot and pass in the path to the corresponding
155
154
prebuilt Swift toolchain to ` build-script ` below, you can build a Swift trunk
156
155
SDK too, as seen on the CI.
@@ -163,14 +162,14 @@ added in NDK 26:
163
162
git apply swift-android.patch swift-android-both-ndks.patch swift-android-foundation-ndk26.patch swift-android-stdlib-ndk26.patch swift-android-stdlib-except-trunk.patch
164
163
```
165
164
166
- 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 )
165
+ After making sure [ needed build tools like python 3, CMake, and ninja] ( https://github.com/apple/swift/blob/release/5.10 /docs/HowToGuides/GettingStarted.md#linux )
167
166
are installed, run the following ` build-script ` command with your local paths
168
167
substituted instead:
169
168
```
170
169
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android
171
170
--android-ndk /home/finagolfin/android-ndk-r26c/ --android-arch aarch64 --android-api-level 24
172
- --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-5.9.2 -RELEASE-ubuntu22.04/usr/bin/
173
- --native-clang-tools-path=/home/finagolfin/swift-5.9.2 -RELEASE-ubuntu22.04/usr/bin/
171
+ --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-5.10 -RELEASE-ubuntu22.04/usr/bin/
172
+ --native-clang-tools-path=/home/finagolfin/swift-5.10 -RELEASE-ubuntu22.04/usr/bin/
174
173
--host-cc=/usr/bin/clang-13 --host-cxx=/usr/bin/clang++-13
175
174
--cross-compile-hosts=android-aarch64 --cross-compile-deps-path=/home/finagolfin/swift-release-android-aarch64-24-sdk
176
175
--skip-local-build --xctest --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay'
@@ -201,7 +200,7 @@ API 24. Specifically, it downloads the libicu, libicu-static, libandroid-spawn,
201
200
libcurl, and libxml2 packages from the [ Termux package
202
201
repository] ( https://packages.termux.dev/apt/termux-main/pool/main/ ) .
203
202
204
- Each one is unpacked with ` ar x libicu_74.1_aarch64 .deb; tar xf data.tar.xz ` and
203
+ Each one is unpacked with ` ar x libicu_74.2_aarch64 .deb; tar xf data.tar.xz ` and
205
204
the resulting files moved to a newly-created Swift release SDK directory:
206
205
```
207
206
mkdir swift-release-android-aarch64-24-sdk
@@ -216,17 +215,17 @@ rm swift-release-android-aarch64-24-sdk/usr/bin/*-config
216
215
cd swift-release-android-aarch64-24-sdk/usr/lib
217
216
218
217
rm libicu{io,test,tu}*
219
- patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.74.1 libxml2.so
218
+ patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libicu*so.74.2 libxml2.so
220
219
221
220
# repeat the following for libicui18n.so and libicudata.so, as needed
222
221
rm libicuuc.so libicuuc.so.74
223
- readelf -d libicuuc.so.74.1
224
- mv libicuuc.so.74.1 libicuuc.so
222
+ readelf -d libicuuc.so.74.2
223
+ mv libicuuc.so.74.2 libicuuc.so
225
224
patchelf --set-soname libicuuc.so libicuuc.so
226
225
patchelf --replace-needed libicudata.so.74 libicudata.so libicuuc.so
227
226
```
228
227
The libcurl and libxml2 packages are [ only needed for the FoundationNetworking
229
- and FoundationXML libraries respectively] ( https://github.com/apple/swift-corelibs-foundation/blob/release/5.9 /Docs/ReleaseNotes_Swift5.md ) ,
228
+ and FoundationXML libraries respectively] ( https://github.com/apple/swift-corelibs-foundation/blob/release/5.10 /Docs/ReleaseNotes_Swift5.md ) ,
230
229
so you don't have to deploy them on the Android device if you don't use those
231
230
extra Foundation libraries. I simply include all four libraries since there's
232
231
currently no way to disable building them in the CMake configuration.
@@ -237,7 +236,7 @@ instead, so this Swift SDK for Android could be built without using
237
236
any prebuilt Termux packages, if you're willing to put in the effort to
238
237
cross-compile them yourself, for example, against a different Android API.
239
238
240
- Finally, it gets [ the 5.9.2 source] ( https://github.com/apple/swift/releases/tag/swift-5.9.2 -RELEASE )
239
+ Finally, it gets [ the 5.10 source] ( https://github.com/apple/swift/releases/tag/swift-5.10 -RELEASE )
241
240
tarballs for seven Swift repos and renames them to ` llvm-project/ ` , ` swift/ ` ,
242
241
` swift-syntax ` , ` swift-experimental-string-processing ` , ` swift-corelibs-libdispatch ` ,
243
242
` swift-corelibs-foundation ` , and ` swift-corelibs-xctest ` , as required by the Swift
0 commit comments