From 23e4ee6a936b126d539a68f3c9b13e637082adb8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 29 Mar 2025 12:28:00 +0000 Subject: [PATCH 1/3] Update base tag for main to swift-DEVELOPMENT-SNAPSHOT-2025-03-28-a --- schemes/main/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemes/main/manifest.json b/schemes/main/manifest.json index a2ba86c..9106c4e 100644 --- a/schemes/main/manifest.json +++ b/schemes/main/manifest.json @@ -1,5 +1,5 @@ { - "base-tag": "swift-DEVELOPMENT-SNAPSHOT-2025-03-25-a", + "base-tag": "swift-DEVELOPMENT-SNAPSHOT-2025-03-28-a", "icu4c": [], "libxml2": [ "https://github.com/swiftwasm/libxml2-wasm/releases/download/2.0.0/libxml2-wasm32-unknown-wasi.tar.gz", From 737e866e25f48d3425f78b5f5993bc56c0e3ad6a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 31 Mar 2025 11:10:57 +0000 Subject: [PATCH 2/3] Use toolchain's FoundationMacros plugin instead of building it The libFoundationMacros.so built in this script links SwiftSyntax (not prefixed with _Compiler) but it's not available in the recent toolchain for some reason. Not sure why it started happening recently but we don't need to build it in this script anyway. --- schemes/main/build/build-foundation.sh | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/schemes/main/build/build-foundation.sh b/schemes/main/build/build-foundation.sh index c95ae8c..290215b 100755 --- a/schemes/main/build/build-foundation.sh +++ b/schemes/main/build/build-foundation.sh @@ -8,12 +8,10 @@ WASI_SYSROOT_PATH=$5 TRIPLE="$6" SOURCE_PATH="$(cd "$(dirname $0)/../../../.." && pwd)" -SCHEME_BUILD_PATH="$(cd "$(dirname $0)" && pwd)" BUILD_SDK_PATH="$SOURCE_PATH/build-sdk" LIBXML2_PATH="$BUILD_SDK_PATH/libxml2-$TRIPLE" FOUNDATION_BUILD="$SOURCE_PATH/build/WebAssembly/foundation-$TRIPLE" -FOUNDATION_MACROS_BUILD="$SOURCE_PATH/build/WebAssembly/foundation-macros-$TRIPLE" swift_extra_flags="" c_extra_flags="" @@ -22,16 +20,6 @@ if [[ "$TRIPLE" == "wasm32-unknown-wasip1-threads" ]]; then c_extra_flags="-mthread-model posix -pthread -ftls-model=local-exec" fi -cmake -G Ninja \ - -D CMAKE_C_COMPILER="$CLANG_BIN_DIR/clang" \ - -D CMAKE_CXX_COMPILER="$CLANG_BIN_DIR/clang++" \ - -D CMAKE_Swift_COMPILER="$SWIFT_BIN_DIR/swiftc" \ - -D BUILD_SHARED_LIBS=ON \ - -B "$FOUNDATION_MACROS_BUILD" \ - "${SOURCE_PATH}/swift-foundation/Sources/FoundationMacros" - -cmake --build "$FOUNDATION_MACROS_BUILD" - cmake -G Ninja \ -D CMAKE_BUILD_TYPE="Release" \ -D CMAKE_SYSROOT="$WASI_SYSROOT_PATH" \ @@ -58,7 +46,7 @@ cmake -G Ninja \ -D _SwiftCollections_SourceDIR="$SOURCE_PATH/swift-collections" \ -D _SwiftFoundation_SourceDIR="$SOURCE_PATH/swift-foundation" \ -D _SwiftFoundationICU_SourceDIR="$SOURCE_PATH/swift-foundation-icu" \ - -D SwiftFoundation_MACRO="$FOUNDATION_MACROS_BUILD/lib" \ + -D SwiftFoundation_MACRO="$SWIFT_BIN_DIR/../lib/swift/host/plugins" \ -B "$FOUNDATION_BUILD" \ "${SOURCE_PATH}/swift-corelibs-foundation" From 43b74c0f71fb7306e37da7dbf5f3bac4152e5d01 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 31 Mar 2025 11:14:30 +0000 Subject: [PATCH 3/3] Fix Foundation build --- ...-write-option-usages-behind-platform.patch | 64 +++++++++++++++++++ .../0001-wasm-Add-O_NONBLOCK-shim.patch | 39 +++++++++++ 2 files changed, 103 insertions(+) create mode 100644 schemes/main/swift-corelibs-foundation/0001-wasm-Gate-atomic-write-option-usages-behind-platform.patch create mode 100644 schemes/main/swift-foundation/0001-wasm-Add-O_NONBLOCK-shim.patch diff --git a/schemes/main/swift-corelibs-foundation/0001-wasm-Gate-atomic-write-option-usages-behind-platform.patch b/schemes/main/swift-corelibs-foundation/0001-wasm-Gate-atomic-write-option-usages-behind-platform.patch new file mode 100644 index 0000000..9596883 --- /dev/null +++ b/schemes/main/swift-corelibs-foundation/0001-wasm-Gate-atomic-write-option-usages-behind-platform.patch @@ -0,0 +1,64 @@ +From 6e3a9e2ced5688bfe9e209633735bf6bdc85d64c Mon Sep 17 00:00:00 2001 +From: Yuta Saito +Date: Mon, 31 Mar 2025 11:07:42 +0000 +Subject: [PATCH] [wasm] Gate atomic write option usages behind platform check + +`Data.WritingOptions.atomic` is now unavailable on WASI: https://github.com/swiftlang/swift-foundation/pull/992 +--- + Sources/Foundation/NSData.swift | 11 +++++++++-- + Sources/Foundation/NSString.swift | 7 ++++++- + 2 files changed, 15 insertions(+), 3 deletions(-) + +diff --git a/Sources/Foundation/NSData.swift b/Sources/Foundation/NSData.swift +index 1a076bef..e1499ae2 100644 +--- a/Sources/Foundation/NSData.swift ++++ b/Sources/Foundation/NSData.swift +@@ -433,10 +433,12 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { + #if os(WASI) + // WASI does not have permission concept + let permissions: Int? = nil ++ var atomicWrite: Bool { false } + #else + let permissions = try? fm.attributesOfItem(atPath: path)[.posixPermissions] as? Int ++ let atomicWrite = writeOptionsMask.contains(.atomic) + #endif +- if writeOptionsMask.contains(.atomic) { ++ if atomicWrite { + let (newFD, auxFilePath) = try _NSCreateTemporaryFile(path) + let fh = FileHandle(fileDescriptor: newFD, closeOnDealloc: true) + do { +@@ -489,7 +491,12 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { + /// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes + open func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool { + do { +- try write(toFile: path, options: useAuxiliaryFile ? .atomic : []) ++ #if os(WASI) ++ let options: WritingOptions = [] ++ #else ++ let options: WritingOptions = useAuxiliaryFile ? .atomic : [] ++ #endif ++ try write(toFile: path, options: options) + } catch { + return false + } +diff --git a/Sources/Foundation/NSString.swift b/Sources/Foundation/NSString.swift +index ccd0ae08..fd1de6f3 100644 +--- a/Sources/Foundation/NSString.swift ++++ b/Sources/Foundation/NSString.swift +@@ -1269,7 +1269,12 @@ extension NSString { + internal func _writeTo(_ url: URL, _ useAuxiliaryFile: Bool, _ enc: UInt) throws { + var data = Data() + try _getExternalRepresentation(&data, url, enc) +- try data.write(to: url, options: useAuxiliaryFile ? .atomic : []) ++ #if os(WASI) ++ let options: Data.WritingOptions = [] ++ #else ++ let options: Data.WritingOptions = useAuxiliaryFile ? .atomic : [] ++ #endif ++ try data.write(to: url, options: options) + } + + public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: UInt) throws { +-- +2.48.1 + diff --git a/schemes/main/swift-foundation/0001-wasm-Add-O_NONBLOCK-shim.patch b/schemes/main/swift-foundation/0001-wasm-Add-O_NONBLOCK-shim.patch new file mode 100644 index 0000000..b097345 --- /dev/null +++ b/schemes/main/swift-foundation/0001-wasm-Add-O_NONBLOCK-shim.patch @@ -0,0 +1,39 @@ +From 00b480096e31a7f9a70d6516b407cac2a88862cb Mon Sep 17 00:00:00 2001 +From: Yuta Saito +Date: Mon, 31 Mar 2025 11:06:50 +0000 +Subject: [PATCH] [wasm] Add O_NONBLOCK shim + +--- + Sources/FoundationEssentials/WASILibc+Extensions.swift | 3 +++ + Sources/_FoundationCShims/include/platform_shims.h | 1 + + 2 files changed, 4 insertions(+) + +diff --git a/Sources/FoundationEssentials/WASILibc+Extensions.swift b/Sources/FoundationEssentials/WASILibc+Extensions.swift +index 529ac77..0a420e3 100644 +--- a/Sources/FoundationEssentials/WASILibc+Extensions.swift ++++ b/Sources/FoundationEssentials/WASILibc+Extensions.swift +@@ -49,6 +49,9 @@ internal var O_TRUNC: Int32 { + internal var O_WRONLY: Int32 { + return _platform_shims_O_WRONLY() + } ++internal var O_NONBLOCK: Int32 { ++ return _platform_shims_O_NONBLOCK() ++} + internal var O_RDONLY: Int32 { + return _platform_shims_O_RDONLY() + } +diff --git a/Sources/_FoundationCShims/include/platform_shims.h b/Sources/_FoundationCShims/include/platform_shims.h +index e02b581..37d0ca2 100644 +--- a/Sources/_FoundationCShims/include/platform_shims.h ++++ b/Sources/_FoundationCShims/include/platform_shims.h +@@ -102,6 +102,7 @@ static inline int32_t _platform_shims_O_CREAT(void) { return O_CREAT; } + static inline int32_t _platform_shims_O_EXCL(void) { return O_EXCL; } + static inline int32_t _platform_shims_O_TRUNC(void) { return O_TRUNC; } + static inline int32_t _platform_shims_O_WRONLY(void) { return O_WRONLY; } ++static inline int32_t _platform_shims_O_NONBLOCK(void) { return O_NONBLOCK; } + static inline int32_t _platform_shims_O_RDONLY(void) { return O_RDONLY; } + static inline int32_t _platform_shims_O_DIRECTORY(void) { return O_DIRECTORY; } + static inline int32_t _platform_shims_O_NOFOLLOW(void) { return O_NOFOLLOW; } +-- +2.48.1 +