Skip to content

build: adjust android build path #71927

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,6 @@ that it's possible to build the compiler using host tools.")
set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING
"Version number for the Android API")

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_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")

Expand Down Expand Up @@ -1094,8 +1092,9 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
set(SWIFT_HOST_VARIANT "android" CACHE STRING
"Deployment OS for Swift host tools (the compiler) [android]")

set(SWIFT_ANDROID_NATIVE_SYSROOT "/data/data/com.termux/files" CACHE STRING
"Path to Android sysroot, default initialized to the Termux app's layout")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You misunderstand what this is used for. SWIFT_ANDROID_NATIVE_SYSROOT is a native sysroot used in Android itself, eg the Termux app that runs on Android has its own native compilation sysroot and does not use the NDK. SWIFT_ANDROID_NDK_PATH is the path to the NDK and is only set when cross-compiling to Android.

That's why the code in cmake/modules/SwiftAndroidSupport.cmake below first checks if SWIFT_ANDROID_NDK_PATH is set, so it knows if it is cross-compiling with the NDK, then checks if natively compiling with an Android sysroot, ie in Termux, and if neither happens to be set, it errors.

Don't modify these two lines: it is not relevant to the normal Android cross-compilation workflow that you are using.

string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
set(SWIFT_ANDROID_NATIVE_SYSROOT "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" CACHE STRING
"Path to Android sysroot")

if("${SWIFT_SDK_ANDROID_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_ANDROID_ARCHITECTURES ${SWIFT_HOST_VARIANT_ARCH})
Expand Down Expand Up @@ -1158,9 +1157,6 @@ endif()
# Should we cross-compile the standard library for Android?
is_sdk_requested(ANDROID swift_build_android)
if(swift_build_android AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
if ("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
message(FATAL_ERROR "You must set SWIFT_ANDROID_NDK_PATH to cross-compile the Swift runtime for Android")
endif()
if (NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux"))
message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
endif()
Expand Down
10 changes: 5 additions & 5 deletions cmake/modules/SwiftAndroidSupport.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function(swift_android_sysroot sysroot_var_name)
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
if(NOT "${CMAKE_ANDROID_NDK}" STREQUAL "")
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
set(${sysroot_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" PARENT_SCOPE)
set(${sysroot_var_name} "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/${platform}-x86_64/sysroot" PARENT_SCOPE)
elseif(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
set(${sysroot_var_name} "${SWIFT_ANDROID_NATIVE_SYSROOT}" PARENT_SCOPE)
else()
Expand All @@ -10,9 +10,9 @@ function(swift_android_sysroot sysroot_var_name)
endfunction()

function(swift_android_tools_path arch path_var_name)
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
if(NOT "${CMAKE_ANDROID_NDK}" STREQUAL "")
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} platform)
set(${path_var_name} "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${platform}-x86_64/bin" PARENT_SCOPE)
set(${path_var_name} "${CMAKE_ANDROID_NDK}/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()
Expand All @@ -22,7 +22,7 @@ endfunction ()

function(swift_android_cxx_libraries_for_arch arch libraries_var_name)
set(link_libraries)
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
if(NOT "${CMAKE_ANDROID_NDK}" STREQUAL "")
set(android_libcxx_path "${SWIFT_SDK_ANDROID_ARCH_${arch}_PATH}/usr/lib/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}")
list(APPEND link_libraries ${android_libcxx_path}/libc++abi.a
${android_libcxx_path}/libc++_shared.so)
Expand Down