Skip to content

Commit 5093e60

Browse files
Merge pull request #473 from swiftwasm/update-base-tag/main-swift-DEVELOPMENT-SNAPSHOT-2024-12-12-a
Update base tag for main to swift-DEVELOPMENT-SNAPSHOT-2024-12-12-a
2 parents e481cda + 1431fe2 commit 5093e60

5 files changed

+158
-1
lines changed

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-12-10-a",
2+
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-12-12-a",
33
"build-compiler": false,
44
"icu4c": [],
55
"libxml2": [
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From cc9d6a3535122542a28f3cf8eb93feb95e05b0f5 Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Fri, 13 Dec 2024 16:09:59 +0000
4+
Subject: [PATCH 1/4] Fix WASI build of `_copyDirectoryMetadata`
5+
6+
Extended attributes don't exist in WASI, so we need to exclude the use
7+
of xattr-related APIs including `flistxattr`.
8+
---
9+
Sources/FoundationEssentials/FileManager/FileOperations.swift | 2 ++
10+
1 file changed, 2 insertions(+)
11+
12+
diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
13+
index 418f5cf..9567f65 100644
14+
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
15+
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
16+
@@ -951,6 +951,7 @@ enum _FileOperations {
17+
18+
#if !canImport(Darwin)
19+
private static func _copyDirectoryMetadata(srcFD: CInt, srcPath: @autoclosure () -> String, dstFD: CInt, dstPath: @autoclosure () -> String, delegate: some LinkOrCopyDelegate) throws {
20+
+ #if !os(WASI)
21+
// Copy extended attributes
22+
var size = flistxattr(srcFD, nil, 0)
23+
if size > 0 {
24+
@@ -976,6 +977,7 @@ enum _FileOperations {
25+
}
26+
}
27+
}
28+
+ #endif
29+
var statInfo = stat()
30+
if fstat(srcFD, &statInfo) == 0 {
31+
// Copy owner/group
32+
--
33+
2.46.0
34+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 88ddc3cc219262ea2c3d421be0333b8625b4d77c Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Sat, 14 Dec 2024 06:48:35 +0000
4+
Subject: [PATCH 2/4] Gate `fchown` and `fchmod` calls behind `os(WASI)`
5+
6+
They are not available on WASI, so we gate them behind `os(WASI)`.
7+
---
8+
Sources/FoundationEssentials/FileManager/FileOperations.swift | 4 ++++
9+
1 file changed, 4 insertions(+)
10+
11+
diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
12+
index 9567f65..49e2c37 100644
13+
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
14+
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
15+
@@ -980,10 +980,12 @@ enum _FileOperations {
16+
#endif
17+
var statInfo = stat()
18+
if fstat(srcFD, &statInfo) == 0 {
19+
+ #if !os(WASI) // WASI doesn't have fchown for now
20+
// Copy owner/group
21+
if fchown(dstFD, statInfo.st_uid, statInfo.st_gid) != 0 {
22+
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
23+
}
24+
+ #endif
25+
26+
// Copy modification date
27+
let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000)
28+
@@ -996,10 +998,12 @@ enum _FileOperations {
29+
}
30+
}
31+
32+
+ #if !os(WASI) // WASI doesn't have fchmod for now
33+
// Copy permissions
34+
if fchmod(dstFD, mode_t(statInfo.st_mode)) != 0 {
35+
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
36+
}
37+
+ #endif
38+
} else {
39+
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
40+
}
41+
--
42+
2.46.0
43+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 694cc281ab301a2b0f9b18d17d59aa8e5f94b65a Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Sat, 14 Dec 2024 09:12:24 +0000
4+
Subject: [PATCH 3/4] Add missing constant shims for wasi-libc
5+
6+
---
7+
Sources/FoundationEssentials/WASILibc+Extensions.swift | 9 +++++++++
8+
Sources/_FoundationCShims/include/platform_shims.h | 4 ++++
9+
2 files changed, 13 insertions(+)
10+
11+
diff --git a/Sources/FoundationEssentials/WASILibc+Extensions.swift b/Sources/FoundationEssentials/WASILibc+Extensions.swift
12+
index 351fe19..44f3f93 100644
13+
--- a/Sources/FoundationEssentials/WASILibc+Extensions.swift
14+
+++ b/Sources/FoundationEssentials/WASILibc+Extensions.swift
15+
@@ -49,5 +49,14 @@ internal var O_TRUNC: Int32 {
16+
internal var O_WRONLY: Int32 {
17+
return _platform_shims_O_WRONLY()
18+
}
19+
+internal var O_RDONLY: Int32 {
20+
+ return _platform_shims_O_RDONLY()
21+
+}
22+
+internal var O_DIRECTORY: Int32 {
23+
+ return _platform_shims_O_DIRECTORY()
24+
+}
25+
+internal var O_NOFOLLOW: Int32 {
26+
+ return _platform_shims_O_NOFOLLOW()
27+
+}
28+
29+
#endif // os(WASI)
30+
diff --git a/Sources/_FoundationCShims/include/platform_shims.h b/Sources/_FoundationCShims/include/platform_shims.h
31+
index 6bc0a0e..e02b581 100644
32+
--- a/Sources/_FoundationCShims/include/platform_shims.h
33+
+++ b/Sources/_FoundationCShims/include/platform_shims.h
34+
@@ -102,6 +102,10 @@ static inline int32_t _platform_shims_O_CREAT(void) { return O_CREAT; }
35+
static inline int32_t _platform_shims_O_EXCL(void) { return O_EXCL; }
36+
static inline int32_t _platform_shims_O_TRUNC(void) { return O_TRUNC; }
37+
static inline int32_t _platform_shims_O_WRONLY(void) { return O_WRONLY; }
38+
+static inline int32_t _platform_shims_O_RDONLY(void) { return O_RDONLY; }
39+
+static inline int32_t _platform_shims_O_DIRECTORY(void) { return O_DIRECTORY; }
40+
+static inline int32_t _platform_shims_O_NOFOLLOW(void) { return O_NOFOLLOW; }
41+
+
42+
#endif
43+
44+
#endif /* CSHIMS_PLATFORM_SHIMS */
45+
--
46+
2.46.0
47+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From aed67387933a934e3734b9768a9467294569952b Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Sat, 14 Dec 2024 09:12:49 +0000
4+
Subject: [PATCH 4/4] Use `futimens` instead of legacy `futimes`
5+
6+
wasi-libc does not provide `futimes` as it is a legacy function.
7+
https://github.com/WebAssembly/wasi-libc/blob/574b88da481569b65a237cb80daf9a2d5aeaf82d/libc-top-half/musl/include/sys/time.h#L34
8+
---
9+
.../FoundationEssentials/FileManager/FileOperations.swift | 6 +++---
10+
1 file changed, 3 insertions(+), 3 deletions(-)
11+
12+
diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
13+
index 49e2c37..2ef8a03 100644
14+
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
15+
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
16+
@@ -988,11 +988,11 @@ enum _FileOperations {
17+
#endif
18+
19+
// Copy modification date
20+
- let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000)
21+
+ let value = statInfo.st_mtim
22+
var tv = (value, value)
23+
try withUnsafePointer(to: &tv) {
24+
- try $0.withMemoryRebound(to: timeval.self, capacity: 2) {
25+
- if futimes(dstFD, $0) != 0 {
26+
+ try $0.withMemoryRebound(to: timespec.self, capacity: 2) {
27+
+ if futimens(dstFD, $0) != 0 {
28+
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
29+
}
30+
}
31+
--
32+
2.46.0
33+

0 commit comments

Comments
 (0)