From 7a0dd2385a4149ae2c2f1ba0b34afbe98ec33056 Mon Sep 17 00:00:00 2001 From: buttaface Date: Wed, 21 Sep 2022 23:16:29 +0530 Subject: [PATCH] [android] Update to LTS NDK 25b (#60938) Also, remove `SWIFT_ANDROID_NDK_CLANG_VERSION` and just extract the resource directory from the NDK using `file(GLOB)`. --- CMakeLists.txt | 2 -- docs/Android.md | 10 +++++----- stdlib/cmake/modules/AddSwiftStdlib.cmake | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c21c550c23595..e5f3153797ba7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,8 +315,6 @@ set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING "Path to the directory that contains the Android NDK tools that are executable on the build machine") -set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.8" CACHE STRING - "The Clang version to use when building for Android.") set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING "Path on an Android device where build products will be pushed. These are used when running the test suite against the device") diff --git a/docs/Android.md b/docs/Android.md index dd347c3425e0f..6cfc6b30161e1 100644 --- a/docs/Android.md +++ b/docs/Android.md @@ -33,7 +33,7 @@ To follow along with this guide, you'll need: Ubuntu 18.04 or Ubuntu 16.04. Before attempting to build for Android, please make sure you are able to build for Linux by following the instructions in the Swift project README. -2. The latest version of the Android NDK (r23b at the time of this writing), +3. The latest version of the Android LTS NDK (r25b at the time of this writing), available to download here: https://developer.android.com/ndk/downloads/index.html. 3. An Android device with remote debugging enabled or the emulator. We require @@ -49,7 +49,7 @@ Enter your Swift directory, then run the build script, passing the path to the Android NDK: ``` -$ NDK_PATH=path/to/android-ndk-r23b +$ NDK_PATH=path/to/android-ndk-r25b $ utils/build-script \ -R \ # Build in ReleaseAssert mode. --android \ # Build for Android. @@ -70,7 +70,7 @@ Then use the built Swift compiler from the previous step to compile a Swift source file, targeting Android: ``` -$ NDK_PATH="path/to/android-ndk-r23b" +$ NDK_PATH="path/to/android-ndk-r25b" $ build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc \ # The Swift compiler built in the previous step # The location of the tools used to build Android binaries -tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \ @@ -116,7 +116,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libswi In addition, you'll also need to copy the Android NDK's libc++: ``` -$ adb push /path/to/android-ndk-r23b/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp +$ adb push /path/to/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/libc++_shared.so /data/local/tmp ``` Finally, you'll need to copy the `hello` executable you built in the @@ -159,7 +159,7 @@ $ utils/build-script \ -R \ # Build in ReleaseAssert mode. -T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the linux host). --android \ # Build for Android. - --android-ndk ~/android-ndk-r23b \ # Path to an Android NDK. + --android-ndk ~/android-ndk-r25b \ # Path to an Android NDK. --android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64 --android-api-level 21 ``` diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index f44b978c896e4..f4d55ab285f1e 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -457,7 +457,8 @@ function(_add_target_variant_link_flags) # We need to add the math library, which is linked implicitly by libc++ list(APPEND result "-lm") if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") - list(APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION}") + file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*) + list(APPEND result "-resource-dir=${RESOURCE_DIR}") endif() # link against the custom C++ library