Skip to content

Commit 0cf39c0

Browse files
michael-yujijakepetroules
authored andcommitted
fix FreeBSD build
1 parent b464fcd commit 0cf39c0

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

Sources/TSCBasic/Process/Process.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public final class Process {
625625
return stdinPipe.fileHandleForWriting
626626
#elseif (!canImport(Darwin) || os(macOS))
627627
// Initialize the spawn attributes.
628-
#if canImport(Darwin) || os(Android) || os(OpenBSD)
628+
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
629629
var attributes: posix_spawnattr_t? = nil
630630
#else
631631
var attributes = posix_spawnattr_t()
@@ -670,7 +670,7 @@ public final class Process {
670670
posix_spawnattr_setflags(&attributes, Int16(flags))
671671

672672
// Setup the file actions.
673-
#if canImport(Darwin) || os(Android) || os(OpenBSD)
673+
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
674674
var fileActions: posix_spawn_file_actions_t? = nil
675675
#else
676676
var fileActions = posix_spawn_file_actions_t()
@@ -686,6 +686,8 @@ public final class Process {
686686
if #available(macOS 10.15, *) {
687687
posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory)
688688
}
689+
#elseif os(FreeBSD)
690+
posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory)
689691
#elseif os(Linux)
690692
guard SPM_posix_spawn_file_actions_addchdir_np_supported() else {
691693
throw Process.Error.workingDirectoryNotSupported

Sources/TSCUtility/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ target_link_libraries(TSCUtility PRIVATE
5050
Threads::Threads)
5151

5252
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
53-
if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
53+
if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
5454
target_link_directories(TSCUtility PRIVATE /usr/local/lib)
5555
endif()
5656
if(Foundation_FOUND)

Sources/TSCUtility/FSWatch.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class FSWatch {
5050
self.paths = paths
5151
self.latency = latency
5252

53-
#if os(OpenBSD)
53+
#if os(OpenBSD) || os(FreeBSD)
5454
self._watcher = NoOpWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
5555
#elseif os(Windows)
5656
self._watcher = RDCWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
@@ -100,7 +100,7 @@ private protocol _FileWatcher {
100100
func stop()
101101
}
102102

103-
#if os(OpenBSD) || (!os(macOS) && canImport(Darwin))
103+
#if os(OpenBSD) || os(FreeBSD) || (!os(macOS) && canImport(Darwin))
104104
extension FSWatch._WatcherDelegate: NoOpWatcherDelegate {}
105105
extension NoOpWatcher: _FileWatcher{}
106106
#elseif os(Windows)
@@ -118,7 +118,7 @@ extension FSEventStream: _FileWatcher{}
118118

119119
// MARK:- inotify
120120

121-
#if os(OpenBSD) || (!os(macOS) && canImport(Darwin))
121+
#if os(FreeBSD) || os(OpenBSD) || (!os(macOS) && canImport(Darwin))
122122

123123
public protocol NoOpWatcherDelegate {
124124
func pathsDidReceiveEvent(_ paths: [AbsolutePath])

Sources/TSCUtility/InterruptHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class InterruptHandler {
7474
}
7575
#else
7676
var action = sigaction()
77-
#if canImport(Darwin) || os(OpenBSD)
77+
#if canImport(Darwin) || os(OpenBSD) || os(FreeBSD)
7878
action.__sigaction_u.__sa_handler = self.signalHandler
7979
#elseif os(Android)
8080
action.sa_handler = self.signalHandler

Sources/TSCUtility/Triple.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public struct Triple: Encodable, Equatable, Sendable {
7272
case windows
7373
case wasi
7474
case openbsd
75+
case freebsd
7576
}
7677

7778
public enum ABI: Encodable, Equatable, RawRepresentable, Sendable {
@@ -182,6 +183,10 @@ public struct Triple: Encodable, Equatable, Sendable {
182183
return os == .openbsd
183184
}
184185

186+
public func isFreeBSD() -> Bool {
187+
return os == .freebsd
188+
}
189+
185190
/// Returns the triple string for the given platform version.
186191
///
187192
/// This is currently meant for Apple platforms only.
@@ -252,7 +257,7 @@ extension Triple {
252257
switch os {
253258
case .darwin, .macOS:
254259
return ".dylib"
255-
case .linux, .openbsd:
260+
case .linux, .openbsd, .freebsd:
256261
return ".so"
257262
case .windows:
258263
return ".dll"
@@ -265,7 +270,7 @@ extension Triple {
265270
switch os {
266271
case .darwin, .macOS:
267272
return ""
268-
case .linux, .openbsd:
273+
case .linux, .openbsd, .freebsd:
269274
return ""
270275
case .wasi:
271276
return ".wasm"

0 commit comments

Comments
 (0)