|
| 1 | +From acdc7e138ff67f02c261bb6372f755c2fdb6bc7b Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yuta Saito < [email protected]> |
| 3 | +Date: Sat, 30 Mar 2024 10:28:40 +0000 |
| 4 | +Subject: [PATCH] build: Repair the build on WASI platform |
| 5 | + |
| 6 | +Cherry picked from https://github.com/apple/swift-corelibs-foundation/pull/4934 |
| 7 | + |
| 8 | +(cherry picked from commit 51ee6906be0556eb63cd35a16ad4167f69f16a63) |
| 9 | +--- |
| 10 | + Package.swift | 20 ++++++++++++++++++-- |
| 11 | + Sources/CoreFoundation/CFBundle.c | 8 +++++++- |
| 12 | + Sources/CoreFoundation/CFString.c | 2 +- |
| 13 | + 3 files changed, 26 insertions(+), 4 deletions(-) |
| 14 | + |
| 15 | +diff --git a/Package.swift b/Package.swift |
| 16 | +index 4ead01c3..8aa40e79 100644 |
| 17 | +--- a/Package.swift |
| 18 | ++++ b/Package.swift |
| 19 | +@@ -3,6 +3,16 @@ |
| 20 | + |
| 21 | + import PackageDescription |
| 22 | + |
| 23 | ++let platformsWithThreads: [Platform] = [ |
| 24 | ++ .iOS, |
| 25 | ++ .macOS, |
| 26 | ++ .tvOS, |
| 27 | ++ .watchOS, |
| 28 | ++ .macCatalyst, |
| 29 | ++ .driverKit, |
| 30 | ++ .android, |
| 31 | ++ .linux, |
| 32 | ++] |
| 33 | + var dispatchIncludeFlags: [CSetting] |
| 34 | + if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] { |
| 35 | + dispatchIncludeFlags = [.unsafeFlags([ |
| 36 | +@@ -31,8 +41,11 @@ let coreFoundationBuildSettings: [CSetting] = [ |
| 37 | + .define("DEPLOYMENT_ENABLE_LIBDISPATCH"), |
| 38 | + .define("DEPLOYMENT_RUNTIME_SWIFT"), |
| 39 | + .define("HAVE_STRUCT_TIMESPEC"), |
| 40 | +- .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"), |
| 41 | ++ .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)), |
| 42 | + .define("_GNU_SOURCE", .when(platforms: [.linux, .android])), |
| 43 | ++ .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])), |
| 44 | ++ .define("HAVE_STRLCPY", .when(platforms: [.wasi])), |
| 45 | ++ .define("HAVE_STRLCAT", .when(platforms: [.wasi])), |
| 46 | + .unsafeFlags([ |
| 47 | + "-Wno-shorten-64-to-32", |
| 48 | + "-Wno-deprecated-declarations", |
| 49 | +@@ -61,8 +74,11 @@ let interfaceBuildSettings: [CSetting] = [ |
| 50 | + .define("CF_BUILDING_CF"), |
| 51 | + .define("DEPLOYMENT_ENABLE_LIBDISPATCH"), |
| 52 | + .define("HAVE_STRUCT_TIMESPEC"), |
| 53 | +- .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"), |
| 54 | ++ .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)), |
| 55 | + .define("_GNU_SOURCE", .when(platforms: [.linux, .android])), |
| 56 | ++ .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])), |
| 57 | ++ .define("HAVE_STRLCPY", .when(platforms: [.wasi])), |
| 58 | ++ .define("HAVE_STRLCAT", .when(platforms: [.wasi])), |
| 59 | + .unsafeFlags([ |
| 60 | + "-Wno-shorten-64-to-32", |
| 61 | + "-Wno-deprecated-declarations", |
| 62 | +diff --git a/Sources/CoreFoundation/CFBundle.c b/Sources/CoreFoundation/CFBundle.c |
| 63 | +index 8026a262..05afe988 100644 |
| 64 | +--- a/Sources/CoreFoundation/CFBundle.c |
| 65 | ++++ b/Sources/CoreFoundation/CFBundle.c |
| 66 | +@@ -596,7 +596,13 @@ static CFBundleRef _CFBundleGetBundleWithIdentifier(CFStringRef bundleID, void * |
| 67 | + |
| 68 | + CFBundleRef CFBundleGetBundleWithIdentifier(CFStringRef bundleID) { |
| 69 | + // Use the frame that called this as a hint |
| 70 | +- return _CFBundleGetBundleWithIdentifier(bundleID, __builtin_return_address(0)); |
| 71 | ++ void *hint; |
| 72 | ++#if TARGET_OS_WASI |
| 73 | ++ hint = NULL; |
| 74 | ++#else |
| 75 | ++ hint = __builtin_frame_address(0); |
| 76 | ++#endif |
| 77 | ++ return _CFBundleGetBundleWithIdentifier(bundleID, hint); |
| 78 | + } |
| 79 | + |
| 80 | + CFBundleRef _CFBundleGetBundleWithIdentifierWithHint(CFStringRef bundleID, void *pointer) { |
| 81 | +diff --git a/Sources/CoreFoundation/CFString.c b/Sources/CoreFoundation/CFString.c |
| 82 | +index 1de46dac..94a6c86d 100644 |
| 83 | +--- a/Sources/CoreFoundation/CFString.c |
| 84 | ++++ b/Sources/CoreFoundation/CFString.c |
| 85 | +@@ -28,7 +28,7 @@ |
| 86 | + #include "CFRuntime_Internal.h" |
| 87 | + #include <assert.h> |
| 88 | + #include <_foundation_unicode/uchar.h> |
| 89 | +-#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD |
| 90 | ++#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI |
| 91 | + #include "CFConstantKeys.h" |
| 92 | + #include "CFStringLocalizedFormattingInternal.h" |
| 93 | + #endif |
| 94 | +-- |
| 95 | +2.46.0 |
| 96 | + |
0 commit comments