Skip to content

Commit bf98fbb

Browse files
committed
Update to NDK 23
1 parent 3549660 commit bf98fbb

8 files changed

+208
-29
lines changed

.github/workflows/sdks.yml

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ jobs:
1414
devel-version: ${{ steps.check.outputs.devel-tag }}
1515
trunk-version: ${{ steps.check.outputs.trunk-tag }}
1616
steps:
17+
- name: Get cached NDK
18+
id: cache-ndk
19+
uses: actions/cache@v2
20+
with:
21+
path: ~/android-ndk-r23-linux.zip
22+
key: ndk-23
23+
- name: Get NDK 23 if not cached
24+
if: ${{ steps.cache-ndk.outputs.cache-hit != 'true' }}
25+
run: wget -q -O ~/android-ndk-r23-linux.zip https://dl.google.com/android/repository/android-ndk-r23-linux.zip
1726
- name: Check for latest Swift ${{ matrix.version }} toolchain
1827
id: check
1928
run: |
@@ -26,7 +35,9 @@ jobs:
2635
SWIFT_TAG="swift-5.5-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
2736
echo "::set-output name=devel-tag::$SWIFT_TAG"
2837
else
29-
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-DEV | cut -d- -f4-6)
38+
# LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-DEV | cut -d- -f4-6)
39+
# trunk toolchain is broken right now, so pin to Aug. 16
40+
LATEST_TOOLCHAIN_VERSION="2021-08-16"
3041
SWIFT_TAG="swift-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
3142
echo "::set-output name=trunk-tag::$SWIFT_TAG"
3243
fi
@@ -82,12 +93,18 @@ jobs:
8293
with:
8394
path: ~/${{ steps.version.outputs.tag }}-ubuntu20.04.tar.gz
8495
key: ${{ steps.version.outputs.tag }}-toolchain
96+
- name: Get cached NDK
97+
id: cache-ndk
98+
uses: actions/cache@v2
99+
with:
100+
path: ~/android-ndk-r23-linux.zip
101+
key: ndk-23
85102
- name: Get cached SDK
86103
id: cache-sdk
87104
uses: actions/cache@v2
88105
with:
89106
path: ~/swift-${{ matrix.version }}*-android-${{ matrix.arch }}-*-sdk.tar.xz
90-
key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-sdk
107+
key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-23-sdk
91108
- name: Clone
92109
uses: actions/checkout@v2
93110
with:
@@ -106,29 +123,47 @@ jobs:
106123
SDK=`pwd`/$SDK_NAME
107124
108125
tar xf ~/$SWIFT_TAG-ubuntu20.04.tar.gz
126+
unzip -q ~/android-ndk-r23-linux.zip
127+
NDK=`pwd`/android-ndk-r23
109128
110-
if [ ${{ matrix.version }} = 'trunk' ]; then
129+
if [ ${{ matrix.version }} = '5.4' ]; then
130+
sed -i "s%abort(void) %abort(void);// %" android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdlib.h
131+
elif [ ${{ matrix.version }} = 'trunk' ]; then
111132
EXTRA_FLAGS="--skip-early-swift-driver"
112133
fi
113134
114-
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android --android-ndk $ANDROID_NDK_HOME --android-arch ${{ matrix.arch }} --android-api-level $ANDROID_API_LEVEL --android-icu-uc $SDK/usr/lib/libicuuc.so --android-icu-uc-include $SDK/usr/include --android-icu-i18n $SDK/usr/lib/libicui18n.so --android-icu-i18n-include $SDK/usr/include --android-icu-data $SDK/usr/lib/libicudata.so --build-swift-tools=0 --native-swift-tools-path=`pwd`/$SWIFT_TAG-ubuntu20.04/usr/bin --native-clang-tools-path=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin --cross-compile-hosts=android-${{ matrix.arch }} --cross-compile-deps-path=$SDK --skip-local-build --xctest --install-swift --install-libdispatch --install-foundation --install-xctest --install-destdir=$SDK --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay' $EXTRA_FLAGS
135+
./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android --android-ndk $NDK --android-arch ${{ matrix.arch }} --android-api-level $ANDROID_API_LEVEL --android-icu-uc $SDK/usr/lib/libicuuc.so --android-icu-uc-include $SDK/usr/include --android-icu-i18n $SDK/usr/lib/libicui18n.so --android-icu-i18n-include $SDK/usr/include --android-icu-data $SDK/usr/lib/libicudata.so --build-swift-tools=0 --native-swift-tools-path=`pwd`/$SWIFT_TAG-ubuntu20.04/usr/bin --native-clang-tools-path=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin --cross-compile-hosts=android-${{ matrix.arch }} --cross-compile-deps-path=$SDK --skip-local-build --xctest --install-swift --install-libdispatch --install-foundation --install-xctest --install-destdir=$SDK --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay' $EXTRA_FLAGS
115136
116137
patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN $SDK/usr/lib/swift/android/lib*.so
117138
118139
tar cJf ~/$SDK_NAME.tar.xz $SDK_NAME
119-
rm -rf $SDK_NAME
120140
- name: Patch SPM ${{ matrix.version }} config
121141
run: |
122142
cd sdk-config
123143
124-
tar xf ~/${{ steps.version.outputs.tag }}-ubuntu20.04.tar.gz
144+
if [ ! -d android-ndk-r23 ]; then
145+
unzip -q ~/android-ndk-r23-linux.zip
146+
if [ ${{ matrix.version }} = '5.4' ]; then
147+
sed -i "s%abort(void) %abort(void);// %" android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdlib.h
148+
fi
149+
fi
150+
151+
if [ ! -d ${{ steps.version.outputs.tag }}-ubuntu20.04 ]; then
152+
tar xf ~/${{ steps.version.outputs.tag }}-ubuntu20.04.tar.gz
153+
fi
125154
sed -i "s%/home/butta/swift-5.4.2-RELEASE%`pwd`/${{ steps.version.outputs.tag }}%" android-${{ matrix.arch }}.json
126155
127-
tar xf ~/swift-${{ matrix.version }}*-android-${{ matrix.arch }}*-${ANDROID_API_LEVEL}-sdk.tar.xz
156+
ls
128157
SDK_NAME=$(ls | grep swift-${{ matrix.version }}.*-sdk)
158+
df
159+
if [[ $SDK_NAME = "" ]]; then
160+
echo "foo"
161+
tar xf ~/swift-${{ matrix.version }}*-android-${{ matrix.arch }}*-${ANDROID_API_LEVEL}-sdk.tar.xz
162+
fi
163+
echo "got before"
129164
sed -i "s%/home/butta/swift-5.4-android-${{ matrix.arch }}-${ANDROID_API_LEVEL}-sdk%`pwd`/${SDK_NAME}%" android-${{ matrix.arch }}.json
130165
131-
sed -i "s%/home/butta/src/android-ndk-r21e%${ANDROID_NDK_HOME}%" android-${{ matrix.arch }}.json
166+
sed -i "s%/home/butta/src/android-ndk-r21e%`pwd`/android-ndk-r23%" android-${{ matrix.arch }}.json
132167
- name: Get Swift Argument Parser package
133168
uses: actions/checkout@v2
134169
with:
@@ -251,6 +286,13 @@ jobs:
251286
run: |
252287
mkdir -p pack/lib/swift/android
253288
cp swift-argument-parser/.build/x86_64-unknown-linux-android/debug/{math,repeat,roll,swift-argument-parserPackageTests.xctest} pack
289+
290+
wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/master/termux-elf-cleaner.cpp
291+
wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/master/elf.h
292+
clang -D__ANDROID_API__=$ANDROID_API_LEVEL -o termux-elf-cleaner termux-elf-cleaner.cpp
293+
294+
./termux-elf-cleaner pack/{math,repeat,roll} || true
295+
254296
cp swift-crypto/.build/x86_64-unknown-linux-android/debug/swift-cryptoPackageTests.xctest pack
255297
if [ ${{ matrix.version }} = '5.4' ]; then
256298
cp swift-nio/.build/x86_64-unknown-linux-android/debug/swift-nioPackageTests.xctest pack
@@ -268,7 +310,7 @@ jobs:
268310
cp yams/Tests/YamsTests/Fixtures/SourceKitten#289/debug.yaml pack
269311
cp sdk-config/swift-${{ matrix.version }}*-android-x86_64-*${ANDROID_API_LEVEL}-sdk/usr/lib/lib*so pack/lib
270312
cp sdk-config/swift-${{ matrix.version }}*-android-x86_64-*${ANDROID_API_LEVEL}-sdk/usr/lib/swift/android/lib*so pack/lib/swift/android
271-
cp $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so pack/lib/swift/android
313+
cp sdk-config/android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so pack/lib/swift/android
272314
- name: Run tests on Android x86_64 emulator
273315
if: ${{ matrix.arch == 'x86_64' }}
274316
uses: reactivecircus/android-emulator-runner@v2

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
All patches used to build these SDKs are open source and listed below.
44

55
To build with an SDK, first download [the latest Android LTS NDK
6-
21e](https://developer.android.com/ndk/downloads) and [Swift 5.4.2
6+
23](https://developer.android.com/ndk/downloads) and [Swift 5.4.2
77
compiler](https://swift.org/download/#releases) (make sure to install the Swift
88
compiler's dependencies listed there). Unpack these archives and the SDK.
99

1010
I will write up a Swift script to do this SDK configuration, but you will need
1111
to do it manually for now. [You can see how I do it on the CI for a concrete
12-
example](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L125).
12+
example](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L154).
1313

1414
The SDK will need to be modified with the path to your NDK and Swift compiler
1515
in the following ways (I'll show aarch64 below, the same will need to be done
1616
for the armv7 or x86_64 SDKs):
1717

1818
1. Change all paths in `swift-5.4-android-aarch64-24-sdk/usr/lib/swift/android/aarch64/glibc.modulemap`
1919
from `/home/butta/src/android-ndk-r21e` to the path to your NDK, ie something
20-
like `/home/yourname/android-ndk-r21e`.
20+
like `/home/yourname/android-ndk-r23`.
2121

2222
2. There's a single line pointing to a header in the SDK itself, so change it
2323
from `/home/butta/swift-5.4-android-aarch64-24-sdk` in `glibc.modulemap` to the
@@ -33,7 +33,7 @@ swift-5.4-android-aarch64-24-sdk/usr/lib/swift/clang
3333
Finally, modify the cross-compilation JSON file in this repo similarly:
3434

3535
1. All paths to the NDK should change from `/home/butta/src/android-ndk-r21e`
36-
to the path to your NDK, `/home/yourname/android-ndk-r21e`.
36+
to the path to your NDK, `/home/yourname/android-ndk-r23`.
3737

3838
2. The path to the compiler should change from `/home/butta/swift-5.4.2-RELEASE-ubuntu20.04`
3939
to the path to your Swift compiler, `/home/yourname/swift-5.4.2-RELEASE-centos8`.
@@ -63,13 +63,13 @@ same build directory. Other packages use `#file` to point at test data in the
6363
repo: I've had success moving this data with the test runner, after modifying
6464
the test source so it has the path to this test data in the Android test
6565
environment. See [the example](https://github.com/buttaface/swift-android-sdk/blob/main/package-patches/swift-crypto-test-vectors.patch)
66-
of [swift-crypto on the CI](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L267).
66+
of [swift-crypto on the CI](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L305).
6767

6868
You can copy these executables and the SDK to [an emulator or a USB
6969
debugging-enabled device with adb](https://github.com/apple/swift/blob/release/5.4/docs/Android.md#4-deploying-the-build-products-to-the-device),
7070
or put them on an Android device with [a terminal emulator app like Termux](https://termux.com).
7171
I test aarch64 with Termux so I'll show how to run the test runner there, but
72-
the process is similar with adb, [as can be seen on the CI](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L280).
72+
the process is similar with adb, [as can be seen on the CI](https://github.com/buttaface/swift-android-sdk/blob/main/.github/workflows/sdks.yml#L318).
7373

7474
Copy the test executables to the same directory as the SDK:
7575
```
@@ -188,14 +188,14 @@ After making sure [needed build tools like python 3, CMake, and ninja](https://g
188188
are installed, I ran the following `build-script` command:
189189
```
190190
./swift/utils/build-script -R --no-assertions --skip-build-cmark --skip-build-llvm --android
191-
--android-ndk /home/butta/src/android-ndk-r21e/ --android-arch aarch64 --android-api-level 24
191+
--android-ndk /home/butta/src/android-ndk-r23/ --android-arch aarch64 --android-api-level 24
192192
--android-icu-uc /home/butta/swift-5.4-android-aarch64-24-sdk/usr/lib/libicuuc.so
193193
--android-icu-uc-include /home/butta/swift-5.4-android-aarch64-24-sdk/usr/include/
194194
--android-icu-i18n /home/butta/swift-5.4-android-aarch64-24-sdk/usr/lib/libicui18n.so
195195
--android-icu-i18n-include /home/butta/swift-5.4-android-aarch64-24-sdk/usr/include/
196196
--android-icu-data /home/butta/swift-5.4-android-aarch64-24-sdk/usr/lib/libicudata.so
197197
--build-swift-tools=0 --native-swift-tools-path=/home/butta/swift-5.4-RELEASE-ubuntu20.04/usr/bin/
198-
--native-clang-tools-path=/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin
198+
--native-clang-tools-path=/home/butta/src/android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/bin
199199
--host-cc=/usr/bin/clang-11 --host-cxx=/usr/bin/clang++-11
200200
--cross-compile-hosts=android-aarch64 --cross-compile-deps-path=/home/butta/swift-5.4-android-aarch64-24-sdk
201201
--skip-local-build --xctest --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay'

android-aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"extra-swiftc-flags": [
1010
"-resource-dir", "/home/butta/swift-5.4-android-aarch64-24-sdk/usr/lib/swift",
1111
"-tools-directory", "/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-Xclang-linker", "--target=aarch64-linux-android24",
12+
"-Xclang-linker", "--target=aarch64-linux-android24", "-use-ld=lld",
1313
"-L/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x",
1414
],
1515
"extra-cpp-flags": [

android-armv7.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"extra-swiftc-flags": [
1010
"-resource-dir", "/home/butta/swift-5.4-android-armv7-24-sdk/usr/lib/swift",
1111
"-tools-directory", "/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-Xclang-linker", "--target=armv7-linux-android24",
12+
"-Xclang-linker", "--target=armv7-linux-android24", "-use-ld=lld",
1313
"-L/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/armv7-linux-androideabi/4.9.x/armv7-a",
1414
],
1515
"extra-cpp-flags": [

android-x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"extra-swiftc-flags": [
1010
"-resource-dir", "/home/butta/swift-5.4-android-x86_64-24-sdk/usr/lib/swift",
1111
"-tools-directory", "/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/bin",
12-
"-Xclang-linker", "--target=x86_64-linux-android24",
12+
"-Xclang-linker", "--target=x86_64-linux-android24", "-use-ld=lld",
1313
"-L/home/butta/src/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x",
1414
],
1515
"extra-cpp-flags": [

swift-android-5.4.patch

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
2+
index 6d0493d9e00..584890d655e 100644
3+
--- a/swift/CMakeLists.txt
4+
+++ b/swift/CMakeLists.txt
5+
@@ -177,6 +177,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUA
6+
set(SWIFT_USE_LINKER_default "lld")
7+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
8+
set(SWIFT_USE_LINKER_default "")
9+
+elseif(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
10+
+ set(SWIFT_USE_LINKER_default "lld")
11+
else()
12+
set(SWIFT_USE_LINKER_default "gold")
13+
endif()
114
diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
215
index 38191b01a64..1f851d3409c 100644
316
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -28,6 +41,17 @@ diff --git a/swift/stdlib/public/Platform/bionic.modulemap.gyb b/swift/stdlib/pu
2841
index e44f9082653..9ed6719e17d 100644
2942
--- a/swift/stdlib/public/Platform/bionic.modulemap.gyb
3043
+++ b/swift/stdlib/public/Platform/bionic.modulemap.gyb
44+
@@ -82,6 +82,10 @@ module SwiftGlibc [system] {
45+
header "${GLIBC_INCLUDE_PATH}/locale.h"
46+
export *
47+
}
48+
+ module malloc {
49+
+ header "${GLIBC_INCLUDE_PATH}/malloc.h"
50+
+ export *
51+
+ }
52+
module math {
53+
link "m"
54+
header "${GLIBC_INCLUDE_PATH}/math.h"
3155
@@ -185,7 +185,7 @@ module SwiftGlibc [system] {
3256
export *
3357
}
@@ -83,7 +107,7 @@ diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/sw
83107
index 69d71e4e630..e222a510d58 100644
84108
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
85109
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
86-
@@ -152,16 +152,21 @@ class Target(object):
110+
@@ -152,16 +152,22 @@ class Target(object):
87111
def name(self):
88112
return "{}-{}".format(self.platform.name, self.arch)
89113

@@ -107,6 +131,7 @@ index 69d71e4e630..e222a510d58 100644
107131
+ flags += '-resource-dir %s/swift-%s/lib/swift ' % (
108132
+ args.build_root, self.name)
109133
+ flags += '-sdk %s/sysroot ' % (android_toolchain_path)
134+
+ flags += '-use-ld=lld '
110135
+ flags += '-tools-directory %s/bin' % (android_toolchain_path)
111136

112137
return flags
@@ -134,3 +159,19 @@ index 617e27e3..0e4c233b 100644
134159
set_target_properties(Foundation PROPERTIES
135160
INSTALL_RPATH "$ORIGIN"
136161
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>"
162+
diff --git a/swift-corelibs-libdispatch/src/shims/atomic.h b/swift-corelibs-libdispatch/src/shims/atomic.h
163+
index c002e72..bc232f1 100644
164+
--- a/swift-corelibs-libdispatch/src/shims/atomic.h
165+
+++ b/swift-corelibs-libdispatch/src/shims/atomic.h
166+
@@ -35,7 +35,11 @@
167+
#if defined(__cplusplus)
168+
#define _Bool bool
169+
#endif
170+
+#if defined(__ANDROID__) && __NDK_MAJOR__ >= 23
171+
+#include <bits/stdatomic.h>
172+
+#else
173+
#include <stdatomic.h>
174+
+#endif
175+
176+
#define memory_order_ordered memory_order_seq_cst
177+
#define memory_order_dependency memory_order_acquire

0 commit comments

Comments
 (0)