@@ -93,18 +93,22 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
93
93
endif ()
94
94
95
95
# System dependencies
96
- find_package (dispatch CONFIG)
97
- if (NOT dispatch_FOUND)
98
- if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
99
- set (DEFAULT_DISPATCH_INCLUDE_PATH "/usr/lib/swift" )
100
- elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
101
- set (DEFAULT_DISPATCH_INCLUDE_PATH "$ENV{SDKROOT} usr/include" )
96
+
97
+ # We know libdispatch is always unavailable on WASI
98
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
99
+ find_package (dispatch CONFIG)
100
+ if (NOT dispatch_FOUND)
101
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
102
+ set (DEFAULT_DISPATCH_INCLUDE_PATH "/usr/lib/swift" )
103
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
104
+ set (DEFAULT_DISPATCH_INCLUDE_PATH "$ENV{SDKROOT} usr/include" )
105
+ endif ()
106
+ set (DISPATCH_INCLUDE_PATH "${DEFAULT_DISPATCH_INCLUDE_PATH} " CACHE STRING "A path to where you can find libdispatch headers" )
107
+ message ("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH} " )
108
+ list (APPEND _Foundation_common_build_flags
109
+ "-I${DISPATCH_INCLUDE_PATH} "
110
+ "-I${DISPATCH_INCLUDE_PATH} /Block" )
102
111
endif ()
103
- set (DISPATCH_INCLUDE_PATH "${DEFAULT_DISPATCH_INCLUDE_PATH} " CACHE STRING "A path to where you can find libdispatch headers" )
104
- message ("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH} " )
105
- list (APPEND _Foundation_common_build_flags
106
- "-I${DISPATCH_INCLUDE_PATH} "
107
- "-I${DISPATCH_INCLUDE_PATH} /Block" )
108
112
endif ()
109
113
find_package (LibXml2 REQUIRED)
110
114
find_package (CURL REQUIRED)
@@ -113,7 +117,6 @@ find_package(CURL REQUIRED)
113
117
list (APPEND _Foundation_common_build_flags
114
118
"-DDEPLOYMENT_RUNTIME_SWIFT"
115
119
"-DCF_BUILDING_CF"
116
- "-DDEPLOYMENT_ENABLE_LIBDISPATCH"
117
120
"-DHAVE_STRUCT_TIMESPEC"
118
121
"-Wno-shorten-64-to-32"
119
122
"-Wno-deprecated-declarations"
@@ -126,16 +129,10 @@ list(APPEND _Foundation_common_build_flags
126
129
"-Wno-switch"
127
130
"-fblocks" )
128
131
129
- if (CMAKE_SYSTEM_NAME STREQUAL "WASI" )
130
- list (APPEND _Foundation_common_build_flags
131
- "-D_WASI_EMULATED_SIGNAL"
132
- "-DHAVE_STRLCPY"
133
- "-DHAVE_STRLCAT"
134
- )
135
- else ()
136
- list (APPEND _Foundation_common_build_flags
137
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
138
- )
132
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
133
+ list (APPEND _Foundation_common_build_flags
134
+ "-DDEPLOYMENT_ENABLE_LIBDISPATCH"
135
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS" )
139
136
endif ()
140
137
141
138
if (NOT "${CMAKE_C_SIMULATE_ID} " STREQUAL "MSVC" )
@@ -168,16 +165,17 @@ list(APPEND _Foundation_swift_build_flags
168
165
"-Xfrontend"
169
166
"-require-explicit-sendable" )
170
167
171
- if (CMAKE_SYSTEM_NAME STREQUAL "WASI" )
172
- list (APPEND _Foundation_swift_build_flags
173
- "-D_WASI_EMULATED_SIGNAL"
174
- "-DHAVE_STRLCPY"
175
- "-DHAVE_STRLCAT"
176
- )
168
+ if (CMAKE_SYSTEM_NAME STREQUAL WASI)
169
+ # Enable wasi-libc emulation features
170
+ set (WASI_EMULATION_DEFS _WASI_EMULATED_MMAN _WASI_EMULATED_SIGNAL _WASI_EMULATED_PROCESS_CLOCKS)
171
+ foreach (def ${WASI_EMULATION_DEFS} )
172
+ list (APPEND _Foundation_swift_build_flags "SHELL:-Xcc -D${def} " )
173
+ list (APPEND _Foundation_common_build_flags "-D${def} " )
174
+ endforeach ()
177
175
else ()
178
- list ( APPEND _Foundation_swift_build_flags
179
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
180
- )
176
+ # Assume we have threads on other platforms
177
+ list ( APPEND _Foundation_swift_build_flags
178
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS" )
181
179
endif ()
182
180
183
181
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
0 commit comments