Skip to content

Commit 3225e36

Browse files
committed
stdlib: reorder add_subdirectory to repair the Windows build
Due to the horrible attrocities against software of the attempt to perform cross-compilation in the swift build system, we need to emulate the linking behaviour for Windows with the link against the import library. The emulation requires the custom creation of import library targets. In order to actually get the linking semantics correct, the dependendency targets must be created prior to use (unlike standard CMake). The reordering ensures that we get correct linkage when building for Windows. Perform a simple optimization to avoid a number of string comparisions for the host system.
1 parent b875dca commit 3225e36

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ function(_add_swift_library_single target name)
12731273
# doing so will result in incorrect symbol resolution and linkage. We created
12741274
# import library targets when the library was added. Use that to adjust the
12751275
# link libraries.
1276-
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS")
1276+
if(SWIFTLIB_SINGLE_SDK STREQUAL WINDOWS AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
12771277
foreach(library_list LINK_LIBRARIES INTERFACE_LINK_LIBRARIES PRIVATE_LINK_LIBRARIES)
12781278
set(import_libraries)
12791279
foreach(library ${SWIFTLIB_SINGLE_${library_list}})
@@ -1283,7 +1283,7 @@ function(_add_swift_library_single target name)
12831283
# libraries are only associated with shared libraries, so add an
12841284
# additional check for that as well.
12851285
set(import_library ${library})
1286-
if(TARGET ${library} AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
1286+
if(TARGET ${library})
12871287
get_target_property(type ${library} TYPE)
12881288
if(${type} STREQUAL "SHARED_LIBRARY")
12891289
set(import_library ${library}_IMPLIB)

stdlib/private/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ if(SWIFT_BUILD_SDK_OVERLAY)
66
# SwiftPrivateThreadExtras makes use of Darwin/Glibc, which is part of the
77
# SDK overlay. It can't be built separately from the SDK overlay.
88
add_subdirectory(RuntimeUnittest)
9-
add_subdirectory(StdlibUnittest)
109
add_subdirectory(StdlibUnicodeUnittest)
1110
add_subdirectory(StdlibCollectionUnittest)
1211
add_subdirectory(SwiftPrivateLibcExtras)
1312
add_subdirectory(SwiftPrivateThreadExtras)
1413

14+
# NOTE(compnerd) this must come after SwiftPrivateLibcExtras and
15+
# SwiftPrivateThreadExtras to ensure that the dependency targets are setup in
16+
# the correct order for Windows.
17+
add_subdirectory(StdlibUnittest)
18+
1519
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1620
add_subdirectory(StdlibUnittestFoundationExtras)
1721
if (SWIFT_INCLUDE_TESTS)

0 commit comments

Comments
 (0)