Skip to content

Commit 51ee690

Browse files
kateinoigakukunMaxDesiatov
authored andcommitted
build: Repair the build on WASI platform
Cherry picked from #4934
1 parent 9d1a846 commit 51ee690

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Package.swift

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
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+
]
616
var dispatchIncludeFlags: [CSetting]
717
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
818
dispatchIncludeFlags = [.unsafeFlags([
@@ -31,8 +41,11 @@ let coreFoundationBuildSettings: [CSetting] = [
3141
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
3242
.define("DEPLOYMENT_RUNTIME_SWIFT"),
3343
.define("HAVE_STRUCT_TIMESPEC"),
34-
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
44+
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
3545
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
46+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
47+
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
48+
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
3649
.unsafeFlags([
3750
"-Wno-shorten-64-to-32",
3851
"-Wno-deprecated-declarations",
@@ -61,8 +74,11 @@ let interfaceBuildSettings: [CSetting] = [
6174
.define("CF_BUILDING_CF"),
6275
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
6376
.define("HAVE_STRUCT_TIMESPEC"),
64-
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
77+
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
6578
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
79+
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
80+
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
81+
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
6682
.unsafeFlags([
6783
"-Wno-shorten-64-to-32",
6884
"-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)