Skip to content

Commit 577b272

Browse files
authored
Merge pull request #13140 from troughton/windows-cross-compile-fixes
2 parents 50103cd + 5173e3c commit 577b272

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ function(_add_swift_library_single target name)
792792
swift_windows_generate_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS)
793793
foreach(flag ${SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS})
794794
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;${flag})
795+
list(APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS ${flag})
795796
endforeach()
796797
foreach(directory ${SWIFTLIB_INCLUDE})
797798
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xfrontend;-I${directory})
@@ -1719,6 +1720,19 @@ function(add_swift_library name)
17191720
endif()
17201721
endif()
17211722

1723+
# We unconditionally removed "-z,defs" from CMAKE_SHARED_LINKER_FLAGS in
1724+
# swift_common_standalone_build_config_llvm within SwiftSharedCMakeConfig.cmake,
1725+
# where it was added by a call to HandleLLVMOptions.
1726+
#
1727+
# Rather than applying it to all targets and libraries, we here add it back to
1728+
# supported targets and libraries only.
1729+
# This is needed for ELF targets only; however, RemoteMirror needs to build
1730+
# with undefined symbols.
1731+
if("${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF"
1732+
AND NOT "${name}" STREQUAL "swiftRemoteMirror")
1733+
list(APPEND swiftlib_link_flags_all "-Wl,-z,defs")
1734+
endif()
1735+
17221736
# Add this library variant.
17231737
_add_swift_library_single(
17241738
${VARIANT_NAME}

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
7878
include(AddSwiftTableGen) # This imports TableGen from LLVM.
7979
include(HandleLLVMOptions)
8080

81-
# HACK: this ugly tweaking is to prevent the propagation of the flag from LLVM
82-
# into swift. The use of this flag pollutes all targets, and we are not able
83-
# to remove it on a per-target basis which breaks cross-compilation.
81+
# HACK: Not all targets support -z,defs as a linker flag.
82+
#
83+
# Normally, LLVM would only add it as an option for known ELF targets;
84+
# however, due to the custom scheme Swift uses for cross-compilation, the
85+
# CMAKE_SHARED_LINKER_FLAGS are determined based on the host system and
86+
# then applied to all targets. This causes issues in cross-compiling to
87+
# Windows from a Linux host.
88+
#
89+
# To work around this, we unconditionally remove the flag here and then
90+
# selectively add it to the per-target link flags; this is currently done
91+
# in add_swift_library within AddSwift.cmake.
8492
string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
8593

8694
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")

stdlib/public/SwiftRemoteMirror/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# HACK: Force this library to build with undefined symbols.
2-
string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
3-
41
# libswiftRemoteMirror.dylib should not have runtime dependencies; it's
52
# always built as a shared library.
63
if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)

0 commit comments

Comments
 (0)