@@ -10,7 +10,7 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
10
10
## Cross-compiling and testing Swift packages with the Android SDK bundle
11
11
12
12
To build with the Swift 6 SDK bundle, first download [ the official open-source
13
- Swift 6.0.1 toolchain for linux or macOS] ( https://swift.org/download/#releases )
13
+ Swift 6.0.2 toolchain for linux or macOS] ( https://swift.org/download/#releases )
14
14
(make sure to install the Swift dependencies linked there). Install the OSS
15
15
toolchain on macOS as detailed in [ the instructions for using the static linux
16
16
Musl SDK bundle at swift.org] ( https://www.swift.org/documentation/articles/static-linux-getting-started.html ) .
@@ -19,27 +19,18 @@ On linux, simply download the toolchain, unpack it, and add it to your `PATH`.
19
19
Next, install the Android SDK bundle by having the Swift toolchain directly
20
20
download it:
21
21
```
22
- swift sdk install https://github.com/finagolfin/swift-android-sdk/releases/download/6.0.1 /swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz --checksum 28d019e91902681e04bf62b9535888441aa7c0cc96902940964013f29020d100
22
+ swift sdk install https://github.com/finagolfin/swift-android-sdk/releases/download/6.0.2 /swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle.tar.gz --checksum d75615eac3e614131133c7cc2076b0b8fb4327d89dce802c25cd53e75e1881f4
23
23
```
24
24
or alternately, download the SDK bundle with your favorite downloader and install
25
25
it separately:
26
26
```
27
- > wget https://github.com/finagolfin/swift-android-sdk/releases/download/6.0.1 /swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
28
- > sha256sum swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
29
- 28d019e91902681e04bf62b9535888441aa7c0cc96902940964013f29020d100 swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
30
- > swift sdk install swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
27
+ > wget https://github.com/finagolfin/swift-android-sdk/releases/download/6.0.2 /swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle.tar.gz
28
+ > sha256sum swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle.tar.gz
29
+ d75615eac3e614131133c7cc2076b0b8fb4327d89dce802c25cd53e75e1881f4 swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle.tar.gz
30
+ > swift sdk install swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle.tar.gz
31
31
```
32
32
You can check if it was properly installed by running ` swift sdk list ` .
33
33
34
- You will have to modify SwiftPM 6.0.1 on linux and macOS for a recent regression
35
- when cross-compiling a package's tests for Android:
36
- ```
37
- perl -pi -e 's%canImport\(Bionic%canImport\(Android%' swift-6.0.1-RELEASE-ubuntu22.04/usr/bin/swift-package
38
- perl -pi -e 's%import Bionic%import Android%' swift-6.0.1-RELEASE-ubuntu22.04/usr/bin/swift-package
39
- perl -pi -e 's%TSCBasic, would be%TSCBasic, would %' swift-6.0.1-RELEASE-ubuntu22.04/usr/bin/swift-package
40
- ```
41
- This is fixed in the upcoming 6.0.2 patch release.
42
-
43
34
Now you're ready to cross-compile a Swift package and run its tests on Android.
44
35
I'll demonstrate with the swift-argument-parser package:
45
36
```
@@ -59,19 +50,19 @@ one depends on the example executables `color`, `generate-manual`, `math`,
59
50
point at test data in the repo: I've had success moving this data with the test
60
51
runner, after modifying the test source so it has the path to this test data in
61
52
the Android test environment. See the example of [ swift-crypto on the
62
- CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.1 /.github/workflows/sdks.yml#L492 ) .
53
+ CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.2 /.github/workflows/sdks.yml#L505 ) .
63
54
64
55
You can copy these executables and the Swift runtime libraries to [ an emulator
65
56
or a USB debugging-enabled device with adb] ( https://github.com/swiftlang/swift/blob/release/6.0/docs/Android.md#3-deploying-the-build-products-to-the-device ) ,
66
57
or put them on an Android device with [ a terminal emulator app like Termux] ( https://termux.dev/en/ ) .
67
58
I test aarch64 with Termux so I'll show how to run the test runner there, but
68
- the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.1 /.github/workflows/sdks.yml#L440 ) .
59
+ the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.2 /.github/workflows/sdks.yml#L453 ) .
69
60
70
61
Copy the test executables to the same directory as the Swift 6 runtime libraries,
71
62
removing a few Android stub libraries that aren't needed:
72
63
```
73
64
cp .build/aarch64-unknown-linux-android24/debug/{swift-argument-parserPackageTests.xctest,color,generate-manual,math,repeat,roll} ..
74
- cp ~/.swiftpm/swift-sdks/swift-6.0.1 -RELEASE-android-24-0.1.artifactbundle/swift-6.0.1 -release-android-24-sdk/android-27b -sysroot/usr/lib/aarch64-linux-android/24/lib*.so ..
65
+ cp ~/.swiftpm/swift-sdks/swift-6.0.2 -RELEASE-android-24-0.1.artifactbundle/swift-6.0.2 -release-android-24-sdk/android-27c -sysroot/usr/lib/aarch64-linux-android/24/lib*.so ..
75
66
rm ../lib{c,dl,log,m,z}.so
76
67
```
77
68
You can copy the test executables and Swift 6 runtime libraries to Termux using
@@ -81,7 +72,8 @@ uname -m # check if you're running on the right architecture, should say `aarch6
81
72
cd # move to the Termux app's home directory
82
73
pkg install openssh
83
74
84
- scp [email protected] :{lib*.so,swift-argument-parserPackageTests.xctest,color,generate-manual,math,repeat,roll} .
75
+
76
+ scp [email protected] :{swift-argument-parserPackageTests.xctest,color,generate-manual,math,repeat,roll} .
85
77
86
78
./swift-argument-parserPackageTests.xctest
87
79
```
@@ -131,9 +123,9 @@ packagingOptions {
131
123
132
124
## Building an Android SDK from source
133
125
134
- Download the Swift 6.0.1 compiler as above and Android NDK 27b (only building
126
+ Download the Swift 6.0.2 compiler as above and Android NDK 27c (only building
135
127
the Android SDKs on linux works for now). Check out this repo and run
136
- ` SWIFT_TAG=swift-6.0.1 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
128
+ ` SWIFT_TAG=swift-6.0.2 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
137
129
to get some prebuilt Android libraries and the Swift source to build an AArch64
138
130
SDK. If you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2024-10-08-a `
139
131
for the latest Swift trunk snapshot and pass in the path to the corresponding
@@ -154,9 +146,9 @@ are installed, run the following `build-script` command with your local paths
154
146
substituted instead:
155
147
```
156
148
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android
157
- --android-ndk /home/finagolfin/android-ndk-r27b / --android-arch aarch64 --android-api-level 24
158
- --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-6.0.1 -RELEASE-ubuntu22.04/usr/bin/
159
- --native-clang-tools-path=/home/finagolfin/swift-6.0.1 -RELEASE-ubuntu22.04/usr/bin/
149
+ --android-ndk /home/finagolfin/android-ndk-r27c / --android-arch aarch64 --android-api-level 24
150
+ --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-6.0.2 -RELEASE-ubuntu22.04/usr/bin/
151
+ --native-clang-tools-path=/home/finagolfin/swift-6.0.2 -RELEASE-ubuntu22.04/usr/bin/
160
152
--host-cc=/usr/bin/clang-13 --host-cxx=/usr/bin/clang++-13
161
153
--cross-compile-hosts=android-aarch64 --cross-compile-deps-path=/home/finagolfin/swift-release-android-aarch64-24-sdk
162
154
--skip-local-build --xctest --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay'
@@ -173,7 +165,7 @@ into these commands to build SDKs for those architectures instead.
173
165
Finally, copy ` libc++_shared.so ` from the NDK and modify the cross-compiled
174
166
Swift corelibs to include ` $ORIGIN ` and other relative directories in their rpaths:
175
167
```
176
- cp /home/yourname/android-ndk-r27b /toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
168
+ cp /home/yourname/android-ndk-r27c /toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so swift-release-android-aarch64-24-sdk/usr/lib
177
169
patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN swift-release-android-aarch64-24-sdk/usr/lib/swift/android/lib*.so
178
170
```
179
171
@@ -219,7 +211,7 @@ packages, by compiling against a more recent Android API that doesn't need the
219
211
` libandroid-spawn ` backport, and by cross-compiling libcurl/libxml2 and their
220
212
dependencies yourself or not using FoundationNetworking and FoundationXML.
221
213
222
- Finally, it gets [ the 6.0.1 source] ( https://github.com/swiftlang/swift/releases/tag/swift-6.0.1 -RELEASE )
214
+ Finally, it gets [ the 6.0.2 source] ( https://github.com/swiftlang/swift/releases/tag/swift-6.0.2 -RELEASE )
223
215
tarballs for ten Swift repos and renames them to ` llvm-project/ ` , ` swift/ ` ,
224
216
` swift-syntax ` , ` swift-experimental-string-processing ` , ` swift-corelibs-libdispatch ` ,
225
217
` swift-corelibs-foundation ` , ` swift-collections ` , ` swift-foundation ` ,
0 commit comments