Skip to content

Commit b1c8382

Browse files
authored
Merge pull request #83732 from compnerd/sychronize
Synchronization: repair the build on Windows i686
2 parents 7a196ac + 9339a9d commit b1c8382

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Runtimes/Supplemental/Synchronization/CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,45 @@ target_link_libraries(swiftSynchronization PRIVATE
141141
$<$<PLATFORM_ID:Darwin>:swiftDarwin>
142142
$<$<PLATFORM_ID:Windows>:ClangModules>)
143143

144+
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
145+
# FIXME(#83765) `-whole-module-optimization` should not be needed. However,
146+
# without this, we will not properly optimize. On Windows i686 in particular,
147+
# we observe the formation of `__atomic_load` calls rather than the expected
148+
# native sequence.
149+
cmake_policy(GET CMP0157 _PolicyCMP0157)
150+
if(_PolicyCMP0157 STREQUAL NEW)
151+
set_target_properties(swiftSynchronization PROPERTIES
152+
Swift_COMPILATION_MODE wholemodule)
153+
else()
154+
target_compile_options(swiftSynchronization PRIVATE
155+
$<$<COMPILE_LANGUAGE:Swift>:-whole-module-optimization>)
156+
endif()
157+
158+
# WMO requires the early-swift-driver to be usable, which is not yet ready on
159+
# Windows. Workaround this by creating an empty stub for swiftCore, removing
160+
# the import library from the command line, and adding the library search path
161+
# associated with it. Due to the autolink, we will still link against the
162+
# library from the correct location but will also use an empty file for the
163+
# additional input allowing us to perform the WMO.
164+
if(CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
165+
get_target_property(_swiftCore_IMPORTED_IMPLIB_RELEASE swiftCore
166+
IMPORTED_IMPLIB_RELEASE)
167+
if(_swiftCore_IMPORTED_IMPLIB_RELEASE)
168+
# Compute the library directory to allow us to find the import library by
169+
# name.
170+
get_filename_component(_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME
171+
${_swiftCore_IMPORTED_IMPLIB_RELEASE} DIRECTORY)
172+
# Create a (empty) stub library
173+
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib")
174+
# Replace the import library with a stub to bypass the driver and frontend.
175+
# Add the library search path to allow linking via autolinking.
176+
set_target_properties(swiftCore PROPERTIES
177+
IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/swiftCoreStub.lib"
178+
INTERFACE_LINK_DIRECTORIES ${_swiftCore_IMPORTED_IMPLIB_RELEASE_DIRNAME})
179+
endif()
180+
endif()
181+
endif()
182+
144183
install(TARGETS swiftSynchronization
145184
EXPORT SwiftSynchronizationTargets
146185
COMPONENT ${PROJECT_NAME}_runtime

0 commit comments

Comments
 (0)