Skip to content

build: Repair the build on WASI platform #4934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -3,19 +3,32 @@

import PackageDescription

let platformsWithThreads: [Platform] = [
.iOS,
.macOS,
.tvOS,
.watchOS,
.macCatalyst,
.driverKit,
.android,
.linux,
]
let buildSettings: [CSetting] = [
.headerSearchPath("internalInclude"),
.define("DEBUG", .when(configuration: .debug)),
.define("CF_BUILDING_CF"),
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
.define("HAVE_STRUCT_TIMESPEC"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
.define("CF_CHARACTERSET_UNICODE_DATA_L", to: "\"\(Context.packageDirectory)/Sources/CoreFoundation/CFUnicodeData-L.mapping\""),
.define("CF_CHARACTERSET_UNICODE_DATA_B", to: "\"\(Context.packageDirectory)/Sources/CoreFoundation/CFUnicodeData-B.mapping\""),
.define("CF_CHARACTERSET_UNICHAR_DB", to: "\"\(Context.packageDirectory)/Sources/CoreFoundation/CFUniCharPropertyDatabase.data\""),
.define("CF_CHARACTERSET_BITMAP", to: "\"\(Context.packageDirectory)/Sources/CoreFoundation/CFCharacterSetBitmaps.bitmap\""),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
.unsafeFlags([
"-Wno-shorten-64-to-32",
"-Wno-deprecated-declarations",
@@ -43,8 +56,11 @@ let interfaceBuildSettings: [CSetting] = [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
.define("HAVE_STRUCT_TIMESPEC"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
.define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
.define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
.define("HAVE_STRLCPY", .when(platforms: [.wasi])),
.define("HAVE_STRLCAT", .when(platforms: [.wasi])),
.unsafeFlags([
"-Wno-shorten-64-to-32",
"-Wno-deprecated-declarations",
@@ -90,7 +106,10 @@ let package = Package(
"_CoreFoundation"
],
path: "Sources/Foundation",
swiftSettings: [.define("DEPLOYMENT_RUNTIME_SWIFT"), .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS")]
swiftSettings: [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads))
]
),
.target(
name: "FoundationXML",
@@ -101,7 +120,10 @@ let package = Package(
"_CFXMLInterface"
],
path: "Sources/FoundationXML",
swiftSettings: [.define("DEPLOYMENT_RUNTIME_SWIFT"), .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS")]
swiftSettings: [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads))
]
),
.target(
name: "FoundationNetworking",
@@ -112,7 +134,10 @@ let package = Package(
"_CFURLSessionInterface"
],
path: "Sources/FoundationNetworking",
swiftSettings: [.define("DEPLOYMENT_RUNTIME_SWIFT"), .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS")]
swiftSettings: [
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads))
]
),
.target(
name: "_CoreFoundation",
8 changes: 7 additions & 1 deletion Sources/CoreFoundation/CFBundle.c
Original file line number Diff line number Diff line change
@@ -596,7 +596,13 @@ static CFBundleRef _CFBundleGetBundleWithIdentifier(CFStringRef bundleID, void *

CFBundleRef CFBundleGetBundleWithIdentifier(CFStringRef bundleID) {
// Use the frame that called this as a hint
return _CFBundleGetBundleWithIdentifier(bundleID, __builtin_return_address(0));
void *hint;
#if TARGET_OS_WASI
hint = NULL;
#else
hint = __builtin_frame_address(0);
#endif
return _CFBundleGetBundleWithIdentifier(bundleID, hint);
}

CFBundleRef _CFBundleGetBundleWithIdentifierWithHint(CFStringRef bundleID, void *pointer) {
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/CFString.c
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
#include "CFRuntime_Internal.h"
#include <assert.h>
#include <unicode/uchar.h>
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
#include "CFConstantKeys.h"
#include "CFStringLocalizedFormattingInternal.h"
#endif