Skip to content

Commit 808e9d6

Browse files
Merge pull request #398 from swiftwasm/update-base-tag/main-swift-DEVELOPMENT-SNAPSHOT-2024-08-07-a
Update base tag for main to swift-DEVELOPMENT-SNAPSHOT-2024-08-07-a
2 parents 253f054 + d2bdcdb commit 808e9d6

File tree

26 files changed

+1646
-28
lines changed

26 files changed

+1646
-28
lines changed

schemes/main/build/build-foundation.sh

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ LIBXML2_PATH="$BUILD_SDK_PATH/libxml2-$TRIPLE"
1414

1515
FOUNDATION_BUILD="$SOURCE_PATH/build/WebAssembly/foundation-$TRIPLE"
1616

17-
mkdir -p $FOUNDATION_BUILD
18-
cd $FOUNDATION_BUILD
19-
2017
swift_extra_flags=""
2118
c_extra_flags=""
2219
if [[ "$TRIPLE" == "wasm32-unknown-wasip1-threads" ]]; then
@@ -25,27 +22,33 @@ if [[ "$TRIPLE" == "wasm32-unknown-wasip1-threads" ]]; then
2522
fi
2623

2724
cmake -G Ninja \
28-
-DCMAKE_BUILD_TYPE="Release" \
29-
-DCMAKE_SYSROOT="$WASI_SYSROOT_PATH" \
30-
-DCMAKE_Swift_COMPILER="$SWIFT_BIN_DIR/swiftc" \
31-
-DCMAKE_STAGING_PREFIX="$DESTINATION_TOOLCHAIN/usr" \
32-
-DCMAKE_TOOLCHAIN_FILE="$SCHEME_BUILD_PATH/toolchain-wasi.cmake" \
33-
-DTRIPLE="$TRIPLE" \
34-
-DLLVM_BIN="$LLVM_BIN_DIR" \
35-
-DCLANG_BIN="$CLANG_BIN_DIR" \
36-
-DICU_ROOT="$BUILD_SDK_PATH/icu-$TRIPLE" \
37-
-DLIBXML2_INCLUDE_DIR="$LIBXML2_PATH/include/libxml2" \
38-
-DLIBXML2_LIBRARY="$LIBXML2_PATH/lib" \
39-
-DBUILD_SHARED_LIBS=OFF \
40-
-DBUILD_NETWORKING=OFF \
41-
-DBUILD_TOOLS=OFF \
42-
-DFOUNDATION_ENABLE_FOUNDATION_NETWORKING=OFF \
43-
-DFOUNDATION_BUILD_TOOLS=OFF \
44-
-DHAS_LIBDISPATCH_API=OFF \
45-
-DCMAKE_Swift_COMPILER_FORCED=ON \
46-
-DCMAKE_Swift_FLAGS="-sdk $WASI_SYSROOT_PATH -resource-dir $DESTINATION_TOOLCHAIN/usr/lib/swift_static $swift_extra_flags" \
47-
-DCMAKE_C_FLAGS="-resource-dir $DESTINATION_TOOLCHAIN/usr/lib/swift_static/clang -B $LLVM_BIN_DIR $c_extra_flags" \
25+
-D CMAKE_BUILD_TYPE="Release" \
26+
-D CMAKE_SYSROOT="$WASI_SYSROOT_PATH" \
27+
-D CMAKE_Swift_COMPILER="$SWIFT_BIN_DIR/swiftc" \
28+
-D CMAKE_STAGING_PREFIX="$DESTINATION_TOOLCHAIN/usr" \
29+
-D CMAKE_SYSTEM_NAME=WASI \
30+
-D CMAKE_SYSTEM_PROCESSOR=wasm32 \
31+
-D CMAKE_C_COMPILER_TARGET="$TRIPLE" \
32+
-D CMAKE_CXX_COMPILER_TARGET="$TRIPLE" \
33+
-D CMAKE_Swift_COMPILER_TARGET="$TRIPLE" \
34+
-D CMAKE_C_COMPILER="$CLANG_BIN_DIR/clang" \
35+
-D CMAKE_CXX_COMPILER="$CLANG_BIN_DIR/clang++" \
36+
-D CMAKE_AR="$LLVM_BIN_DIR/llvm-ar" \
37+
-D CMAKE_RANLIB="$LLVM_BIN_DIR/llvm-ranlib" \
38+
-D LIBXML2_INCLUDE_DIR="$LIBXML2_PATH/include/libxml2" \
39+
-D LIBXML2_LIBRARY="$LIBXML2_PATH/lib" \
40+
-D BUILD_SHARED_LIBS=OFF \
41+
-D FOUNDATION_BUILD_TOOLS=OFF \
42+
-D CMAKE_Swift_COMPILER_FORCED=ON \
43+
-D CMAKE_C_COMPILER_FORCED=ON \
44+
-D CMAKE_CXX_COMPILER_FORCED=ON \
45+
-D CMAKE_Swift_FLAGS="-sdk $WASI_SYSROOT_PATH -resource-dir $DESTINATION_TOOLCHAIN/usr/lib/swift_static $swift_extra_flags" \
46+
-D CMAKE_C_FLAGS="-resource-dir $DESTINATION_TOOLCHAIN/usr/lib/swift_static/clang -B $LLVM_BIN_DIR $c_extra_flags" \
47+
-D _SwiftCollections_SourceDIR="$SOURCE_PATH/swift-collections" \
48+
-D _SwiftFoundation_SourceDIR="$SOURCE_PATH/swift-foundation" \
49+
-D _SwiftFoundationICU_SourceDIR="$SOURCE_PATH/swift-foundation-icu" \
50+
-B "$FOUNDATION_BUILD" \
4851
"${SOURCE_PATH}/swift-corelibs-foundation"
4952

50-
ninja
51-
ninja install
53+
cmake --build "$FOUNDATION_BUILD"
54+
cmake --install "$FOUNDATION_BUILD"

schemes/main/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-07-15-a",
2+
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-08-07-a",
33
"build-compiler": false,
44
"icu4c": [
55
"https://github.com/swiftwasm/icu4c-wasi/releases/download/0.10.0/icu4c-wasm32-unknown-wasi.tar.xz",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From effb33569a926c12dc8e7bae979ac2075c219189 Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Fri, 26 Jul 2024 03:59:24 +0000
4+
Subject: [PATCH] [CMake] Add support for WebAssembly target architectures
5+
6+
To repair the swift-corelibs-foundation build on WebAssembly, we need to
7+
add support for Wasm targets to swift-collections' CMake build system.
8+
---
9+
cmake/modules/SwiftSupport.cmake | 4 ++++
10+
1 file changed, 4 insertions(+)
11+
12+
diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake
13+
index 0ce99fb8..21b9d693 100644
14+
--- a/cmake/modules/SwiftSupport.cmake
15+
+++ b/cmake/modules/SwiftSupport.cmake
16+
@@ -45,6 +45,10 @@ function(get_swift_host_arch result_var_name)
17+
set("${result_var_name}" "i686" PARENT_SCOPE)
18+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
19+
set("${result_var_name}" "i686" PARENT_SCOPE)
20+
+ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm32")
21+
+ set("${result_var_name}" "wasm32" PARENT_SCOPE)
22+
+ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm64")
23+
+ set("${result_var_name}" "wasm64" PARENT_SCOPE)
24+
else()
25+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
26+
endif()
27+
--
28+
2.43.2
29+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 3506f58a89de211823dcee98eb698dfcc1414fc5 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 fef108320304306b2765df0f839dafabdbf714bd 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 edb6cf06..2bce7426 100644
15+
--- a/CMakeLists.txt
16+
+++ b/CMakeLists.txt
17+
@@ -94,7 +94,7 @@ endif()
18+
19+
# System dependencies
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+
@@ -113,7 +113,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+
@@ -126,16 +125,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+
@@ -168,16 +161,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 27310f474957020b3083605083d86c93a812b42a 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 164af81d45dfff66d8d409f5f6bd946cb3987bc4 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+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From f91a759124ea50b491c3fe0fa8ecf34b39de6c20 Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Wed, 7 Aug 2024 05:39:34 +0000
4+
Subject: [PATCH] [wasm] Fix the new CFString.c compilation error on WASI
5+
6+
Treat WASI as an usual Unix-like system
7+
---
8+
Sources/CoreFoundation/CFString.c | 2 +-
9+
1 file changed, 1 insertion(+), 1 deletion(-)
10+
11+
diff --git a/Sources/CoreFoundation/CFString.c b/Sources/CoreFoundation/CFString.c
12+
index 94a6c86d..f8899e15 100644
13+
--- a/Sources/CoreFoundation/CFString.c
14+
+++ b/Sources/CoreFoundation/CFString.c
15+
@@ -35,7 +35,7 @@
16+
#include <stdarg.h>
17+
#include <stdio.h>
18+
#include <string.h>
19+
-#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
20+
+#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
21+
#include <unistd.h>
22+
#endif
23+
#if TARGET_OS_WASI
24+
--
25+
2.43.2
26+

0 commit comments

Comments
 (0)