Skip to content

Commit 722f466

Browse files
Enable wasi-libc emulation features
Those features require explicit macro definitions to be enabled, so add them to the package definition. Only affects WASI builds.
1 parent 5463e8e commit 722f466

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ foreach(version ${_SwiftFoundation_versions})
104104
endforeach()
105105
endforeach()
106106

107+
# wasi-libc emulation feature flags
108+
set(_SwiftFoundation_wasi_libc_flags)
109+
list(APPEND _SwiftFoundation_wasi_libc_flags
110+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_SIGNAL>"
111+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_MMAN>"
112+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_PROCESS_CLOCKS>")
113+
107114
include(GNUInstallDirs)
108115
include(SwiftFoundationSwiftSupport)
109116

Package.swift

+19-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ var dependencies: [Package.Dependency] {
7070
}
7171
}
7272

73+
let wasiLibcCSettings: [CSetting] = [
74+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
75+
.define("_WASI_EMULATED_MMAN", .when(platforms: [.wasi])),
76+
.define("_WASI_EMULATED_PROCESS_CLOCKS", .when(platforms: [.wasi])),
77+
]
78+
7379
let package = Package(
7480
name: "FoundationPreview",
7581
platforms: [.macOS("13.3"), .iOS("16.4"), .tvOS("16.4"), .watchOS("9.4")],
@@ -88,18 +94,24 @@ let package = Package(
8894
"FoundationEssentials",
8995
"FoundationInternationalization",
9096
],
91-
path: "Sources/Foundation"),
97+
path: "Sources/Foundation",
98+
cSettings: wasiLibcCSettings),
9299

93100
// _FoundationCShims (Internal)
94101
.target(name: "_FoundationCShims",
95102
cSettings: [.define("_CRT_SECURE_NO_WARNINGS",
96103
.when(platforms: [.windows]))]),
97104

98105
// TestSupport (Internal)
99-
.target(name: "TestSupport", dependencies: [
100-
"FoundationEssentials",
101-
"FoundationInternationalization",
102-
], swiftSettings: availabilityMacros + concurrencyChecking),
106+
.target(
107+
name: "TestSupport",
108+
dependencies: [
109+
"FoundationEssentials",
110+
"FoundationInternationalization",
111+
],
112+
cSettings: wasiLibcCSettings,
113+
swiftSettings: availabilityMacros + concurrencyChecking
114+
),
103115

104116
// FoundationEssentials
105117
.target(
@@ -130,7 +142,7 @@ let package = Package(
130142
],
131143
cSettings: [
132144
.define("_GNU_SOURCE", .when(platforms: [.linux]))
133-
],
145+
] + wasiLibcCSettings,
134146
swiftSettings: [
135147
.enableExperimentalFeature("VariadicGenerics"),
136148
.enableExperimentalFeature("AccessLevelOnImport")
@@ -166,6 +178,7 @@ let package = Package(
166178
"CMakeLists.txt",
167179
"Predicate/CMakeLists.txt"
168180
],
181+
cSettings: wasiLibcCSettings,
169182
swiftSettings: [
170183
.enableExperimentalFeature("AccessLevelOnImport")
171184
] + availabilityMacros + concurrencyChecking

Sources/FoundationEssentials/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ target_compile_options(FoundationEssentials PRIVATE
6666
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
6767
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>")
6868
target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_availability_macros})
69+
target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_wasi_libc_flags})
6970
target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundation")
7071

7172
target_link_libraries(FoundationEssentials PUBLIC

Sources/FoundationInternationalization/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ target_compile_options(FoundationInternationalization PRIVATE
3333
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
3434
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>")
3535
target_compile_options(FoundationInternationalization PRIVATE ${_SwiftFoundation_availability_macros})
36+
target_compile_options(FoundationInternationalization PRIVATE ${_SwiftFoundation_wasi_libc_flags})
3637
target_compile_options(FoundationInternationalization PRIVATE -package-name "SwiftFoundation")
3738

3839
target_link_libraries(FoundationInternationalization PUBLIC

0 commit comments

Comments
 (0)