Skip to content

fix FreeBSD build #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
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
6 changes: 4 additions & 2 deletions Sources/TSCBasic/Process/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public final class Process {
return stdinPipe.fileHandleForWriting
#elseif (!canImport(Darwin) || os(macOS))
// Initialize the spawn attributes.
#if canImport(Darwin) || os(Android) || os(OpenBSD)
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
var attributes: posix_spawnattr_t? = nil
#else
var attributes = posix_spawnattr_t()
Expand Down Expand Up @@ -670,7 +670,7 @@ public final class Process {
posix_spawnattr_setflags(&attributes, Int16(flags))

// Setup the file actions.
#if canImport(Darwin) || os(Android) || os(OpenBSD)
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
var fileActions: posix_spawn_file_actions_t? = nil
#else
var fileActions = posix_spawn_file_actions_t()
Expand All @@ -686,6 +686,8 @@ public final class Process {
if #available(macOS 10.15, *) {
posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory)
}
#elseif os(FreeBSD)
posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory)
#elseif os(Linux)
guard SPM_posix_spawn_file_actions_addchdir_np_supported() else {
throw Process.Error.workingDirectoryNotSupported
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSCUtility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target_link_libraries(TSCUtility PRIVATE
Threads::Threads)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
target_link_directories(TSCUtility PRIVATE /usr/local/lib)
endif()
if(Foundation_FOUND)
Expand Down
6 changes: 3 additions & 3 deletions Sources/TSCUtility/FSWatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class FSWatch {
self.paths = paths
self.latency = latency

#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
self._watcher = NoOpWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
#elseif os(Windows)
self._watcher = RDCWatcher(paths: paths, latency: latency, delegate: _WatcherDelegate(block: block))
Expand Down Expand Up @@ -100,7 +100,7 @@ private protocol _FileWatcher {
func stop()
}

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

// MARK:- inotify

#if os(OpenBSD) || (!os(macOS) && canImport(Darwin))
#if os(FreeBSD) || os(OpenBSD) || (!os(macOS) && canImport(Darwin))

public protocol NoOpWatcherDelegate {
func pathsDidReceiveEvent(_ paths: [AbsolutePath])
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSCUtility/InterruptHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final class InterruptHandler {
}
#else
var action = sigaction()
#if canImport(Darwin) || os(OpenBSD)
#if canImport(Darwin) || os(OpenBSD) || os(FreeBSD)
action.__sigaction_u.__sa_handler = self.signalHandler
#elseif os(Android)
action.sa_handler = self.signalHandler
Expand Down
9 changes: 7 additions & 2 deletions Sources/TSCUtility/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public struct Triple: Encodable, Equatable, Sendable {
case windows
case wasi
case openbsd
case freebsd
}

public enum ABI: Encodable, Equatable, RawRepresentable, Sendable {
Expand Down Expand Up @@ -182,6 +183,10 @@ public struct Triple: Encodable, Equatable, Sendable {
return os == .openbsd
}

public func isFreeBSD() -> Bool {
return os == .freebsd
}

/// Returns the triple string for the given platform version.
///
/// This is currently meant for Apple platforms only.
Expand Down Expand Up @@ -252,7 +257,7 @@ extension Triple {
switch os {
case .darwin, .macOS:
return ".dylib"
case .linux, .openbsd:
case .linux, .openbsd, .freebsd:
return ".so"
case .windows:
return ".dll"
Expand All @@ -265,7 +270,7 @@ extension Triple {
switch os {
case .darwin, .macOS:
return ""
case .linux, .openbsd:
case .linux, .openbsd, .freebsd:
return ""
case .wasi:
return ".wasm"
Expand Down