Skip to content

Conversation

@kkebo
Copy link

@kkebo kkebo commented Nov 6, 2025

I've added support for FreeBSD. I've only tested this PR on FreeBSD, but I believe it should also work on OpenBSD.

Motivation:

closes #372

Also, Swift on FreeBSD preview toolchain is now available.

Modifications:

  • changed pthread-related code for *BSD
  • changed Glibc.stdout and Glibc.stderr for *BSD because they are non-optional on *BSD

Result:

swift-log and packages depending on it will be usable on FreeBSD.

Checks:

I tested it with swift build and swift test. All tests have passed.

$ swift test
...
Test Suite 'All tests' passed at 2025-11-07 04:29:34.003                                                                                         
         Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
...
✔ Test run with 52 tests in 7 suites passed after 0.309 seconds.

Environment:

$ uname -a
FreeBSD Coconut-rhinoceros-beetle 15.0-BETA4 FreeBSD 15.0-BETA4 releng/15.0-n280841-a7707f2a3bf4 GENERIC amd64
$ swift --version
Swift version 6.3-dev (LLVM bff1370bd79c983, Swift 57cf4ce563f700b)
Target: x86_64-unknown-freebsd14.3
Build config: +assertions

Swift toolchain is from https://forums.swift.org/t/swift-on-freebsd-preview/83064.

@3405691582
Copy link

OpenBSD post 7.8 also needs the following changes, but otherwise swift-log compiles with this patch. Do you mind integrating this and rebasing?

diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift
index a93b9a1..b3d897a 100644
--- a/Sources/Logging/Logging.swift
+++ b/Sources/Logging/Logging.swift
@@ -1312,7 +1312,7 @@ public struct MultiplexLogHandler: LogHandler {
     }
 }
 
-#if canImport(WASILibc) || os(Android)
+#if canImport(WASILibc) || os(Android) || os(OpenBSD)
 internal typealias CFilePointer = OpaquePointer
 #else
 internal typealias CFilePointer = UnsafeMutablePointer<FILE>
diff --git a/Tests/LoggingTests/TestLogger.swift b/Tests/LoggingTests/TestLogger.swift
index 7d6258a..fc77249 100644
--- a/Tests/LoggingTests/TestLogger.swift
+++ b/Tests/LoggingTests/TestLogger.swift
@@ -375,6 +375,10 @@ public class MDC {
         return Int(pthread_mach_thread_np(pthread_self()))
         #elseif os(Windows)
         return Int(GetCurrentThreadId())
+        #elseif os(FreeBSD)
+        return Int(pthread_getthreadid_np())
+        #elseif os(OpenBSD)
+        return Int(bitPattern: pthread_self())
         #else
         return Int(pthread_self())
         #endif

@kkebo
Copy link
Author

kkebo commented Dec 13, 2025

Yes, sure.

@kkebo
Copy link
Author

kkebo commented Dec 13, 2025

@3405691582 I've added those changes. Thank you for your suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BSD support

3 participants