Skip to content

Commit 79ed857

Browse files
authored
Merge pull request #39791 from apple/revert-39045-android-ndk-23
Revert "[android] Update to NDK 23"
2 parents 008647c + 15a5d2c commit 79ed857

File tree

20 files changed

+116
-60
lines changed

20 files changed

+116
-60
lines changed

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
180180
# build environment.
181181
if(LLVM_USE_LINKER)
182182
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
183-
elseif(${SWIFT_HOST_VARIANT_SDK} STREQUAL ANDROID)
184-
set(SWIFT_USE_LINKER_default "lld")
185183
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
186184
set(SWIFT_USE_LINKER_default "lld")
187185
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
@@ -308,8 +306,8 @@ set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING
308306

309307
set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
310308
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
311-
set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.5" CACHE STRING
312-
"The Clang version to use when building for Android.")
309+
set(SWIFT_ANDROID_NDK_GCC_VERSION "" CACHE STRING
310+
"The GCC version to use when building for Android. Currently only 4.9 is supported.")
313311
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
314312
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
315313

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ function(_add_host_variant_c_compile_link_flags name)
145145
endif()
146146

147147
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
148-
# Make sure the Android NDK lld is used.
149-
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
150-
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-B${tools_path}>)
148+
# lld can handle targeting the android build. However, if lld is not
149+
# enabled, then fallback to the linker included in the android NDK.
150+
if(NOT SWIFT_USE_LINKER STREQUAL "lld")
151+
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
152+
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-B${tools_path}>)
153+
endif()
151154
endif()
152155

153156
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -381,6 +384,11 @@ function(_add_host_variant_link_flags target)
381384
cxx_link_libraries)
382385
target_link_libraries(${target} PRIVATE
383386
${cxx_link_libraries})
387+
388+
swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH}
389+
${SWIFT_HOST_VARIANT_ARCH}_LIB)
390+
target_link_directories(${target} PRIVATE
391+
${${SWIFT_HOST_VARIANT_ARCH}_LIB})
384392
else()
385393
# If lto is enabled, we need to add the object path flag so that the LTO code
386394
# generator leaves the intermediate object file in a place where it will not

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ function(add_swift_unittest test_dirname)
3232
COMMAND "${SWIFT_SOURCE_DIR}/utils/swift-rpathize.py"
3333
"$<TARGET_FILE:${test_dirname}>")
3434
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "android")
35+
swift_android_libgcc_for_arch_cross_compile(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
36+
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_DIRECTORIES
37+
"${android_system_libs}")
3538
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log")
3639
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
3740
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")

cmake/modules/SwiftAndroidSupport.cmake

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
function(swift_android_prebuilt_host_name prebuilt_var_name)
2+
# Get the prebuilt suffix to create the correct toolchain path when using the NDK
3+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
4+
set(${prebuilt_var_name} darwin-x86_64 PARENT_SCOPE)
5+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
6+
set(${prebuilt_var_name} linux-x86_64 PARENT_SCOPE)
7+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
8+
set(${prebuilt_var_name} Windows-x86_64 PARENT_SCOPE)
9+
else()
10+
message(SEND_ERROR "cannot cross-compile to android from ${CMAKE_HOST_SYSTEM_NAME}")
11+
endif()
12+
endfunction()
13+
14+
function(swift_android_libgcc_for_arch_cross_compile arch var)
15+
set(paths)
16+
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
17+
list(APPEND paths "${SWIFT_SDK_ANDROID_ARCH_${arch}_PATH}/../lib/gcc/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/${SWIFT_ANDROID_NDK_GCC_VERSION}.x")
18+
endif()
19+
set(${var} ${paths} PARENT_SCOPE)
20+
endfunction()
21+
122
function(swift_android_sysroot sysroot_var_name)
223
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
3-
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
4-
set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" PARENT_SCOPE)
24+
swift_android_prebuilt_host_name(prebuilt_build)
25+
set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${prebuilt_build}/sysroot" PARENT_SCOPE)
526
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
627
set(${sysroot_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}" PARENT_SCOPE)
728
else()
@@ -11,8 +32,19 @@ endfunction()
1132

1233
function(swift_android_tools_path arch path_var_name)
1334
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
14-
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
15-
set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/bin" PARENT_SCOPE)
35+
swift_android_prebuilt_host_name(prebuilt_build)
36+
if("${arch}" STREQUAL "i686")
37+
set(ndk_prebuilt_path
38+
"${SWIFT_ANDROID_NDK_PATH}/toolchains/x86-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
39+
elseif("${arch}" STREQUAL "x86_64")
40+
set(ndk_prebuilt_path
41+
"${SWIFT_ANDROID_NDK_PATH}/toolchains/x86_64-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
42+
else()
43+
set(ndk_prebuilt_path
44+
"${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}")
45+
endif()
46+
47+
set(${path_var_name} "${ndk_prebuilt_path}/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/bin" PARENT_SCOPE)
1648
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
1749
set(${path_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/bin" PARENT_SCOPE)
1850
else()

docs/Android.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ To follow along with this guide, you'll need:
3333
Ubuntu 18.04 or Ubuntu 16.04. Before attempting to build for Android,
3434
please make sure you are able to build for Linux by following the
3535
instructions in the Swift project README.
36-
2. The latest version of the Android NDK (r23 at the time of this writing),
37-
available to download here:
36+
2. The latest version of the Android NDK (r21e at the time of this writing,
37+
only r19 or later are supported), available to download here:
3838
https://developer.android.com/ndk/downloads/index.html.
3939
3. An Android device with remote debugging enabled or the emulator. We require
4040
remote debugging in order to deploy built stdlib products to the device. You
@@ -73,7 +73,7 @@ Android NDK, as well as the directories that contain the `libicuucswift.so` and
7373

7474
```
7575
$ ARM_DIR=path/to/libiconv-libicu-android/armeabi-v7a
76-
$ NDK_PATH=path/to/android-ndk-r23
76+
$ NDK_PATH=path/to/android-ndk-r21e
7777
$ utils/build-script \
7878
-R \ # Build in ReleaseAssert mode.
7979
--android \ # Build for Android.
@@ -99,7 +99,7 @@ Then use the built Swift compiler from the previous step to compile a Swift
9999
source file, targeting Android:
100100

101101
```
102-
$ NDK_PATH="path/to/android-ndk-r23"
102+
$ NDK_PATH="path/to/android-ndk-r21e"
103103
$ build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc \ # The Swift compiler built in the previous step
104104
# The location of the tools used to build Android binaries
105105
-tools-directory ${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64/bin/ \
@@ -153,7 +153,7 @@ adb push /path/to/libicu-android/armeabi-v7a/libicuucswift.so /data/local/tmp
153153
In addition, you'll also need to copy the Android NDK's libc++:
154154

155155
```
156-
$ adb push /path/to/android-ndk-r23/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp
156+
$ adb push /path/to/android-ndk-r21e/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so /data/local/tmp
157157
```
158158

159159
Finally, you'll need to copy the `hello` executable you built in the
@@ -196,7 +196,7 @@ $ utils/build-script \
196196
-R \ # Build in ReleaseAssert mode.
197197
-T \ # Run all tests, including on the Android device (add --host-test to only run Android tests on the linux host).
198198
--android \ # Build for Android.
199-
--android-ndk ~/android-ndk-r23 \ # Path to an Android NDK.
199+
--android-ndk ~/android-ndk-r21e \ # Path to an Android NDK.
200200
--android-arch armv7 \ # Optionally specify Android architecture, alternately aarch64
201201
--android-ndk-version 21 \
202202
--android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \

lib/Driver/UnixToolChains.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
8585
}
8686

8787
std::string toolchains::GenericUnix::getDefaultLinker() const {
88-
if (getTriple().isAndroid())
89-
return "lld";
90-
9188
switch (getTriple().getArch()) {
9289
case llvm::Triple::arm:
9390
case llvm::Triple::aarch64:

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ function(_add_target_variant_c_compile_link_flags)
9494
endif()
9595

9696
if("${CFLAGS_SDK}" STREQUAL "ANDROID")
97-
# Make sure the Android NDK lld is used.
98-
swift_android_tools_path(${CFLAGS_ARCH} tools_path)
99-
list(APPEND result "-B" "${tools_path}")
97+
# lld can handle targeting the android build. However, if lld is not
98+
# enabled, then fallback to the linker included in the android NDK.
99+
if(NOT SWIFT_USE_LINKER STREQUAL "lld")
100+
swift_android_tools_path(${CFLAGS_ARCH} tools_path)
101+
list(APPEND result "-B" "${tools_path}")
102+
endif()
100103
endif()
101104

102105
if("${CFLAGS_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -402,8 +405,8 @@ function(_add_target_variant_link_flags)
402405
MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR}")
403406
if("${LFLAGS_SDK}" STREQUAL "LINUX")
404407
list(APPEND link_libraries "pthread" "dl")
405-
if("${LFLAGS_ARCH}" MATCHES "armv6|armv7|i686")
406-
list(APPEND link_libraries "atomic")
408+
if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686")
409+
list(APPEND link_libraries PRIVATE "atomic")
407410
endif()
408411
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD")
409412
list(APPEND link_libraries "pthread")
@@ -430,14 +433,8 @@ function(_add_target_variant_link_flags)
430433
list(APPEND result "-Wl,-Bsymbolic")
431434
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
432435
list(APPEND link_libraries "dl" "log")
433-
if("${LFLAGS_ARCH}" STREQUAL "armv7")
434-
list(APPEND link_libraries "atomic")
435-
endif()
436436
# We need to add the math library, which is linked implicitly by libc++
437437
list(APPEND result "-lm")
438-
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
439-
list(APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION}")
440-
endif()
441438

442439
# link against the custom C++ library
443440
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -447,6 +444,11 @@ function(_add_target_variant_link_flags)
447444
list(APPEND link_libraries
448445
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_I18N}
449446
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_UC})
447+
448+
swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
449+
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
450+
list(APPEND library_search_directories ${path})
451+
endforeach()
450452
else()
451453
# If lto is enabled, we need to add the object path flag so that the LTO code
452454
# generator leaves the intermediate object file in a place where it will not
@@ -474,17 +476,10 @@ function(_add_target_variant_link_flags)
474476
endif()
475477

476478
if(SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
477-
# The linker is normally chosen based on the host, but the Android NDK only
478-
# uses lld now.
479-
if("${LFLAGS_SDK}" STREQUAL "ANDROID")
480-
set(linker "lld")
481-
else()
482-
set(linker "${SWIFT_USE_LINKER}")
483-
endif()
484479
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
485-
list(APPEND result "-fuse-ld=${linker}.exe")
480+
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}.exe")
486481
else()
487-
list(APPEND result "-fuse-ld=${linker}")
482+
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}")
488483
endif()
489484
endif()
490485

stdlib/public/runtime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ foreach(sdk ${SWIFT_SDKS})
229229
endif()
230230
set(libpthread -lpthread)
231231
set(android_libraries)
232-
if(${sdk} STREQUAL ANDROID)
232+
if(sdk STREQUAL ANDROID)
233233
set(android_libraries -llog)
234234
set(libpthread)
235235
endif()

test/AutoDiff/validation-test/reflection.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// REQUIRES: no_asan
2-
// UNSUPPORTED: OS=linux-android, OS=linux-androideabi
32
// RUN: %empty-directory(%t)
43
import _Differentiation
54

test/LinkerSections/function_sections-lld.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)