Skip to content

Commit 62dd6bd

Browse files
vgorloffcompnerd
authored andcommitted
Android build on macOS Cross-Compile host: Fixes wrong Ninja rules generation. (#25576)
* Fixes wrong Ninja rules generation for Android build on macOS Cross-Compile host. * PR review fixes.
1 parent 65d63f1 commit 62dd6bd

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,10 @@ function(_add_swift_library_single target name)
10961096
set_target_properties("${target}"
10971097
PROPERTIES
10981098
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/cygwin")
1099+
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
1100+
# CMake generates incorrect rule `$SONAME_FLAG $INSTALLNAME_DIR$SONAME` for Android build on macOS cross-compile host.
1101+
# Proper linker flags constructed manually. See below variable `swiftlib_link_flags_all`.
1102+
set_target_properties("${target}" PROPERTIES NO_SONAME TRUE)
10991103
endif()
11001104

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

18861900
set(sdk_supported_archs
18871901
${SWIFT_SDK_${sdk}_ARCHITECTURES}

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ macro(swift_common_standalone_build_config_llvm product)
114114
# add_swift_host_library and add_swift_target_library within AddSwift.cmake.
115115
string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
116116
string(REGEX REPLACE "-Wl,-z,nodelete" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
117+
# Android build on macOS cross-compile host don't support `-Wl,-headerpad_max_install_names` and `-dynamiclib` as a linker flags.
118+
string(REGEX REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
119+
string(REGEX REPLACE "-dynamiclib" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}")
117120

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

0 commit comments

Comments
 (0)