Skip to content

Commit 1431fe2

Browse files
2nd try
1 parent 09a100b commit 1431fe2

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

schemes/main/swift-foundation/0001-Fix-WASI-build-of-_copyDirectoryMetadata.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From cc9d6a3535122542a28f3cf8eb93feb95e05b0f5 Mon Sep 17 00:00:00 2001
22
From: Yuta Saito <[email protected]>
33
Date: Fri, 13 Dec 2024 16:09:59 +0000
4-
Subject: [PATCH 1/2] Fix WASI build of `_copyDirectoryMetadata`
4+
Subject: [PATCH 1/4] Fix WASI build of `_copyDirectoryMetadata`
55

66
Extended attributes don't exist in WASI, so we need to exclude the use
77
of xattr-related APIs including `flistxattr`.

schemes/main/swift-foundation/0002-Gate-fchown-and-fchmod-calls-behind-os-WASI.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 88ddc3cc219262ea2c3d421be0333b8625b4d77c Mon Sep 17 00:00:00 2001
22
From: Yuta Saito <[email protected]>
33
Date: Sat, 14 Dec 2024 06:48:35 +0000
4-
Subject: [PATCH 2/2] Gate `fchown` and `fchmod` calls behind `os(WASI)`
4+
Subject: [PATCH 2/4] Gate `fchown` and `fchmod` calls behind `os(WASI)`
55

66
They are not available on WASI, so we gate them behind `os(WASI)`.
77
---
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)