Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schemes/main/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-12-10-a",
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2024-12-12-a",
"build-compiler": false,
"icu4c": [],
"libxml2": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From cc9d6a3535122542a28f3cf8eb93feb95e05b0f5 Mon Sep 17 00:00:00 2001
From: Yuta Saito <[email protected]>
Date: Fri, 13 Dec 2024 16:09:59 +0000
Subject: [PATCH 1/4] Fix WASI build of `_copyDirectoryMetadata`

Extended attributes don't exist in WASI, so we need to exclude the use
of xattr-related APIs including `flistxattr`.
---
Sources/FoundationEssentials/FileManager/FileOperations.swift | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
index 418f5cf..9567f65 100644
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
@@ -951,6 +951,7 @@ enum _FileOperations {

#if !canImport(Darwin)
private static func _copyDirectoryMetadata(srcFD: CInt, srcPath: @autoclosure () -> String, dstFD: CInt, dstPath: @autoclosure () -> String, delegate: some LinkOrCopyDelegate) throws {
+ #if !os(WASI)
// Copy extended attributes
var size = flistxattr(srcFD, nil, 0)
if size > 0 {
@@ -976,6 +977,7 @@ enum _FileOperations {
}
}
}
+ #endif
var statInfo = stat()
if fstat(srcFD, &statInfo) == 0 {
// Copy owner/group
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 88ddc3cc219262ea2c3d421be0333b8625b4d77c Mon Sep 17 00:00:00 2001
From: Yuta Saito <[email protected]>
Date: Sat, 14 Dec 2024 06:48:35 +0000
Subject: [PATCH 2/4] Gate `fchown` and `fchmod` calls behind `os(WASI)`

They are not available on WASI, so we gate them behind `os(WASI)`.
---
Sources/FoundationEssentials/FileManager/FileOperations.swift | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
index 9567f65..49e2c37 100644
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
@@ -980,10 +980,12 @@ enum _FileOperations {
#endif
var statInfo = stat()
if fstat(srcFD, &statInfo) == 0 {
+ #if !os(WASI) // WASI doesn't have fchown for now
// Copy owner/group
if fchown(dstFD, statInfo.st_uid, statInfo.st_gid) != 0 {
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
}
+ #endif

// Copy modification date
let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000)
@@ -996,10 +998,12 @@ enum _FileOperations {
}
}

+ #if !os(WASI) // WASI doesn't have fchmod for now
// Copy permissions
if fchmod(dstFD, mode_t(statInfo.st_mode)) != 0 {
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
}
+ #endif
} else {
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
}
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From 694cc281ab301a2b0f9b18d17d59aa8e5f94b65a Mon Sep 17 00:00:00 2001
From: Yuta Saito <[email protected]>
Date: Sat, 14 Dec 2024 09:12:24 +0000
Subject: [PATCH 3/4] Add missing constant shims for wasi-libc

---
Sources/FoundationEssentials/WASILibc+Extensions.swift | 9 +++++++++
Sources/_FoundationCShims/include/platform_shims.h | 4 ++++
2 files changed, 13 insertions(+)

diff --git a/Sources/FoundationEssentials/WASILibc+Extensions.swift b/Sources/FoundationEssentials/WASILibc+Extensions.swift
index 351fe19..44f3f93 100644
--- a/Sources/FoundationEssentials/WASILibc+Extensions.swift
+++ b/Sources/FoundationEssentials/WASILibc+Extensions.swift
@@ -49,5 +49,14 @@ internal var O_TRUNC: Int32 {
internal var O_WRONLY: Int32 {
return _platform_shims_O_WRONLY()
}
+internal var O_RDONLY: Int32 {
+ return _platform_shims_O_RDONLY()
+}
+internal var O_DIRECTORY: Int32 {
+ return _platform_shims_O_DIRECTORY()
+}
+internal var O_NOFOLLOW: Int32 {
+ return _platform_shims_O_NOFOLLOW()
+}

#endif // os(WASI)
diff --git a/Sources/_FoundationCShims/include/platform_shims.h b/Sources/_FoundationCShims/include/platform_shims.h
index 6bc0a0e..e02b581 100644
--- a/Sources/_FoundationCShims/include/platform_shims.h
+++ b/Sources/_FoundationCShims/include/platform_shims.h
@@ -102,6 +102,10 @@ 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_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; }
+
#endif

#endif /* CSHIMS_PLATFORM_SHIMS */
--
2.46.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From aed67387933a934e3734b9768a9467294569952b Mon Sep 17 00:00:00 2001
From: Yuta Saito <[email protected]>
Date: Sat, 14 Dec 2024 09:12:49 +0000
Subject: [PATCH 4/4] Use `futimens` instead of legacy `futimes`

wasi-libc does not provide `futimes` as it is a legacy function.
https://github.com/WebAssembly/wasi-libc/blob/574b88da481569b65a237cb80daf9a2d5aeaf82d/libc-top-half/musl/include/sys/time.h#L34
---
.../FoundationEssentials/FileManager/FileOperations.swift | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
index 49e2c37..2ef8a03 100644
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
@@ -988,11 +988,11 @@ enum _FileOperations {
#endif

// Copy modification date
- let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000)
+ let value = statInfo.st_mtim
var tv = (value, value)
try withUnsafePointer(to: &tv) {
- try $0.withMemoryRebound(to: timeval.self, capacity: 2) {
- if futimes(dstFD, $0) != 0 {
+ try $0.withMemoryRebound(to: timespec.self, capacity: 2) {
+ if futimens(dstFD, $0) != 0 {
try delegate.throwIfNecessary(errno, srcPath(), dstPath())
}
}
--
2.46.0

Loading