Skip to content

Commit add6699

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 eebec9d commit add6699

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
@@ -491,8 +491,10 @@ function(_add_target_variant_link_flags)
491491
# options. This causes conflicts.
492492
list(APPEND result "-nostdlib")
493493
endif()
494-
swift_windows_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
495-
list(APPEND library_search_directories ${${LFLAGS_ARCH}_LIB})
494+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
495+
swift_windows_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
496+
list(APPEND library_search_directories ${${LFLAGS_ARCH}_LIB})
497+
endif()
496498

497499
# NOTE(compnerd) workaround incorrectly extensioned import libraries from
498500
# the Windows SDK on case sensitive file systems.
@@ -894,10 +896,12 @@ function(add_swift_target_library_single target name)
894896
endif()
895897
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS
896898
-vfsoverlay;"${SWIFT_WINDOWS_VFS_OVERLAY}")
897-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
898-
foreach(directory ${SWIFTLIB_INCLUDE})
899-
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-isystem;-Xcc;${directory})
900-
endforeach()
899+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
900+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
901+
foreach(directory ${SWIFTLIB_INCLUDE})
902+
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-isystem;-Xcc;${directory})
903+
endforeach()
904+
endif()
901905
if("${SWIFTLIB_SINGLE_ARCHITECTURE}" MATCHES arm)
902906
list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
903907
endif()
@@ -1059,9 +1063,11 @@ function(add_swift_target_library_single target name)
10591063
SWIFT_INLINE_NAMESPACE=__runtime)
10601064

10611065
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS")
1062-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
1063-
target_include_directories("${target}" SYSTEM PRIVATE
1064-
${SWIFTLIB_INCLUDE})
1066+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
1067+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE)
1068+
target_include_directories("${target}" SYSTEM PRIVATE
1069+
${SWIFTLIB_INCLUDE})
1070+
endif()
10651071
endif()
10661072

10671073
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS" AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
@@ -1370,10 +1376,12 @@ function(add_swift_target_library_single target name)
13701376

13711377
# Set compilation and link flags.
13721378
if(SWIFTLIB_SINGLE_SDK STREQUAL WINDOWS)
1373-
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE}
1374-
${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE)
1375-
target_include_directories(${target} SYSTEM PRIVATE
1376-
${${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE})
1379+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
1380+
swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE}
1381+
${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE)
1382+
target_include_directories(${target} SYSTEM PRIVATE
1383+
${${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE})
1384+
endif()
13771385

13781386
if(NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
13791387
swift_windows_get_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY)
@@ -2614,10 +2622,12 @@ function(_add_swift_target_executable_single name)
26142622
llvm_update_compile_flags("${name}")
26152623

26162624
if(SWIFTEXE_SINGLE_SDK STREQUAL WINDOWS)
2617-
swift_windows_include_for_arch(${SWIFTEXE_SINGLE_ARCHITECTURE}
2618-
${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE)
2619-
target_include_directories(${name} SYSTEM PRIVATE
2620-
${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE})
2625+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
2626+
swift_windows_include_for_arch(${SWIFTEXE_SINGLE_ARCHITECTURE}
2627+
${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE)
2628+
target_include_directories(${name} SYSTEM PRIVATE
2629+
${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE})
2630+
endif()
26212631
if(NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
26222632
# MSVC doesn't support -Xclang. We don't need to manually specify
26232633
# 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)