Skip to content

Commit a7f0a5e

Browse files
authored
Merge pull request #228 from 3405691582/OpenBSDSupport
OpenBSD support
2 parents c5dd301 + c87d728 commit a7f0a5e

File tree

8 files changed

+49
-12
lines changed

8 files changed

+49
-12
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public final class Process: ObjectIdentifierProtocol {
468468
return stdinPipe.fileHandleForWriting
469469
#else
470470
// Initialize the spawn attributes.
471-
#if canImport(Darwin) || os(Android)
471+
#if canImport(Darwin) || os(Android) || os(OpenBSD)
472472
var attributes: posix_spawnattr_t? = nil
473473
#else
474474
var attributes = posix_spawnattr_t()
@@ -513,7 +513,7 @@ public final class Process: ObjectIdentifierProtocol {
513513
posix_spawnattr_setflags(&attributes, Int16(flags))
514514

515515
// Setup the file actions.
516-
#if canImport(Darwin) || os(Android)
516+
#if canImport(Darwin) || os(Android) || os(OpenBSD)
517517
var fileActions: posix_spawn_file_actions_t? = nil
518518
#else
519519
var fileActions = posix_spawn_file_actions_t()

Sources/TSCBasic/TerminalController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ public final class TerminalController {
144144
// a temporary arrangement and needs to be fixed.
145145
#if !arch(powerpc64le)
146146
var ws = winsize()
147-
if ioctl(1, UInt(TIOCGWINSZ), &ws) == 0 {
147+
#if os(OpenBSD)
148+
let tiocgwinsz = 0x40087468
149+
let err = ioctl(1, UInt(tiocgwinsz), &ws)
150+
#else
151+
let err = ioctl(1, UInt(TIOCGWINSZ), &ws)
152+
#endif
153+
if err == 0 {
148154
return Int(ws.ws_col)
149155
}
150156
#endif

Sources/TSCUtility/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ target_link_libraries(TSCUtility PRIVATE
5353
Threads::Threads)
5454

5555
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
56+
if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
57+
target_link_directories(TSCUtility PRIVATE /usr/local/lib)
58+
endif()
5659
target_link_libraries(TSCUtility PRIVATE
5760
SQLite::SQLite3)
5861
if(Foundation_FOUND)

Sources/TSCUtility/FSWatch.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public class FSWatch {
4747
self.paths = paths
4848
self.latency = latency
4949

50-
#if canImport(Glibc)
50+
#if os(OpenBSD)
51+
self._watcher = NoOpWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
52+
#elseif canImport(Glibc)
5153
var ipaths: [AbsolutePath: Inotify.WatchOptions] = [:]
5254

5355
// FIXME: We need to recurse here.
@@ -93,17 +95,37 @@ private protocol _FileWatcher {
9395
func stop()
9496
}
9597

96-
#if canImport(Glibc)
98+
#if os(OpenBSD)
99+
extension FSWatch._WatcherDelegate: NoOpWatcherDelegate {}
100+
extension NoOpWatcher: _FileWatcher{}
101+
#elseif canImport(Glibc)
97102
extension FSWatch._WatcherDelegate: InotifyDelegate {}
98103
extension Inotify: _FileWatcher{}
99104
#elseif os(macOS)
100105
extension FSWatch._WatcherDelegate: FSEventStreamDelegate {}
101106
extension FSEventStream: _FileWatcher{}
107+
#else
108+
#error("Implementation required")
102109
#endif
103110

104111
// MARK:- inotify
105112

106-
#if canImport(Glibc)
113+
#if os(OpenBSD)
114+
115+
public protocol NoOpWatcherDelegate {
116+
func pathsDidReceiveEvent(_ paths: [AbsolutePath])
117+
}
118+
119+
public final class NoOpWatcher {
120+
public init(paths: [AbsolutePath], latency: Double, delegate: NoOpWatcherDelegate? = nil) {
121+
}
122+
123+
public func start() throws {}
124+
125+
public func stop() {}
126+
}
127+
128+
#elseif canImport(Glibc)
107129

108130
/// The delegate for receiving inotify events.
109131
public protocol InotifyDelegate {

Sources/TSCUtility/IndexStore.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ private final class IndexStoreAPIImpl {
223223
self.path = path
224224
#if os(Windows)
225225
let flags: DLOpenFlags = []
226-
#elseif os(Android)
227-
let flags: DLOpenFlags = [.lazy, .local, .first]
228226
#else
229227
let flags: DLOpenFlags = [.lazy, .local, .first, .deepBind]
230228
#endif

Sources/TSCUtility/InterruptHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public final class InterruptHandler {
6363
}
6464
#else
6565
var action = sigaction()
66-
#if canImport(Darwin)
66+
#if canImport(Darwin) || os(OpenBSD)
6767
action.__sigaction_u.__sa_handler = signalHandler
6868
#elseif os(Android)
6969
action.sa_handler = signalHandler

Sources/TSCUtility/Triple.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public struct Triple: Encodable, Equatable {
4141
case powerpc64le
4242
case s390x
4343
case aarch64
44+
case amd64
4445
case armv7
4546
case arm
4647
case arm64
@@ -59,6 +60,7 @@ public struct Triple: Encodable, Equatable {
5960
case linux
6061
case windows
6162
case wasi
63+
case openbsd
6264
}
6365

6466
public enum ABI: String, Encodable {
@@ -127,6 +129,10 @@ public struct Triple: Encodable, Equatable {
127129
return os == .wasi
128130
}
129131

132+
public func isOpenBSD() -> Bool {
133+
return os == .openbsd
134+
}
135+
130136
/// Returns the triple string for the given platform version.
131137
///
132138
/// This is currently meant for Apple platforms only.
@@ -173,7 +179,7 @@ extension Triple {
173179
switch os {
174180
case .darwin, .macOS:
175181
return ".dylib"
176-
case .linux:
182+
case .linux, .openbsd:
177183
return ".so"
178184
case .windows:
179185
return ".dll"
@@ -186,7 +192,7 @@ extension Triple {
186192
switch os {
187193
case .darwin, .macOS:
188194
return ""
189-
case .linux:
195+
case .linux, .openbsd:
190196
return ""
191197
case .wasi:
192198
return ".wasm"

Sources/TSCUtility/dlopen.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public struct DLOpenFlags: RawRepresentable, OptionSet {
6262
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
6363
#else
6464
public static let first: DLOpenFlags = DLOpenFlags(rawValue: 0)
65-
#if !os(Android)
65+
#if os(Linux)
6666
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: RTLD_DEEPBIND)
67+
#else
68+
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
6769
#endif
6870
#endif
6971
#endif

0 commit comments

Comments
 (0)