Skip to content

[Android] Enable building static stdlib on macOS #4972

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

Merged
merged 1 commit into from
Oct 17, 2016
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
39 changes: 22 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -566,23 +566,6 @@ if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
endif()

# Compatible cross-compile SDKS for LINUX: ANDROID (arch always armv7)
is_sdk_requested(ANDROID swift_build_android)
if("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
set(swift_can_crosscompile_stdlib_android FALSE)
else()
set(swift_can_crosscompile_stdlib_android TRUE)
endif()

if(swift_build_android AND ${swift_can_crosscompile_stdlib_android})
configure_sdk_unix(ANDROID "Android" "android" "android" "armv7" "armv7-none-linux-androideabi" "${SWIFT_ANDROID_SDK_PATH}")
# If we're not building for the host, the cross-compiled target should be the 'primary variant'.
if("${swift_build_linux}" STREQUAL "FALSE")
set(SWIFT_PRIMARY_VARIANT_SDK_default "ANDROID")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
endif()
endif()

elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "FREEBSD")

set(CMAKE_EXECUTABLE_FORMAT "ELF")
Expand Down Expand Up @@ -727,6 +710,28 @@ if("${SWIFT_PRIMARY_VARIANT_ARCH}" STREQUAL "")
set(SWIFT_PRIMARY_VARIANT_ARCH "${SWIFT_PRIMARY_VARIANT_ARCH_default}")
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 "")
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"))
message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
elseif(("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT swift_build_osx) OR
("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT swift_build_linux))
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?
is_sdk_requested(WINDOWS swift_build_windows)
if(swift_build_windows)
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function(_add_variant_c_compile_link_flags)
list(APPEND result
"--sysroot=${SWIFT_ANDROID_SDK_PATH}"
# Use the linker included in the Android NDK.
"-B" "${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/linux-x86_64/arm-linux-androideabi/bin/")
"-B" "${SWIFT_ANDROID_PREBUILT_PATH}/arm-linux-androideabi/bin/")
endif()

if("${CFLAGS_SDK}" STREQUAL "WINDOWS")
Expand Down Expand Up @@ -315,7 +315,7 @@ function(_add_variant_link_flags)
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
list(APPEND result
"-ldl"
"-L${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x"
"-L${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x"
"${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so")
else()
list(APPEND result "-lobjc")
Expand Down