@@ -9,8 +9,8 @@ emulator](https://github.com/finagolfin/swift-android-sdk/blob/main/.github/work
9
9
10
10
## Cross-compiling and testing Swift packages with the Android SDK bundle
11
11
12
- To build with the Swift 6 SDK bundle, first download [ the official open-source
13
- Swift 6.0.3 toolchain for linux or macOS] ( https://swift.org/install )
12
+ To build with the Swift 6.1 SDK bundle, first download [ the official open-source
13
+ Swift 6.1 toolchain for linux or macOS] ( https://swift.org/install )
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,15 +19,15 @@ 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.3 /swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle.tar.gz --checksum 4566f23ae2d36dc5c02e915cd67d83b2af971faca4b2595fdd75cf0286acfac1
22
+ swift sdk install https://github.com/finagolfin/swift-android-sdk/releases/download/6.1 /swift-6.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz --checksum 971f3b1fd03c059803d625f0a412d7e8c4c6f34440f5216ceaf13e886e8e706f
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.3 /swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle.tar.gz
28
- > sha256sum swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle.tar.gz
29
- 4566f23ae2d36dc5c02e915cd67d83b2af971faca4b2595fdd75cf0286acfac1 swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle.tar.gz
30
- > swift sdk install swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle.tar.gz
27
+ > wget https://github.com/finagolfin/swift-android-sdk/releases/download/6.1 /swift-6.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
28
+ > sha256sum swift-6.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
29
+ 971f3b1fd03c059803d625f0a412d7e8c4c6f34440f5216ceaf13e886e8e706f swift-6.1 -RELEASE-android-24-0.1.artifactbundle.tar.gz
30
+ > swift sdk install swift-6.1 -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
@@ -56,20 +56,20 @@ one depends on the example executables `color`, `generate-manual`, `math`,
56
56
point at test data in the repo: I've had success moving this data with the test
57
57
runner, after modifying the test source so it has the path to this test data in
58
58
the Android test environment. See the example of [ swift-crypto on the
59
- CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.3 /.github/workflows/sdks.yml#L506 ) .
59
+ CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.1 /.github/workflows/sdks.yml#L516 ) .
60
60
61
61
You can copy these executables and the Swift runtime libraries to [ an emulator
62
- 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 ) ,
62
+ or a USB debugging-enabled device with adb] ( https://github.com/swiftlang/swift/blob/release/6.1 /docs/Android.md#3-deploying-the-build-products-to-the-device ) ,
63
63
or put them on an Android device with [ a terminal emulator app like Termux] ( https://termux.dev/en/ ) .
64
64
I test aarch64 with Termux so I'll show how to run the test runner there, but
65
- the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.0.3 /.github/workflows/sdks.yml#L454 ) .
65
+ the process is similar with adb, [ as can be seen on the CI] ( https://github.com/finagolfin/swift-android-sdk/blob/6.1 /.github/workflows/sdks.yml#L462 ) .
66
66
67
- Copy the test executables to the same directory as the Swift 6 runtime libraries:
67
+ Copy the test executables to the same directory as the Swift 6.1 runtime libraries:
68
68
```
69
69
cp .build/aarch64-unknown-linux-android24/debug/{swift-argument-parserPackageTests.xctest,color,generate-manual,math,repeat,roll} ..
70
- cp ~/.swiftpm/swift-sdks/swift-6.0.3 -RELEASE-android-24-0.1.artifactbundle/swift-6.0.3 -release-android-24-sdk/android-27c-sysroot/usr/lib/aarch64-linux-android/lib*.so ..
70
+ cp ~/.swiftpm/swift-sdks/swift-6.1 -RELEASE-android-24-0.1.artifactbundle/swift-6.1 -release-android-24-sdk/android-27c-sysroot/usr/lib/aarch64-linux-android/lib*.so ..
71
71
```
72
- You can copy the test executables and Swift 6 runtime libraries to Termux using
72
+ You can copy the test executables and Swift 6.1 runtime libraries to Termux using
73
73
scp from OpenSSH, run these commands in Termux on the Android device:
74
74
```
75
75
uname -m # check if you're running on the right architecture, should say `aarch64`
@@ -83,9 +83,8 @@ scp
[email protected] :{swift-argument-parserPackageTests.xctest,color,generat
83
83
```
84
84
I've tried several Swift packages, including some mostly written in C or C++,
85
85
and all the cross-compiled tests passed. Note that while this SDK bundle is
86
- compiled against Android API 24, there was a regression in Swift 6 so that
87
- Foundation can only be run on Android API 29 or later, finagolfin/swift-android-sdk #175 .
88
- I will update the SDK bundle when I find a fix for that new issue.
86
+ compiled against Android API 24, you can also specify an arbitrary later API to
87
+ compile against, eg ` --swift-sdk aarch64-unknown-linux-android29 ` .
89
88
90
89
You can even run armv7 tests on an aarch64 device, though Termux may require
91
90
running ` unset LD_PRELOAD ` before invoking an armv7 test runner on aarch64.
@@ -108,7 +107,7 @@ refer to any FILE pointers like this](https://github.com/swiftlang/swift-tools-s
108
107
#if canImport(Android)
109
108
typealias FILEPointer = OpaquePointer
110
109
```
111
- Those changes are all I had to do [ to port swift-argument-parser to
110
+ Those changes are all I had to make [ to port swift-argument-parser to
112
111
Android] ( https://github.com/apple/swift-argument-parser/pull/651/files ) .
113
112
114
113
## Building an Android app with Swift
@@ -127,32 +126,32 @@ packagingOptions {
127
126
128
127
## Building an Android SDK from source
129
128
130
- Download the Swift 6.0.3 compiler as above and Android NDK 27c (only building
129
+ Download the Swift 6.1 compiler as above and Android NDK 27c (only building
131
130
the Android SDKs on linux works for now). Check out this repo and run
132
- ` SWIFT_TAG=swift-6.0.3 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
131
+ ` SWIFT_TAG=swift-6.1 -RELEASE ANDROID_ARCH=aarch64 swift get-packages-and-swift-source.swift `
133
132
to get some prebuilt Android libraries and the Swift source to build an AArch64
134
- SDK. If you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2025-01-05 -a `
133
+ SDK. If you pass in a different tag like ` swift-DEVELOPMENT-SNAPSHOT-2025-04-03 -a `
135
134
for the latest Swift trunk snapshot and pass in the path to the corresponding
136
135
prebuilt Swift toolchain to ` build-script ` below, you can build a Swift trunk
137
136
SDK too, as seen on the CI.
138
137
139
138
Next, apply two patches from this repo to the Swift source, which make
140
139
modifications for NDK 27 and [ the Foundation rewrite in Swift 6 that was merged
141
- this summer] ( https://www.swift.org/blog/foundation-preview-now-available/ ) , and
140
+ last summer] ( https://www.swift.org/blog/foundation-preview-now-available/ ) , and
142
141
substitute a string for NDK 27:
143
142
```
144
- git apply swift-android.patch swift-android-foundation -release.patch
143
+ git apply swift-android.patch swift-android-testing -release.patch
145
144
perl -pi -e 's%r26%r27%' swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
146
145
```
147
146
148
- After making sure [ needed build tools like python 3, CMake, and ninja] ( https://github.com/swiftlang/swift/blob/release/6.0 /docs/HowToGuides/GettingStarted.md#linux )
147
+ After making sure [ needed build tools like python 3, CMake, and ninja] ( https://github.com/swiftlang/swift/blob/release/6.1 /docs/HowToGuides/GettingStarted.md#linux )
149
148
are installed, run the following ` build-script ` command with your local paths
150
149
substituted instead:
151
150
```
152
151
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android
153
152
--android-ndk /home/finagolfin/android-ndk-r27c/ --android-arch aarch64 --android-api-level 24
154
- --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-6.0.3 -RELEASE-ubuntu22.04/usr/bin/
155
- --native-clang-tools-path=/home/finagolfin/swift-6.0.3 -RELEASE-ubuntu22.04/usr/bin/
153
+ --build-swift-tools=0 --native-swift-tools-path=/home/finagolfin/swift-6.1 -RELEASE-ubuntu22.04/usr/bin/
154
+ --native-clang-tools-path=/home/finagolfin/swift-6.1 -RELEASE-ubuntu22.04/usr/bin/
156
155
--host-cc=/usr/bin/clang-13 --host-cxx=/usr/bin/clang++-13
157
156
--cross-compile-hosts=android-aarch64 --cross-compile-deps-path=/home/finagolfin/swift-release-android-aarch64-24-sdk
158
157
--skip-local-build --xctest --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay'
@@ -178,11 +177,11 @@ Here is a description of what the above Swift script is doing:
178
177
This prebuilt SDK was compiled against Android API 24, because the Swift
179
178
Foundation libraries require some libraries like libcurl, that are pulled from the
180
179
prebuilt library packages used by the Termux app, which are built against Android
181
- API 24. Specifically, it downloads the libandroid-spawn, libcurl, and libxml2
182
- packages and their handful of dependencies from the [ Termux package
183
- repository] ( https://packages.termux.dev/apt/termux-main/pool/main/ ) .
180
+ API 24. Specifically, it downloads the libandroid-execinfo, libandroid-spawn,
181
+ libcurl, and libxml2 packages and their handful of dependencies from the [ Termux
182
+ package repository] ( https://packages.termux.dev/apt/termux-main/pool/main/ ) .
184
183
185
- Each one is unpacked with ` ar x libcurl_8.10.1-1_aarch64 .deb; tar xf data.tar.xz ` and
184
+ Each one is unpacked with ` ar x libcurl_8.13.0_aarch64 .deb; tar xf data.tar.xz ` and
186
185
the resulting files moved to a newly-created Swift release SDK directory:
187
186
```
188
187
mkdir swift-release-android-aarch64-24-sdk
@@ -200,8 +199,8 @@ patchelf --set-rpath \$ORIGIN libandroid-spawn.so libcurl.so libxml2.so
200
199
201
200
# repeat the following for all versioned Termux libraries, as needed
202
201
rm libxml2.so libxml2.so.2
203
- readelf -d libxml2.so.2.13.4
204
- mv libxml2.so.2.13.4 libxml2.so
202
+ readelf -d libxml2.so.2.13.7
203
+ mv libxml2.so.2.13.7 libxml2.so
205
204
patchelf --set-soname libxml2.so libxml2.so
206
205
patchelf --replace-needed libz.so.1 libz.so libxml2.so
207
206
```
@@ -215,9 +214,9 @@ packages, by compiling against a more recent Android API that doesn't need the
215
214
` libandroid-spawn ` backport, and by cross-compiling libcurl/libxml2 and their
216
215
dependencies yourself or not using FoundationNetworking and FoundationXML.
217
216
218
- Finally, it gets [ the 6.0.3 source] ( https://github.com/swiftlang/swift/releases/tag/swift-6.0.3 -RELEASE )
219
- tarballs for ten Swift repos and renames them to ` llvm-project/ ` , ` swift/ ` ,
217
+ Finally, it gets [ the 6.1 source] ( https://github.com/swiftlang/swift/releases/tag/swift-6.1 -RELEASE )
218
+ tarballs for eleven Swift repos and renames them to ` llvm-project/ ` , ` swift/ ` ,
220
219
` swift-syntax ` , ` swift-experimental-string-processing ` , ` swift-corelibs-libdispatch ` ,
221
220
` swift-corelibs-foundation ` , ` swift-collections ` , ` swift-foundation ` ,
222
- ` swift-foundation-icu ` , and ` swift-corelibs-xctest ` , as required by the Swift
223
- ` build-script ` .
221
+ ` swift-foundation-icu ` , ` swift-corelibs-xctest ` , and ` swift-testing ` , as required
222
+ by the Swift ` build-script ` .
0 commit comments