Skip to content

Commit 6c1a678

Browse files
Merge pull request #572 from swiftwasm/update-base-tag/main-swift-DEVELOPMENT-SNAPSHOT-2025-03-28-a
Update base tag for main to swift-DEVELOPMENT-SNAPSHOT-2025-03-28-a
2 parents 2b09487 + 43b74c0 commit 6c1a678

File tree

4 files changed

+105
-14
lines changed

4 files changed

+105
-14
lines changed

schemes/main/build/build-foundation.sh

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ WASI_SYSROOT_PATH=$5
88
TRIPLE="$6"
99

1010
SOURCE_PATH="$(cd "$(dirname $0)/../../../.." && pwd)"
11-
SCHEME_BUILD_PATH="$(cd "$(dirname $0)" && pwd)"
1211
BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
1312
LIBXML2_PATH="$BUILD_SDK_PATH/libxml2-$TRIPLE"
1413

1514
FOUNDATION_BUILD="$SOURCE_PATH/build/WebAssembly/foundation-$TRIPLE"
16-
FOUNDATION_MACROS_BUILD="$SOURCE_PATH/build/WebAssembly/foundation-macros-$TRIPLE"
1715

1816
swift_extra_flags=""
1917
c_extra_flags=""
@@ -22,16 +20,6 @@ if [[ "$TRIPLE" == "wasm32-unknown-wasip1-threads" ]]; then
2220
c_extra_flags="-mthread-model posix -pthread -ftls-model=local-exec"
2321
fi
2422

25-
cmake -G Ninja \
26-
-D CMAKE_C_COMPILER="$CLANG_BIN_DIR/clang" \
27-
-D CMAKE_CXX_COMPILER="$CLANG_BIN_DIR/clang++" \
28-
-D CMAKE_Swift_COMPILER="$SWIFT_BIN_DIR/swiftc" \
29-
-D BUILD_SHARED_LIBS=ON \
30-
-B "$FOUNDATION_MACROS_BUILD" \
31-
"${SOURCE_PATH}/swift-foundation/Sources/FoundationMacros"
32-
33-
cmake --build "$FOUNDATION_MACROS_BUILD"
34-
3523
cmake -G Ninja \
3624
-D CMAKE_BUILD_TYPE="Release" \
3725
-D CMAKE_SYSROOT="$WASI_SYSROOT_PATH" \
@@ -58,7 +46,7 @@ cmake -G Ninja \
5846
-D _SwiftCollections_SourceDIR="$SOURCE_PATH/swift-collections" \
5947
-D _SwiftFoundation_SourceDIR="$SOURCE_PATH/swift-foundation" \
6048
-D _SwiftFoundationICU_SourceDIR="$SOURCE_PATH/swift-foundation-icu" \
61-
-D SwiftFoundation_MACRO="$FOUNDATION_MACROS_BUILD/lib" \
49+
-D SwiftFoundation_MACRO="$SWIFT_BIN_DIR/../lib/swift/host/plugins" \
6250
-B "$FOUNDATION_BUILD" \
6351
"${SOURCE_PATH}/swift-corelibs-foundation"
6452

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-2025-03-25-a",
2+
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2025-03-28-a",
33
"icu4c": [],
44
"libxml2": [
55
"https://github.com/swiftwasm/libxml2-wasm/releases/download/2.0.0/libxml2-wasm32-unknown-wasi.tar.gz",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 6e3a9e2ced5688bfe9e209633735bf6bdc85d64c Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Mon, 31 Mar 2025 11:07:42 +0000
4+
Subject: [PATCH] [wasm] Gate atomic write option usages behind platform check
5+
6+
`Data.WritingOptions.atomic` is now unavailable on WASI: https://github.com/swiftlang/swift-foundation/pull/992
7+
---
8+
Sources/Foundation/NSData.swift | 11 +++++++++--
9+
Sources/Foundation/NSString.swift | 7 ++++++-
10+
2 files changed, 15 insertions(+), 3 deletions(-)
11+
12+
diff --git a/Sources/Foundation/NSData.swift b/Sources/Foundation/NSData.swift
13+
index 1a076bef..e1499ae2 100644
14+
--- a/Sources/Foundation/NSData.swift
15+
+++ b/Sources/Foundation/NSData.swift
16+
@@ -433,10 +433,12 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
17+
#if os(WASI)
18+
// WASI does not have permission concept
19+
let permissions: Int? = nil
20+
+ var atomicWrite: Bool { false }
21+
#else
22+
let permissions = try? fm.attributesOfItem(atPath: path)[.posixPermissions] as? Int
23+
+ let atomicWrite = writeOptionsMask.contains(.atomic)
24+
#endif
25+
- if writeOptionsMask.contains(.atomic) {
26+
+ if atomicWrite {
27+
let (newFD, auxFilePath) = try _NSCreateTemporaryFile(path)
28+
let fh = FileHandle(fileDescriptor: newFD, closeOnDealloc: true)
29+
do {
30+
@@ -489,7 +491,12 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
31+
/// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
32+
open func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool {
33+
do {
34+
- try write(toFile: path, options: useAuxiliaryFile ? .atomic : [])
35+
+ #if os(WASI)
36+
+ let options: WritingOptions = []
37+
+ #else
38+
+ let options: WritingOptions = useAuxiliaryFile ? .atomic : []
39+
+ #endif
40+
+ try write(toFile: path, options: options)
41+
} catch {
42+
return false
43+
}
44+
diff --git a/Sources/Foundation/NSString.swift b/Sources/Foundation/NSString.swift
45+
index ccd0ae08..fd1de6f3 100644
46+
--- a/Sources/Foundation/NSString.swift
47+
+++ b/Sources/Foundation/NSString.swift
48+
@@ -1269,7 +1269,12 @@ extension NSString {
49+
internal func _writeTo(_ url: URL, _ useAuxiliaryFile: Bool, _ enc: UInt) throws {
50+
var data = Data()
51+
try _getExternalRepresentation(&data, url, enc)
52+
- try data.write(to: url, options: useAuxiliaryFile ? .atomic : [])
53+
+ #if os(WASI)
54+
+ let options: Data.WritingOptions = []
55+
+ #else
56+
+ let options: Data.WritingOptions = useAuxiliaryFile ? .atomic : []
57+
+ #endif
58+
+ try data.write(to: url, options: options)
59+
}
60+
61+
public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: UInt) throws {
62+
--
63+
2.48.1
64+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From 00b480096e31a7f9a70d6516b407cac2a88862cb Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Mon, 31 Mar 2025 11:06:50 +0000
4+
Subject: [PATCH] [wasm] Add O_NONBLOCK shim
5+
6+
---
7+
Sources/FoundationEssentials/WASILibc+Extensions.swift | 3 +++
8+
Sources/_FoundationCShims/include/platform_shims.h | 1 +
9+
2 files changed, 4 insertions(+)
10+
11+
diff --git a/Sources/FoundationEssentials/WASILibc+Extensions.swift b/Sources/FoundationEssentials/WASILibc+Extensions.swift
12+
index 529ac77..0a420e3 100644
13+
--- a/Sources/FoundationEssentials/WASILibc+Extensions.swift
14+
+++ b/Sources/FoundationEssentials/WASILibc+Extensions.swift
15+
@@ -49,6 +49,9 @@ internal var O_TRUNC: Int32 {
16+
internal var O_WRONLY: Int32 {
17+
return _platform_shims_O_WRONLY()
18+
}
19+
+internal var O_NONBLOCK: Int32 {
20+
+ return _platform_shims_O_NONBLOCK()
21+
+}
22+
internal var O_RDONLY: Int32 {
23+
return _platform_shims_O_RDONLY()
24+
}
25+
diff --git a/Sources/_FoundationCShims/include/platform_shims.h b/Sources/_FoundationCShims/include/platform_shims.h
26+
index e02b581..37d0ca2 100644
27+
--- a/Sources/_FoundationCShims/include/platform_shims.h
28+
+++ b/Sources/_FoundationCShims/include/platform_shims.h
29+
@@ -102,6 +102,7 @@ static inline int32_t _platform_shims_O_CREAT(void) { return O_CREAT; }
30+
static inline int32_t _platform_shims_O_EXCL(void) { return O_EXCL; }
31+
static inline int32_t _platform_shims_O_TRUNC(void) { return O_TRUNC; }
32+
static inline int32_t _platform_shims_O_WRONLY(void) { return O_WRONLY; }
33+
+static inline int32_t _platform_shims_O_NONBLOCK(void) { return O_NONBLOCK; }
34+
static inline int32_t _platform_shims_O_RDONLY(void) { return O_RDONLY; }
35+
static inline int32_t _platform_shims_O_DIRECTORY(void) { return O_DIRECTORY; }
36+
static inline int32_t _platform_shims_O_NOFOLLOW(void) { return O_NOFOLLOW; }
37+
--
38+
2.48.1
39+

0 commit comments

Comments
 (0)