-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[android] Update to NDK 23 #39045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[android] Update to NDK 23 #39045
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,7 @@ | ||
function(swift_android_prebuilt_host_name prebuilt_var_name) | ||
# Get the prebuilt suffix to create the correct toolchain path when using the NDK | ||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) | ||
set(${prebuilt_var_name} darwin-x86_64 PARENT_SCOPE) | ||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) | ||
set(${prebuilt_var_name} linux-x86_64 PARENT_SCOPE) | ||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | ||
set(${prebuilt_var_name} Windows-x86_64 PARENT_SCOPE) | ||
finagolfin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else() | ||
message(SEND_ERROR "cannot cross-compile to android from ${CMAKE_HOST_SYSTEM_NAME}") | ||
endif() | ||
endfunction() | ||
|
||
function(swift_android_libgcc_for_arch_cross_compile arch var) | ||
set(paths) | ||
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") | ||
list(APPEND paths "${SWIFT_SDK_ANDROID_ARCH_${arch}_PATH}/../lib/gcc/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/${SWIFT_ANDROID_NDK_GCC_VERSION}.x") | ||
endif() | ||
set(${var} ${paths} PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(swift_android_sysroot sysroot_var_name) | ||
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") | ||
swift_android_prebuilt_host_name(prebuilt_build) | ||
set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${prebuilt_build}/sysroot" PARENT_SCOPE) | ||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform) | ||
set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" PARENT_SCOPE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be change shortly when Google releases native NDK for Darwin-arm64. I think the previous function was better in case further changes were needed. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can always change this later if we ever support that mooted arm64 NDK. |
||
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "") | ||
set(${sysroot_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}" PARENT_SCOPE) | ||
else() | ||
|
@@ -32,19 +11,8 @@ endfunction() | |
|
||
function(swift_android_tools_path arch path_var_name) | ||
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") | ||
swift_android_prebuilt_host_name(prebuilt_build) | ||
if("${arch}" STREQUAL "i686") | ||
set(ndk_prebuilt_path | ||
"${SWIFT_ANDROID_NDK_PATH}/toolchains/x86-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}") | ||
elseif("${arch}" STREQUAL "x86_64") | ||
set(ndk_prebuilt_path | ||
"${SWIFT_ANDROID_NDK_PATH}/toolchains/x86_64-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}") | ||
else() | ||
set(ndk_prebuilt_path | ||
"${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${prebuilt_build}") | ||
endif() | ||
|
||
set(${path_var_name} "${ndk_prebuilt_path}/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}/bin" PARENT_SCOPE) | ||
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform) | ||
set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/bin" PARENT_SCOPE) | ||
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "") | ||
set(${path_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/bin" PARENT_SCOPE) | ||
else() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,12 +94,9 @@ function(_add_target_variant_c_compile_link_flags) | |
endif() | ||
|
||
if("${CFLAGS_SDK}" STREQUAL "ANDROID") | ||
# lld can handle targeting the android build. However, if lld is not | ||
# enabled, then fallback to the linker included in the android NDK. | ||
if(NOT SWIFT_USE_LINKER STREQUAL "lld") | ||
swift_android_tools_path(${CFLAGS_ARCH} tools_path) | ||
list(APPEND result "-B" "${tools_path}") | ||
endif() | ||
# Make sure the Android NDK lld is used. | ||
swift_android_tools_path(${CFLAGS_ARCH} tools_path) | ||
list(APPEND result "-B" "${tools_path}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brought the NDK tools path back here and tested it by passing the prebuilt clang that comes with the Swift trunk snapshot toolchain, as that's the clang a fresh build would use too, to We may be better off changing the clang used to link for Android with a freshly-built Swift toolchain to the NDK clang too, let me know what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @drodriguez, just waiting to hear from you about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the radio silence. It has been a busy couple of weeks lately. What I have done:
What I have not done:
I will probably try to find out some time for the rebranch check (because the clock is ticking on that one). I will try to get to the others as soon as I can. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been getting the stdlib built for Android with the Swift-forked clang and I just noticed that clang 13 switches Android to building with compiler-rt and libunwind, llvm/llvm-project@91f8aacc0, which was upstreamed from the NDK clang. Since the upcoming Swift rebranch has that patch too, I think it will break the community Android CI, unless we switch it to Android NDK 23. We should probably get this NDK 23 pull in before the rebranch: the good news is that I have the Swift-forked clang building the stdlib for Android now, with the patches in my first link. I've just kicked off a build to make sure the validation suite passes for me locally on linux, just as the Android CI runs with |
||
endif() | ||
|
||
if("${CFLAGS_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS) | ||
|
@@ -389,8 +386,8 @@ function(_add_target_variant_link_flags) | |
MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR}") | ||
if("${LFLAGS_SDK}" STREQUAL "LINUX") | ||
list(APPEND link_libraries "pthread" "dl") | ||
if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686") | ||
list(APPEND link_libraries PRIVATE "atomic") | ||
if("${LFLAGS_ARCH}" MATCHES "armv6|armv7|i686") | ||
list(APPEND link_libraries "atomic") | ||
endif() | ||
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD") | ||
list(APPEND link_libraries "pthread") | ||
|
@@ -417,8 +414,14 @@ function(_add_target_variant_link_flags) | |
list(APPEND result "-Wl,-Bsymbolic") | ||
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID") | ||
list(APPEND link_libraries "dl" "log") | ||
if("${LFLAGS_ARCH}" STREQUAL "armv7") | ||
list(APPEND link_libraries "atomic") | ||
endif() | ||
# 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}") | ||
endif() | ||
|
||
# link against the custom C++ library | ||
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries) | ||
|
@@ -428,11 +431,6 @@ function(_add_target_variant_link_flags) | |
list(APPEND link_libraries | ||
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_I18N} | ||
${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_UC}) | ||
|
||
swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB) | ||
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB) | ||
list(APPEND library_search_directories ${path}) | ||
endforeach() | ||
else() | ||
# If lto is enabled, we need to add the object path flag so that the LTO code | ||
# generator leaves the intermediate object file in a place where it will not | ||
|
@@ -460,10 +458,17 @@ function(_add_target_variant_link_flags) | |
endif() | ||
|
||
if(SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE) | ||
# The linker is normally chosen based on the host, but the Android NDK only | ||
# uses lld now. | ||
if("${LFLAGS_SDK}" STREQUAL "ANDROID") | ||
set(linker "lld") | ||
else() | ||
set(linker "${SWIFT_USE_LINKER}") | ||
endif() | ||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) | ||
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}.exe") | ||
list(APPEND result "-fuse-ld=${linker}.exe") | ||
else() | ||
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}") | ||
list(APPEND result "-fuse-ld=${linker}") | ||
endif() | ||
endif() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// REQUIRES: OS=linux-androideabi || OS=linux-android | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift -Xfrontend -function-sections -emit-module -emit-library -static -parse-stdlib %S/Inputs/FunctionSections.swift | ||
// RUN: %target-build-swift -Xlinker --gc-sections -Xlinker -Map=%t/../../FunctionSections.map -I%t/../.. -L%t/../.. -lFunctionSections %S/Inputs/FunctionSectionsUse.swift | ||
// RUN: %FileCheck %s < %t/../../FunctionSections.map | ||
|
||
// CHECK-NOT: .text.$s16FunctionSections5func2yyF | ||
// CHECK: .text.$s16FunctionSections5func1yyF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to update this every year when a new LTS NDK comes out.