Skip to content
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

[6.0] build: Repair the build on WASI platform #5053

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
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
26 changes: 24 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ list(APPEND _Foundation_common_build_flags
"-DCF_BUILDING_CF"
"-DDEPLOYMENT_ENABLE_LIBDISPATCH"
"-DHAVE_STRUCT_TIMESPEC"
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
"-Wno-shorten-64-to-32"
"-Wno-deprecated-declarations"
"-Wno-unreachable-code"
Expand All @@ -127,6 +126,18 @@ list(APPEND _Foundation_common_build_flags
"-Wno-switch"
"-fblocks")

if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
list(APPEND _Foundation_common_build_flags
"-D_WASI_EMULATED_SIGNAL"
"-DHAVE_STRLCPY"
"-DHAVE_STRLCAT"
)
else()
list(APPEND _Foundation_common_build_flags
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
)
endif()

if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
list(APPEND _Foundation_common_build_flags
"-fconstant-cfstrings"
Expand Down Expand Up @@ -154,10 +165,21 @@ set(_Foundation_swift_build_flags)
list(APPEND _Foundation_swift_build_flags
"-swift-version 6"
"-DDEPLOYMENT_RUNTIME_SWIFT"
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
"-Xfrontend"
"-require-explicit-sendable")

if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
list(APPEND _Foundation_swift_build_flags
"-D_WASI_EMULATED_SIGNAL"
"-DHAVE_STRLCPY"
"-DHAVE_STRLCAT"
)
else()
list(APPEND _Foundation_swift_build_flags
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND _Foundation_common_build_flags
"-D_GNU_SOURCE")
Expand Down
21 changes: 19 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

import PackageDescription

let platformsWithThreads: [Platform] = [
.iOS,
.macOS,
.tvOS,
.watchOS,
.macCatalyst,
.driverKit,
.android,
.linux,
.windows,
]
var dispatchIncludeFlags: [CSetting]
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
dispatchIncludeFlags = [.unsafeFlags([
Expand Down Expand Up @@ -31,8 +42,11 @@ let coreFoundationBuildSettings: [CSetting] = [
.define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
.define("DEPLOYMENT_RUNTIME_SWIFT"),
.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",
Expand Down Expand Up @@ -61,8 +75,11 @@ let interfaceBuildSettings: [CSetting] = [
.define("CF_BUILDING_CF"),
.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",
Expand Down
8 changes: 7 additions & 1 deletion Sources/CoreFoundation/CFBundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreFoundation/CFString.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "CFRuntime_Internal.h"
#include <assert.h>
#include <_foundation_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
Expand Down