Skip to content

Commit 0264b75

Browse files
Fix conflict
1 parent 3ab0a59 commit 0264b75

File tree

29 files changed

+1322
-1469
lines changed

29 files changed

+1322
-1469
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From 4db45e0b9c75e3a6ac31cf45a06018592af381f5 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 6d660388..4949fe4e 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.43.2
96+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
From f8c20b56988da0f649c1645dd4e0ea18af739b95 Mon Sep 17 00:00:00 2001
2+
From: Max Desiatov <[email protected]>
3+
Date: Mon, 5 Aug 2024 20:28:46 +0100
4+
Subject: [PATCH] Reflect `Package.swift` WASI changes in `CMakeLists.txt`
5+
6+
---
7+
CMakeLists.txt | 26 ++++++++++++++++++++++++--
8+
1 file changed, 24 insertions(+), 2 deletions(-)
9+
10+
diff --git a/CMakeLists.txt b/CMakeLists.txt
11+
index 7f290d16..1fbdee6a 100644
12+
--- a/CMakeLists.txt
13+
+++ b/CMakeLists.txt
14+
@@ -146,7 +146,6 @@ list(APPEND _Foundation_common_build_flags
15+
"-DCF_BUILDING_CF"
16+
"-DDEPLOYMENT_ENABLE_LIBDISPATCH"
17+
"-DHAVE_STRUCT_TIMESPEC"
18+
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
19+
"-Wno-shorten-64-to-32"
20+
"-Wno-deprecated-declarations"
21+
"-Wno-unreachable-code"
22+
@@ -158,6 +157,18 @@ list(APPEND _Foundation_common_build_flags
23+
"-Wno-switch"
24+
"-fblocks")
25+
26+
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
27+
+ list(APPEND _Foundation_common_build_flags
28+
+ "-D_WASI_EMULATED_SIGNAL"
29+
+ "-DHAVE_STRLCPY"
30+
+ "-DHAVE_STRLCAT"
31+
+ )
32+
+else()
33+
+ list(APPEND _Foundation_common_build_flags
34+
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
35+
+ )
36+
+endif()
37+
+
38+
if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
39+
list(APPEND _Foundation_common_build_flags
40+
"-fconstant-cfstrings"
41+
@@ -185,10 +196,21 @@ set(_Foundation_swift_build_flags)
42+
list(APPEND _Foundation_swift_build_flags
43+
"-swift-version 6"
44+
"-DDEPLOYMENT_RUNTIME_SWIFT"
45+
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
46+
"-Xfrontend"
47+
"-require-explicit-sendable")
48+
49+
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
50+
+ list(APPEND _Foundation_swift_build_flags
51+
+ "-D_WASI_EMULATED_SIGNAL"
52+
+ "-DHAVE_STRLCPY"
53+
+ "-DHAVE_STRLCAT"
54+
+ )
55+
+else()
56+
+ list(APPEND _Foundation_swift_build_flags
57+
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
58+
+ )
59+
+endif()
60+
+
61+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
62+
list(APPEND _Foundation_common_build_flags
63+
"-D_GNU_SOURCE")
64+
--
65+
2.43.2
66+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 0c954d9de286e15204240722d717e1928e165cbb Mon Sep 17 00:00:00 2001
2+
From: Max Desiatov <[email protected]>
3+
Date: Mon, 5 Aug 2024 20:16:22 +0100
4+
Subject: [PATCH] Add `.windows` to `platformsWithThreads` in `Package.swift`
5+
6+
(cherry picked from commit bc0dd484adbabdb978e68cf6905e3b44ca5117bd)
7+
---
8+
Package.swift | 1 +
9+
1 file changed, 1 insertion(+)
10+
11+
diff --git a/Package.swift b/Package.swift
12+
index 4949fe4e..aca50e80 100644
13+
--- a/Package.swift
14+
+++ b/Package.swift
15+
@@ -12,6 +12,7 @@ let platformsWithThreads: [Platform] = [
16+
.driverKit,
17+
.android,
18+
.linux,
19+
+ .windows,
20+
]
21+
var dispatchIncludeFlags: [CSetting]
22+
if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
23+
--
24+
2.43.2
25+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 278d6ffde7788d16455f5dbcef9400b75f849adf Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Wed, 7 Aug 2024 05:10:42 +0000
4+
Subject: [PATCH] [CMake] Use LIBXML2_INCLUDE_DIR instead of hardcoding
5+
/usr/include/libxml2
6+
7+
`find_package(LibXml2 REQUIRED)` sets `LIBXML2_INCLUDE_DIR` to the correct
8+
include directory for the libxml2 headers. Use this variable instead of
9+
hardcoding `/usr/include/libxml2`. This allows the build to work with
10+
custom libxml2 builds on WASI.
11+
---
12+
Sources/_CFXMLInterface/CMakeLists.txt | 2 +-
13+
1 file changed, 1 insertion(+), 1 deletion(-)
14+
15+
diff --git a/Sources/_CFXMLInterface/CMakeLists.txt b/Sources/_CFXMLInterface/CMakeLists.txt
16+
index d6e63a3f..d550a520 100644
17+
--- a/Sources/_CFXMLInterface/CMakeLists.txt
18+
+++ b/Sources/_CFXMLInterface/CMakeLists.txt
19+
@@ -20,7 +20,7 @@ target_include_directories(_CFXMLInterface
20+
../CoreFoundation/include
21+
PRIVATE
22+
../CoreFoundation/internalInclude
23+
- /usr/include/libxml2/)
24+
+ ${LIBXML2_INCLUDE_DIR})
25+
26+
target_compile_options(_CFXMLInterface INTERFACE
27+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>"
28+
--
29+
2.43.2
30+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
From 7e4cdc1b0163c1a3afdd35da87d4f25b50aa22be Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Wed, 7 Aug 2024 05:13:38 +0000
4+
Subject: [PATCH] [CMake] Disable libdispatch & threads, enable some emulations
5+
on WASI
6+
7+
This commit disables libdispatch and threads on WASI, and enables
8+
wasi-libc emulation features.
9+
---
10+
CMakeLists.txt | 36 +++++++++++++++---------------------
11+
1 file changed, 15 insertions(+), 21 deletions(-)
12+
13+
diff --git a/CMakeLists.txt b/CMakeLists.txt
14+
index 1fbdee6a..e7d0ebcf 100644
15+
--- a/CMakeLists.txt
16+
+++ b/CMakeLists.txt
17+
@@ -125,7 +125,7 @@ endif()
18+
# System dependencies
19+
find_package(LibRT)
20+
find_package(dispatch CONFIG)
21+
-if(NOT dispatch_FOUND)
22+
+if(NOT dispatch_FOUND AND NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
23+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
24+
set(DEFAULT_DISPATCH_INCLUDE_PATH "/usr/lib/swift")
25+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
26+
@@ -144,7 +144,6 @@ find_package(CURL REQUIRED)
27+
list(APPEND _Foundation_common_build_flags
28+
"-DDEPLOYMENT_RUNTIME_SWIFT"
29+
"-DCF_BUILDING_CF"
30+
- "-DDEPLOYMENT_ENABLE_LIBDISPATCH"
31+
"-DHAVE_STRUCT_TIMESPEC"
32+
"-Wno-shorten-64-to-32"
33+
"-Wno-deprecated-declarations"
34+
@@ -157,16 +156,10 @@ list(APPEND _Foundation_common_build_flags
35+
"-Wno-switch"
36+
"-fblocks")
37+
38+
-if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
39+
- list(APPEND _Foundation_common_build_flags
40+
- "-D_WASI_EMULATED_SIGNAL"
41+
- "-DHAVE_STRLCPY"
42+
- "-DHAVE_STRLCAT"
43+
- )
44+
-else()
45+
- list(APPEND _Foundation_common_build_flags
46+
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
47+
- )
48+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
49+
+ list(APPEND _Foundation_common_build_flags
50+
+ "-DDEPLOYMENT_ENABLE_LIBDISPATCH"
51+
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS")
52+
endif()
53+
54+
if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
55+
@@ -199,16 +192,17 @@ list(APPEND _Foundation_swift_build_flags
56+
"-Xfrontend"
57+
"-require-explicit-sendable")
58+
59+
-if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
60+
- list(APPEND _Foundation_swift_build_flags
61+
- "-D_WASI_EMULATED_SIGNAL"
62+
- "-DHAVE_STRLCPY"
63+
- "-DHAVE_STRLCAT"
64+
- )
65+
+if(CMAKE_SYSTEM_NAME STREQUAL WASI)
66+
+ # Enable wasi-libc emulation features
67+
+ set(WASI_EMULATION_DEFS _WASI_EMULATED_MMAN _WASI_EMULATED_SIGNAL _WASI_EMULATED_PROCESS_CLOCKS)
68+
+ foreach(def ${WASI_EMULATION_DEFS})
69+
+ list(APPEND _Foundation_swift_build_flags "SHELL:-Xcc -D${def}")
70+
+ list(APPEND _Foundation_common_build_flags "-D${def}")
71+
+ endforeach()
72+
else()
73+
- list(APPEND _Foundation_swift_build_flags
74+
- "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
75+
- )
76+
+ # Assume we have threads on other platforms
77+
+ list(APPEND _Foundation_swift_build_flags
78+
+ "-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS")
79+
endif()
80+
81+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
82+
--
83+
2.43.2
84+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From e9657f073a0fde4435840e6d4ef93d181d192b8b Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Wed, 7 Aug 2024 05:15:39 +0000
4+
Subject: [PATCH] [CMake] Exclude FoundationNetworking and
5+
_CFURLSessionInterface on WASI
6+
7+
Because networking is not a part of WASI Preview 1. We can add it back
8+
when it is available.
9+
---
10+
Sources/CMakeLists.txt | 8 ++++++--
11+
1 file changed, 6 insertions(+), 2 deletions(-)
12+
13+
diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt
14+
index 0ee266a4..29b92440 100644
15+
--- a/Sources/CMakeLists.txt
16+
+++ b/Sources/CMakeLists.txt
17+
@@ -14,10 +14,14 @@
18+
19+
add_subdirectory(CoreFoundation)
20+
add_subdirectory(_CFXMLInterface)
21+
-add_subdirectory(_CFURLSessionInterface)
22+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
23+
+ add_subdirectory(_CFURLSessionInterface)
24+
+endif()
25+
add_subdirectory(Foundation)
26+
add_subdirectory(FoundationXML)
27+
-add_subdirectory(FoundationNetworking)
28+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
29+
+ add_subdirectory(FoundationNetworking)
30+
+endif()
31+
if(FOUNDATION_BUILD_TOOLS)
32+
add_subdirectory(plutil)
33+
endif()
34+
--
35+
2.43.2
36+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From d7c300fa5bb26c061aaf41553e06c814cf8e5d8f Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Wed, 7 Aug 2024 05:34:51 +0000
4+
Subject: [PATCH] [wasm] Include CFPreferences.h, CFRunLoop.h, and CFStream.h
5+
in WASI builds
6+
7+
Those headers has been imported by Swift side through
8+
`CoreFoundation/Base.subproj/SwiftRuntime/CoreFoundation.h` since
9+
44031b5a0e96ad91eada2261db2d3890818fe1d0 but we switched to
10+
use CoreFoundation.h directly after the recore, and the header was not
11+
updated in 44031b5a0e96ad91eada2261db2d3890818fe1d0
12+
---
13+
Sources/CoreFoundation/include/CoreFoundation.h | 8 +++++---
14+
1 file changed, 5 insertions(+), 3 deletions(-)
15+
16+
diff --git a/Sources/CoreFoundation/include/CoreFoundation.h b/Sources/CoreFoundation/include/CoreFoundation.h
17+
index a66e7e61..64313f0b 100644
18+
--- a/Sources/CoreFoundation/include/CoreFoundation.h
19+
+++ b/Sources/CoreFoundation/include/CoreFoundation.h
20+
@@ -58,9 +58,7 @@
21+
#include "CFLocale.h"
22+
#include "CFNumber.h"
23+
#include "CFNumberFormatter.h"
24+
-#if !TARGET_OS_WASI
25+
#include "CFPreferences.h"
26+
-#endif
27+
#include "CFPropertyList.h"
28+
#include "CFSet.h"
29+
#include "CFString.h"
30+
@@ -76,13 +74,17 @@
31+
32+
#include "ForSwiftFoundationOnly.h"
33+
34+
-#if TARGET_OS_OSX || TARGET_OS_IPHONE || TARGET_OS_WIN32 || TARGET_OS_LINUX
35+
+#if TARGET_OS_OSX || TARGET_OS_IPHONE || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
36+
+# if !TARGET_OS_WASI
37+
#include "CFMessagePort.h"
38+
#include "CFPlugIn.h"
39+
+# endif
40+
#include "CFRunLoop.h"
41+
#include "CFStream.h"
42+
+# if !TARGET_OS_WASI
43+
#include "CFSocket.h"
44+
#include "CFMachPort.h"
45+
+# endif
46+
47+
#include "CFAttributedString.h"
48+
#include "CFNotificationCenter.h"
49+
--
50+
2.43.2
51+

0 commit comments

Comments
 (0)