Skip to content

Android build on macOS Cross-Compile host: Fixes wrong Ninja rules generation. #25576

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 2 commits into from
Jun 22, 2019
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
14 changes: 14 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,10 @@ function(_add_swift_library_single target name)
set_target_properties("${target}"
PROPERTIES
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/cygwin")
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
# CMake generates incorrect rule `$SONAME_FLAG $INSTALLNAME_DIR$SONAME` for Android build on macOS cross-compile host.
# Proper linker flags constructed manually. See below variable `swiftlib_link_flags_all`.
set_target_properties("${target}" PROPERTIES NO_SONAME TRUE)
endif()

set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)
Expand Down Expand Up @@ -1882,6 +1886,16 @@ function(add_swift_target_library name)
NOT ${name} STREQUAL swiftRemoteMirror)
list(APPEND swiftlib_link_flags_all "-Wl,-z,defs")
endif()
# Setting back linker flags which are not supported when making Android build on macOS cross-compile host.
if(SWIFTLIB_SHARED)
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
list(APPEND swiftlib_link_flags_all "-dynamiclib -Wl,-headerpad_max_install_names")
elseif(sdk STREQUAL ANDROID)
list(APPEND swiftlib_link_flags_all "-shared")
# TODO: Instead of `lib${name}.so` find variable or target property which already have this value.
list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so")
endif()
endif()

set(sdk_supported_archs
${SWIFT_SDK_${sdk}_ARCHITECTURES}
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/SwiftSharedCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ macro(swift_common_standalone_build_config_llvm product)
# add_swift_host_library and add_swift_target_library within AddSwift.cmake.
string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
string(REGEX REPLACE "-Wl,-z,nodelete" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
# Android build on macOS cross-compile host don't support `-Wl,-headerpad_max_install_names` and `-dynamiclib` as a linker flags.
string(REGEX REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
string(REGEX REPLACE "-dynamiclib" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")

set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" PACKAGE_VERSION_MAJOR
Expand Down