From b8006a9de07f4bde23f9828074d2ada3996c904e Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Tue, 27 Jan 2026 02:33:54 +0900 Subject: [PATCH] Add support for FreeBSD (#375) * Add partial support for FreeBSD This change will allow `swift build` to succeed. However, SwiftPM support is still incomplete and does not yet allow adding `.freebsd` to `.when(platforms:)`, so `swift test` cannot be executed. * Make `swift test` work on FreeBSD --- Package.swift | 2 ++ Sources/AsyncAlgorithms/Locking.swift | 4 ++++ Sources/AsyncSequenceValidation/TaskDriver.swift | 2 ++ 3 files changed, 8 insertions(+) diff --git a/Package.swift b/Package.swift index d0f2939..c23d0a1 100644 --- a/Package.swift +++ b/Package.swift @@ -72,6 +72,7 @@ let package = Package( .macCatalyst, .android, .linux, + .custom("freebsd"), .openbsd, .wasi, ]) @@ -87,6 +88,7 @@ let package = Package( .macCatalyst, .android, .linux, + .custom("freebsd"), .openbsd, .wasi, ]) diff --git a/Sources/AsyncAlgorithms/Locking.swift b/Sources/AsyncAlgorithms/Locking.swift index 9603b23..ffc6035 100644 --- a/Sources/AsyncAlgorithms/Locking.swift +++ b/Sources/AsyncAlgorithms/Locking.swift @@ -34,7 +34,11 @@ internal struct Lock { #if canImport(Darwin) typealias Primitive = os_unfair_lock #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) || canImport(wasi_pthread) + #if os(FreeBSD) || os(OpenBSD) + typealias Primitive = pthread_mutex_t? + #else typealias Primitive = pthread_mutex_t + #endif #elseif canImport(WASILibc) // This WASILibc variation is single threaded, provides no locks #elseif canImport(WinSDK) diff --git a/Sources/AsyncSequenceValidation/TaskDriver.swift b/Sources/AsyncSequenceValidation/TaskDriver.swift index 336164e..a3e7f1f 100644 --- a/Sources/AsyncSequenceValidation/TaskDriver.swift +++ b/Sources/AsyncSequenceValidation/TaskDriver.swift @@ -55,6 +55,8 @@ final class TaskDriver: Sendable { let queue: WorkQueue #if canImport(Darwin) || canImport(wasi_pthread) nonisolated(unsafe) var thread: pthread_t? + #elseif os(FreeBSD) + nonisolated(unsafe) var thread = pthread_t(bitPattern: 0) #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) nonisolated(unsafe) var thread = pthread_t() #elseif canImport(WinSDK)