Skip to content

Commit 8f876cf

Browse files
authored
Merge pull request #37721 from gottesmm/pr-a29fee875eff61d38bd51f7fff8c622eaf3d526e
[cmake] Work around a bug in the swift-driver by passing host side libraries from LLVMSupport to linker jobs via a -Xlinker flag.
2 parents 66c4ace + 4a189d8 commit 8f876cf

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,49 @@ macro(swift_common_standalone_build_config_llvm product)
9898
endif()
9999

100100
if(LLVM_ENABLE_ZLIB)
101-
find_package(ZLIB REQUIRED)
101+
find_package(ZLIB REQUIRED)
102+
endif()
103+
104+
# Work around a bug in the swift-driver that causes the swift-driver to not be
105+
# able to accept .tbd files when linking without passing in the .tbd file with
106+
# a -Xlinker flag.
107+
#
108+
# Both clang and swiftc can accept an -Xlinker flag so we use that to pass the
109+
# value.
110+
if (APPLE)
111+
get_target_property(LLVMSUPPORT_INTERFACE_LINK_LIBRARIES LLVMSupport INTERFACE_LINK_LIBRARIES)
112+
get_target_property(LLVMSUPPORT_INTERFACE_LINK_OPTIONS LLVMSupport INTERFACE_LINK_OPTIONS)
113+
set(new_libraries)
114+
set(new_options)
115+
if (LLVMSUPPORT_INTERFACE_LINK_OPTIONS)
116+
set(new_options ${LLVMSUPPORT_INTERFACE_LINK_OPTIONS})
117+
endif()
118+
foreach(lib ${LLVMSUPPORT_INTERFACE_LINK_LIBRARIES})
119+
# The reason why we also fix link libraries that are specified as a full
120+
# target is since those targets can still be a tbd file.
121+
#
122+
# Example: ZLIB::ZLIB's library path is defined by
123+
# ZLIB_LIBRARY_{DEBUG,RELEASE} which can on Darwin have a tbd file as a
124+
# value. So we need to work around this until we get a newer swiftc that
125+
# can accept a .tbd file.
126+
if (TARGET ${lib})
127+
list(APPEND new_options "LINKER:$<TARGET_FILE:${lib}>")
128+
continue()
129+
endif()
130+
131+
# If we have an interface library dependency that is just a path to a tbd
132+
# file, pass the tbd file via -Xlinker so it gets straight to the linker.
133+
get_filename_component(LIB_FILENAME_COMPONENT ${lib} LAST_EXT)
134+
if ("${LIB_FILENAME_COMPONENT}" STREQUAL ".tbd")
135+
list(APPEND new_options "LINKER:${lib}")
136+
continue()
137+
endif()
138+
139+
list(APPEND new_libraries "${lib}")
140+
endforeach()
141+
142+
set_target_properties(LLVMSupport PROPERTIES INTERFACE_LINK_LIBRARIES "${new_libraries}")
143+
set_target_properties(LLVMSupport PROPERTIES INTERFACE_LINK_OPTIONS "${new_options}")
102144
endif()
103145

104146
include(AddLLVM)

tools/libSwiftSyntaxParser/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ set(LLVM_EXPORTED_SYMBOL_FILE
99

1010
add_swift_host_library(libSwiftSyntaxParser SHARED
1111
c-include-check.c
12-
libSwiftSyntaxParser.cpp)
12+
libSwiftSyntaxParser.cpp
13+
LLVM_LINK_COMPONENTS support)
1314
if(NOT SWIFT_BUILT_STANDALONE AND NOT CMAKE_C_COMPILER_ID MATCHES Clang)
1415
add_dependencies(libSwiftSyntaxParser clang)
1516
endif()

tools/swift-refactor/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_swift_host_tool(swift-refactor
22
swift-refactor.cpp
33
SWIFT_COMPONENT tools
4+
LLVM_LINK_COMPONENTS support
45
)
56
target_link_libraries(swift-refactor
67
PRIVATE

0 commit comments

Comments
 (0)