Skip to content

Commit e372166

Browse files
authored
Merge pull request #5053 from apple/maxd/6.0-fix-wasi
[6.0] build: Repair the build on WASI platform
2 parents 59e6789 + df11f82 commit e372166

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

CMakeLists.txt

+24-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ list(APPEND _Foundation_common_build_flags
146146
"-DCF_BUILDING_CF"
147147
"-DDEPLOYMENT_ENABLE_LIBDISPATCH"
148148
"-DHAVE_STRUCT_TIMESPEC"
149-
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
150149
"-Wno-shorten-64-to-32"
151150
"-Wno-deprecated-declarations"
152151
"-Wno-unreachable-code"
@@ -158,6 +157,18 @@ list(APPEND _Foundation_common_build_flags
158157
"-Wno-switch"
159158
"-fblocks")
160159

160+
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
161+
list(APPEND _Foundation_common_build_flags
162+
"-D_WASI_EMULATED_SIGNAL"
163+
"-DHAVE_STRLCPY"
164+
"-DHAVE_STRLCAT"
165+
)
166+
else()
167+
list(APPEND _Foundation_common_build_flags
168+
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
169+
)
170+
endif()
171+
161172
if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
162173
list(APPEND _Foundation_common_build_flags
163174
"-fconstant-cfstrings"
@@ -185,10 +196,21 @@ set(_Foundation_swift_build_flags)
185196
list(APPEND _Foundation_swift_build_flags
186197
"-swift-version 6"
187198
"-DDEPLOYMENT_RUNTIME_SWIFT"
188-
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
189199
"-Xfrontend"
190200
"-require-explicit-sendable")
191201

202+
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
203+
list(APPEND _Foundation_swift_build_flags
204+
"-D_WASI_EMULATED_SIGNAL"
205+
"-DHAVE_STRLCPY"
206+
"-DHAVE_STRLCAT"
207+
)
208+
else()
209+
list(APPEND _Foundation_swift_build_flags
210+
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
211+
)
212+
endif()
213+
192214
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
193215
list(APPEND _Foundation_common_build_flags
194216
"-D_GNU_SOURCE")

Package.swift

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
import PackageDescription
55

6+
let platformsWithThreads: [Platform] = [
7+
.iOS,
8+
.macOS,
9+
.tvOS,
10+
.watchOS,
11+
.macCatalyst,
12+
.driverKit,
13+
.android,
14+
.linux,
15+
.windows,
16+
]
617
var dispatchIncludeFlags: [CSetting]
718
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
819
dispatchIncludeFlags = [.unsafeFlags([
@@ -31,8 +42,11 @@ let coreFoundationBuildSettings: [CSetting] = [
3142
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
3243
.define("DEPLOYMENT_RUNTIME_SWIFT"),
3344
.define("HAVE_STRUCT_TIMESPEC"),
34-
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
45+
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
3546
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
47+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
48+
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
49+
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
3650
.unsafeFlags([
3751
"-Wno-shorten-64-to-32",
3852
"-Wno-deprecated-declarations",
@@ -61,8 +75,11 @@ let interfaceBuildSettings: [CSetting] = [
6175
.define("CF_BUILDING_CF"),
6276
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
6377
.define("HAVE_STRUCT_TIMESPEC"),
64-
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
78+
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
6579
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
80+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
81+
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
82+
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
6683
.unsafeFlags([
6784
"-Wno-shorten-64-to-32",
6885
"-Wno-deprecated-declarations",

Sources/CoreFoundation/CFBundle.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,13 @@ static CFBundleRef _CFBundleGetBundleWithIdentifier(CFStringRef bundleID, void *
596596

597597
CFBundleRef CFBundleGetBundleWithIdentifier(CFStringRef bundleID) {
598598
// Use the frame that called this as a hint
599-
return _CFBundleGetBundleWithIdentifier(bundleID, __builtin_return_address(0));
599+
void *hint;
600+
#if TARGET_OS_WASI
601+
hint = NULL;
602+
#else
603+
hint = __builtin_frame_address(0);
604+
#endif
605+
return _CFBundleGetBundleWithIdentifier(bundleID, hint);
600606
}
601607

602608
CFBundleRef _CFBundleGetBundleWithIdentifierWithHint(CFStringRef bundleID, void *pointer) {

Sources/CoreFoundation/CFString.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "CFRuntime_Internal.h"
2929
#include <assert.h>
3030
#include <_foundation_unicode/uchar.h>
31-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
31+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
3232
#include "CFConstantKeys.h"
3333
#include "CFStringLocalizedFormattingInternal.h"
3434
#endif

0 commit comments

Comments
 (0)