Add support for FreeBSD and OpenBSD#387
Conversation
|
OpenBSD post 7.8 also needs the following changes, but otherwise swift-log compiles with this patch. Do you mind integrating this and rebasing? |
|
Yes, sure. |
|
@3405691582 I've added those changes. Thank you for your suggestions! |
|
I've been using this successfully via var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-log", branch: "pull/387/head"),
] |
ktoso
left a comment
There was a problem hiding this comment.
While we don't have CI for this platform seems folks used this successfully... we can always keep updating if it happened to be slightly off
|
Sorry this is taking a while to integrate -- would you mind rebasing? I don't have a freebsd at hand to verify I'll get the changes right |
|
@ktoso I've resolved the conflict with a92ccc6. Also, I found that a92ccc6 was broken on OpenBSD because it was using uninitialized swift-log/Sources/Logging/Locks.swift Line 75 in 0d9c9ae Finally, I verified that my changes were appropriate using $ freebsd-version
15.0-RELEASE-p1
$ uname -a
FreeBSD Coconut-rhinoceros-beetle 15.0-RELEASE-p1 FreeBSD 15.0-RELEASE-p1 releng/15.0-n280999-7bceec30b351 GENERIC amd64
$ swift --version
Swift version 6.3-dev (LLVM b58b2a34d509492, Swift cf535d8b998d09b)
Target: x86_64-unknown-freebsd14.3
Build config: +assertions
$ swift test
[1/1] Planning build
Building for debugging...
[41/41] Linking swift-logPackageTests.xctest
Build complete! (6.41s)
Test Suite 'All tests' started at 2026-01-15 22:13:08.972
Test Suite 'debug.xctest' started at 2026-01-15 22:13:09.007
Test Suite 'debug.xctest' passed at 2026-01-15 22:13:09.007
Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
Test Suite 'All tests' passed at 2026-01-15 22:13:09.007
Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
◇ Test run started.
↳ Testing Library Version: 6.3-dev (98430f2d6cb8d81)
↳ Target Platform: x86_64-unknown-freebsd
◇ Suite GlobalLoggerTest started.
◇ Suite MDCTest started.
◇ Suite SendableTest started.
◇ Suite MetadataProviderTest started.
◇ Suite LocalLoggerTest started.
◇ Suite CompatibilityTest started.
◇ Suite InMemoryLogHandlerTests started.
◇ Suite LoggingTest started.
...
✔ Suite GlobalLoggerTest passed after 0.307 seconds.
✔ Test run with 57 tests in 8 suites passed after 0.307 seconds. |
|
The |
This PR adds support for FreeBSD to the `CNIOSHA1` target and the `NIOConcurrencyHelpers` target. ### Motivation: This PR is partial because the `NIOCore` target still can't be built, and the existing PR #3398 includes almost the same changes too. However, #3398 is a little bit old. Besides, the source code in `NIOConcurrencyHelpers` is used in other repositories now, for example: - apple/swift-log#398 - apple/swift-log#387 was merged before swift-nio is fixed. So I think it's important to fix `NIOConcurrencyHelpers` first, even if the entire swift-nio is yet to be fixed. ### Modifications: - Make `swift build --target NIOConcurrencyHelpers` work on FreeBSD - Make `swift build --target CNIOSHA1` work on FreeBSD ### Result: The following commands finished successfully. ```shell swift build --target NIOConcurrencyHelpers swift build --target CNIOSHA1 ``` Environment: - FreeBSD 15.0-RELEASE-p1 x86_64 - [Swift on FreeBSD Preview toolchain](https://forums.swift.org/t/swift-on-freebsd-preview/83064) ``` Swift version 6.3-dev (LLVM b58b2a34d509492, Swift cf535d8b998d09b) Target: x86_64-unknown-freebsd14.3 Build config: +assertions ``` --------- Co-authored-by: Cory Benfield <[email protected]>
### Motivation: NIOLock's pthread fallback branch types LockPrimitive as pthread_mutex_t and initializes pthread_mutexattr_t with a default initializer; both compile on Linux but fail on FreeBSD/OpenBSD where those types are opaque-pointer typedefs imported as Optional<OpaquePointer>. Additionally, PTHREAD_MUTEX_ERRORCHECK is imported as a pthread_mutextype enum case on FreeBSD whose .rawValue must be used to construct the CInt that pthread_mutexattr_settype expects. ### Modifications: Mirror the pattern landed in apple/swift-log#387: - alias LockPrimitive to pthread_mutex_t? on FreeBSD/OpenBSD - initialize pthread_mutexattr_t via the bitPattern overload - on FreeBSD/OpenBSD, access PTHREAD_MUTEX_ERRORCHECK via .rawValue before passing to pthread_mutexattr_settype ### Result: swift-prometheus compiles on FreeBSD with the official Swift FreeBSD preview toolchain.
### Motivation `ConcurrencyHelpers/Lock` has a pthread fallback branch (taken on every non-Windows / non-Darwin platform) that types `LockPrimitive` as `pthread_mutex_t` and initializes `pthread_mutexattr_t` with a default initializer. Both compile on Linux but fail on FreeBSD / OpenBSD, where those types are opaque-pointer typedefs Swift imports as `Optional<OpaquePointer>` — the no-argument initializers don't exist. This blocks swift-service-lifecycle (and everything that depends on it — Hummingbird, downstream HTTP servers) from compiling on FreeBSD with the official Swift FreeBSD preview toolchain. ### Modifications Mirror the pattern landed in [apple/swift-log#387][log-pr]; same change is being submitted for the sibling NIOLock copies (e.g. [apple/swift-http-types#123][sht-pr]): - On `os(FreeBSD) || os(OpenBSD)` alias `LockPrimitive` to `pthread_mutex_t?`. - In `LockOperations.create(_:)`, wrap `pthread_mutexattr_t()` with `#if os(FreeBSD) || os(OpenBSD)` to use the `bitPattern:` overload. [log-pr]: apple/swift-log#387 [sht-pr]: apple/swift-http-types#123 Touches one file (`Sources/ConcurrencyHelpers/Lock.swift`), +7 lines, all behind FreeBSD/OpenBSD conditionals. No behaviour change on existing platforms. ### Result `swift build` and `swift test` both clean on FreeBSD 15.0 with the official Swift FreeBSD preview toolchain: ``` $ uname -a FreeBSD swiftbuild 15.0-RELEASE FreeBSD 15.0-RELEASE-p9 releng/15.0-n281048-6d536196f1bd GENERIC amd64 $ swift --version Swift version 6.3-dev (LLVM 972b62858355d07, Swift 3f8c798cfe25bbb) Target: x86_64-unknown-freebsd14.3 Build config: +assertions $ swift build Building for debugging... ... 276 modules ... Build complete! (42.62s) $ swift test ... ClosureServiceTests passed ... ✔ Test run passed. ``` Without this change `ServiceLifecycle` fails to compile on the same toolchain. ### Checks - [x] Builds on Linux/Darwin (no change there, all changes guarded behind `#if os(FreeBSD) || os(OpenBSD)`). - [x] Builds + passes existing tests on FreeBSD 15.0 with Swift 6.3-dev preview toolchain. - [x] Same pattern as [apple/swift-log#387][log-pr] / [apple/swift-http-types#123][sht-pr].
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:
Glibc.stdoutandGlibc.stderrfor *BSD because they are non-optional on *BSDResult:
swift-log and packages depending on it will be usable on FreeBSD.
Checks:
I tested it with
swift buildandswift test. All tests have passed.Environment:
Swift toolchain is from https://forums.swift.org/t/swift-on-freebsd-preview/83064.