Skip to content

Commit 1d45a98

Browse files
authored
OpenBSD support. (#365)
* Ensure the swift-crypto dependency is conditioned for the platform. The relevant swift-crypto changes are not landed upstream yet, but when they are, this picks up the dependency. * Cast timestamps to time_t. This is done unconditionally here, because the standard specifies that `tv_sec` in `timespec` has type `time_t`, and doing so avoids a type mismatch error on the platform. * Since pthread types are pointers here, make the usual changes to capture the fact they are optional types on the Swift side. So far, this has been the only set of changes that have seemed necessary. Fixes #114.
1 parent 8693c3a commit 1d45a98

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ let package = Package(
195195
"SWBCSupport",
196196
"SWBLibc",
197197
.product(name: "ArgumentParser", package: "swift-argument-parser"),
198-
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .android])),
198+
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .openbsd, .android])),
199199
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
200200
],
201201
exclude: ["CMakeLists.txt"],

Sources/SWBUtil/FSProxy.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ class LocalFS: FSProxy, @unchecked Sendable {
665665
let UTIME_OMIT = 1073741822
666666
#endif
667667
let atime = timespec(tv_sec: 0, tv_nsec: Int(UTIME_OMIT))
668-
let mtime = timespec(tv_sec: timestamp, tv_nsec: 0)
668+
let mtime = timespec(tv_sec: time_t(timestamp), tv_nsec: 0)
669669
guard utimensat(AT_FDCWD, path.str, [atime, mtime], 0) == 0 else {
670670
throw POSIXError(errno, context: "utimensat", "AT_FDCWD", path.str, String(timestamp))
671671
}
@@ -1390,7 +1390,7 @@ public class PseudoFS: FSProxy, @unchecked Sendable {
13901390
#if os(Windows)
13911391
info.st_mtimespec = timespec(tv_sec: Int64(node.timestamp), tv_nsec: 0)
13921392
#else
1393-
info.st_mtimespec = timespec(tv_sec: node.timestamp, tv_nsec: 0)
1393+
info.st_mtimespec = timespec(tv_sec: time_t(node.timestamp), tv_nsec: 0)
13941394
#endif
13951395
info.st_size = off_t(contents.bytes.count)
13961396
info.st_dev = node.device
@@ -1403,7 +1403,7 @@ public class PseudoFS: FSProxy, @unchecked Sendable {
14031403
info.st_mtimespec = timespec(tv_sec: Int64(node.timestamp), tv_nsec: 0)
14041404
#else
14051405
info.st_mode = S_IFDIR
1406-
info.st_mtimespec = timespec(tv_sec: node.timestamp, tv_nsec: 0)
1406+
info.st_mtimespec = timespec(tv_sec: time_t(node.timestamp), tv_nsec: 0)
14071407
#endif
14081408
info.st_size = off_t(dir.contents.count)
14091409
info.st_dev = node.device
@@ -1416,7 +1416,7 @@ public class PseudoFS: FSProxy, @unchecked Sendable {
14161416
info.st_mtimespec = timespec(tv_sec: Int64(node.timestamp), tv_nsec: 0)
14171417
#else
14181418
info.st_mode = S_IFLNK
1419-
info.st_mtimespec = timespec(tv_sec: node.timestamp, tv_nsec: 0)
1419+
info.st_mtimespec = timespec(tv_sec: time_t(node.timestamp), tv_nsec: 0)
14201420
#endif
14211421
info.st_size = off_t(0)
14221422
info.st_dev = node.device

Sources/SWBUtil/Lock.swift

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public final class Lock: @unchecked Sendable {
2626
#if os(Windows)
2727
@usableFromInline
2828
let mutex: UnsafeMutablePointer<SRWLOCK> = UnsafeMutablePointer.allocate(capacity: 1)
29+
#elseif os(OpenBSD)
30+
@usableFromInline
31+
let mutex: UnsafeMutablePointer<pthread_mutex_t?> = UnsafeMutablePointer.allocate(capacity: 1)
2932
#else
3033
@usableFromInline
3134
let mutex: UnsafeMutablePointer<pthread_mutex_t> = UnsafeMutablePointer.allocate(capacity: 1)

0 commit comments

Comments
 (0)