Skip to content
Merged
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
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,21 @@ endif()
# Should we cross-compile the standard library for Android?
is_sdk_requested(ANDROID swift_build_android)
if(swift_build_android AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
# Get the prebuilt suffix to create the correct toolchain path when using the NDK
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(_swift_android_prebuilt_suffix "darwin-x86_64")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(_swift_android_prebuilt_suffix "linux-x86_64")
endif()

set(SWIFT_ANDROID_PREBUILT_PATH
"${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_suffix}")

# Resolve the correct linker based on the file name of CMAKE_LINKER (being 'ld' or 'ld.gold' the options)
get_filename_component(SWIFT_ANDROID_LINKER_NAME "${CMAKE_LINKER}" NAME)
Copy link
Member

Choose a reason for hiding this comment

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

This is a bad idea in the long run. Since this enables building for Android, I think this is okay to commit, but we shouldn't use CMAKE_LINKER per se. I think that detecting the linker here should be separate since the valid linkers are ld, ld.gold, ld.lld, ld.ld64, link. At least two of those do not support ELF.

set(SWIFT_SDK_ANDROID_ARCH_armv7_LINKER
"${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_suffix}/bin/arm-linux-androideabi-${SWIFT_ANDROID_LINKER_NAME}")

configure_sdk_unix(ANDROID "Android" "android" "android" "armv7" "armv7-none-linux-androideabi" "${SWIFT_ANDROID_SDK_PATH}")

if (NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
Expand All @@ -809,14 +824,6 @@ if(swift_build_android AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
set(SWIFT_PRIMARY_VARIANT_SDK_default "ANDROID")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(_swift_android_prebuilt_suffix "darwin-x86_64")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(_swift_android_prebuilt_suffix "linux-x86_64")
endif()
set(SWIFT_ANDROID_PREBUILT_PATH
"${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_suffix}")
endif()

# Should we cross-compile the standard library for Windows?
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function(_report_sdk prefix)
message(STATUS " Architectures: ${SWIFT_SDK_${prefix}_ARCHITECTURES}")
message(STATUS " Object Format: ${SWIFT_SDK_${prefix}_OBJECT_FORMAT}")
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
if(${SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER})
if(SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER)
message(STATUS " Linker (${arch}): ${SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER}")
else()
message(STATUS " Linker (${arch}): ${CMAKE_LINKER}")
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ foreach(sdk ${ELFISH_SDKS})
set(section_magic_end_obj "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/section_magic_end-${arch_suffix}.dir/swift_sections.S${CMAKE_C_OUTPUT_EXTENSION}")

set(ld_EXECUTABLE ${CMAKE_LINKER})
if(${SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER})
set(ld_EXECUTABLE ${SWIFT_SDK_${prefix}_ARCH_${arch}_LINKER})
if(SWIFT_SDK_${sdk}_ARCH_${arch}_LINKER)
set(ld_EXECUTABLE ${SWIFT_SDK_${sdk}_ARCH_${arch}_LINKER})
endif()

add_custom_command_target(section_magic_${arch_suffix}_begin_object
Expand Down