Skip to content

Commit e23f40b

Browse files
committed
[android] Update to LTS NDK 26b
NDK 26 renamed the directory in which it places the Android compiler-rt from `lib64/`, and added a bunch of nullability annotations to the Bionic libc.
1 parent f6e8fd2 commit e23f40b

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

docs/Android.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ To follow along with this guide, you'll need:
3636
instructions in the Swift project README.
3737
2. The latest build of the Swift compiler for your Linux distro, available at
3838
https://www.swift.org/download/ or sometimes your distro package manager.
39-
3. The last version of the Android LTS NDK (r25c, the latest LTS NDK 26 at the
40-
time of this writing doesn't work yet), available to download here:
39+
3. The latest version of the Android LTS NDK (r26b at the time of this writing),
40+
available to download here:
4141
https://developer.android.com/ndk/downloads
4242
4. An Android device with remote debugging enabled or the emulator. We require
4343
remote debugging in order to deploy built stdlib products to the device. You
@@ -54,7 +54,7 @@ and the prebuilt Swift toolchain (add --skip-early-swift-driver if you already
5454
have a Swift toolchain in your path):
5555

5656
```
57-
$ NDK_PATH=path/to/android-ndk-r25c
57+
$ NDK_PATH=path/to/android-ndk-r26b
5858
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
5959
$ git checkout swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a
6060
$ utils/build-script \
@@ -83,7 +83,7 @@ Then use the standalone Swift stdlib from the previous step to compile a Swift
8383
source file, targeting Android:
8484

8585
```
86-
$ NDK_PATH="path/to/android-ndk-r25c"
86+
$ NDK_PATH="path/to/android-ndk-r26b"
8787
$ SWIFT_PATH=path/to/swift-DEVELOPMENT-SNAPSHOT-2023-09-30-a-ubuntu20.04/usr/bin
8888
$ $SWIFT_PATH/swiftc \ # The prebuilt Swift compiler you downloaded
8989
# The location of the tools used to build Android binaries
@@ -133,7 +133,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
133133
In addition, you'll also need to copy the Android NDK's libc++:
134134

135135
```
136-
$ adb push /path/to/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
136+
$ adb push /path/to/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
137137
```
138138

139139
Finally, you'll need to copy the `hello` executable you built in the
@@ -176,7 +176,7 @@ $ utils/build-script \
176176
-R \ # Build in ReleaseAssert mode.
177177
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the Linux host).
178178
--android \ # Build for Android.
179-
--android-ndk ~/android-ndk-r25c \ # Path to an Android NDK.
179+
--android-ndk ~/android-ndk-r26b \ # Path to an Android NDK.
180180
--android-arch aarch64 \ # Optionally specify Android architecture, alternately armv7
181181
--android-api-level 21
182182
```

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ function(_add_target_variant_link_flags)
526526
# We need to add the math library, which is linked implicitly by libc++
527527
list(APPEND result "-lm")
528528
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
529-
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
529+
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26")
530+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
531+
else()
532+
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
533+
endif()
530534
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
531535
endif()
532536

stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) {
131131
return _pipe(unsafeFds.baseAddress, 0, 0)
132132
#elseif os(WASI)
133133
preconditionFailure("No pipes available on WebAssembly/WASI")
134+
#elseif os(Android)
135+
return pipe(unsafeFds.baseAddress!)
134136
#else
135137
return pipe(unsafeFds.baseAddress)
136138
#endif

stdlib/public/SwiftShims/swift/shims/LibcShims.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ SWIFT_READONLY
6161
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
6262
__swift_size_t n) {
6363
// FIXME: Is there a way to identify Glibc specifically?
64-
#if defined(__gnu_linux__)
64+
#if defined(__gnu_linux__) || defined(__ANDROID__)
6565
extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t);
6666
#else
6767
extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t);

0 commit comments

Comments
 (0)