@@ -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)
0 commit comments