Skip to content

Commit 3aec82d

Browse files
committed
Platform: make stdint module implicit on Windows
This makes the `stdint` module implicit which repairs the ability to build some components. In order to accomplish this, we need to potentially break the fragile Swift build system. Due to the incorrect handling of compilers we need some workarounds to support cross-compilation. This removes the injected system header paths when building on Windows to ensure that the clang resource headers are not following the system headers which breaks the modules as the clang resources are dependent on the system headers when running in hosted mode.
1 parent 42a2c2b commit 3aec82d

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,10 @@ function(_add_target_variant_link_flags)
495495
# options. This causes conflicts.
496496
list(APPEND result "-nostdlib")
497497
endif()
498-
swift_windows_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
499-
list(APPEND library_search_directories ${${LFLAGS_ARCH}_LIB})
498+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
499+
swift_windows_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
500+
list(APPEND library_search_directories ${${LFLAGS_ARCH}_LIB})
501+
endif()
500502

501503
# NOTE(compnerd) workaround incorrectly extensioned import libraries from
502504
# the Windows SDK on case sensitive file systems.
@@ -905,10 +907,12 @@ function(add_swift_target_library_single target name)
905907
endif()
906908
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS
907909
-vfsoverlay;"${SWIFT_WINDOWS_VFS_OVERLAY}")
908-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
909-
foreach(directory ${SWIFTLIB_INCLUDE})
910-
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-isystem;-Xcc;${directory})
911-
endforeach()
910+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
911+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
912+
foreach(directory ${SWIFTLIB_INCLUDE})
913+
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-isystem;-Xcc;${directory})
914+
endforeach()
915+
endif()
912916
if("${SWIFTLIB_SINGLE_ARCHITECTURE}" MATCHES arm)
913917
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
914918
endif()
@@ -1071,9 +1075,11 @@ function(add_swift_target_library_single target name)
10711075
SWIFT_INLINE_NAMESPACE=__runtime)
10721076

10731077
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS")
1074-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
1075-
target_include_directories("${target}" SYSTEM PRIVATE
1076-
${SWIFTLIB_INCLUDE})
1078+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
1079+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
1080+
target_include_directories("${target}" SYSTEM PRIVATE
1081+
${SWIFTLIB_INCLUDE})
1082+
endif()
10771083
endif()
10781084

10791085
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS" AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
@@ -1382,10 +1388,12 @@ function(add_swift_target_library_single target name)
13821388

13831389
# Set compilation and link flags.
13841390
if(SWIFTLIB_SINGLE_SDK STREQUAL "WINDOWS")
1385-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE}
1386-
${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE)
1387-
target_include_directories(${target} SYSTEM PRIVATE
1388-
${${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE})
1391+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
1392+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE}
1393+
${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE)
1394+
target_include_directories(${target} SYSTEM PRIVATE
1395+
${${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE})
1396+
endif()
13891397

13901398
if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC")
13911399
swift_windows_get_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY)
@@ -2626,10 +2634,12 @@ function(_add_swift_target_executable_single name)
26262634
llvm_update_compile_flags("${name}")
26272635

26282636
if(SWIFTEXE_SINGLE_SDK STREQUAL "WINDOWS")
2629-
swift_windows_include_for_arch(${SWIFTEXE_SINGLE_ARCHITECTURE}
2630-
${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE)
2631-
target_include_directories(${name} SYSTEM PRIVATE
2632-
${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE})
2637+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
2638+
swift_windows_include_for_arch(${SWIFTEXE_SINGLE_ARCHITECTURE}
2639+
${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE)
2640+
target_include_directories(${name} SYSTEM PRIVATE
2641+
${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE})
2642+
endif()
26332643
if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC")
26342644
# MSVC doesn't support -Xclang. We don't need to manually specify
26352645
# the dependent libraries as `cl` does so.

stdlib/public/Platform/vcruntime.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module vcruntime [system] {
105105
export *
106106
}
107107

108-
explicit module stdint {
108+
module stdint {
109109
header "stdint.h"
110110
export *
111111
}

0 commit comments

Comments
 (0)