Skip to content

Commit a6e9bdd

Browse files
committed
Add platform-specific branches for FreeBSD.
This PR adds support for FreeBSD where we have platform-specific code. Most changes simply involve changing `os(Linux)` to `os(Linux) || os(FreeBSD)`, although there is some actual platform-specific code and at least one spot where Darwin and FreeBSD share an implementation but Linux does not. > [!NOTE] > This new code is minimally tested. The Swift project does not officially > support FreeBSD.
1 parent dab00ae commit a6e9bdd

22 files changed

+95
-60
lines changed

Diff for: Sources/Testing/ABI/EntryPoints/EntryPoint.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ extension Event.ConsoleOutputRecorder.Options {
673673
/// Whether or not the system terminal claims to support 16-color ANSI escape
674674
/// codes.
675675
private static var _terminalSupports16ColorANSIEscapeCodes: Bool {
676-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
676+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
677677
if let termVariable = Environment.variable(named: "TERM") {
678678
return termVariable != "dumb"
679679
}
@@ -695,7 +695,7 @@ extension Event.ConsoleOutputRecorder.Options {
695695
/// Whether or not the system terminal claims to support 256-color ANSI escape
696696
/// codes.
697697
private static var _terminalSupports256ColorANSIEscapeCodes: Bool {
698-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
698+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
699699
if let termVariable = Environment.variable(named: "TERM") {
700700
return strstr(termVariable, "256") != nil
701701
}
@@ -717,7 +717,7 @@ extension Event.ConsoleOutputRecorder.Options {
717717
/// Whether or not the system terminal claims to support true-color ANSI
718718
/// escape codes.
719719
private static var _terminalSupportsTrueColorANSIEscapeCodes: Bool {
720-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
720+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
721721
if let colortermVariable = Environment.variable(named: "COLORTERM") {
722722
return strstr(colortermVariable, "truecolor") != nil
723723
}

Diff for: Sources/Testing/ABI/EntryPoints/SwiftPMEntryPoint.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private import _TestingInternals
2424
///
2525
/// This constant is not part of the public interface of the testing library.
2626
var EXIT_NO_TESTS_FOUND: CInt {
27-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
27+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
2828
EX_UNAVAILABLE
2929
#elseif os(Windows)
3030
CInt(ERROR_NOT_FOUND)

Diff for: Sources/Testing/Events/Recorder/Event.Symbol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension Event.Symbol {
100100
/// be used to represent it in text-based output. The value of this property
101101
/// is platform-dependent.
102102
public var unicodeCharacter: Character {
103-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
103+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
104104
switch self {
105105
case .default:
106106
// Unicode: WHITE DIAMOND

Diff for: Sources/Testing/ExitTests/ExitCondition.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public enum ExitCondition: Sendable {
4242
/// |-|-|
4343
/// | macOS | [`<stdlib.h>`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/_Exit.3.html), [`<sysexits.h>`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysexits.3.html) |
4444
/// | Linux | [`<stdlib.h>`](https://sourceware.org/glibc/manual/latest/html_node/Exit-Status.html), `<sysexits.h>` |
45+
/// | FreeBSD | `<stdlib.h>`, `<sysexits.h>` |
4546
/// | Windows | [`<stdlib.h>`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure) |
4647
///
47-
/// On macOS and Windows, the full exit code reported by the process is
48-
/// yielded to the parent process. Linux and other POSIX-like systems may only
49-
/// reliably report the low unsigned 8 bits (0&ndash;255) of the exit code.
48+
/// On macOS, FreeBSD, and Windows, the full exit code reported by the process
49+
/// is yielded to the parent process. Linux and other POSIX-like systems may
50+
/// only reliably report the low unsigned 8 bits (0&ndash;255) of the exit
51+
/// code.
5052
case exitCode(_ exitCode: CInt)
5153

5254
/// The process terminated with the given signal.
@@ -61,6 +63,7 @@ public enum ExitCondition: Sendable {
6163
/// |-|-|
6264
/// | macOS | [`<signal.h>`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/signal.3.html) |
6365
/// | Linux | [`<signal.h>`](https://sourceware.org/glibc/manual/latest/html_node/Standard-Signals.html) |
66+
/// | FreeBSD | `<signal.h>` |
6467
/// | Windows | [`<signal.h>`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/signal-constants) |
6568
///
6669
/// On Windows, by default, the C runtime will terminate a process with exit

Diff for: Sources/Testing/ExitTests/ExitTest.swift

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public struct ExitTest: Sendable {
4747
EXCEPTION_DEFAULT,
4848
THREAD_STATE_NONE
4949
)
50-
#elseif os(Linux)
51-
// On Linux, disable the generation of core files (although they will often
52-
// be disabled by default.) If a particular Linux distro performs additional
53-
// crash diagnostics, we may want to special-case them as well if we can.
50+
#elseif os(Linux) || os(FreeBSD)
51+
// On Linux and FreeBSD, disable the generation of core files (although they
52+
// will often be disabled by default.) If a particular Linux distro performs
53+
// additional crash diagnostics, we may want to special-case them as well if we can.
5454
var rl = rlimit(rlim_cur: 0, rlim_max: 0)
5555
_ = setrlimit(CInt(RLIMIT_CORE.rawValue), &rl)
5656
#elseif os(Windows)
@@ -322,13 +322,14 @@ extension ExitTest {
322322
for key in childEnvironment.keys where key.starts(with: "XCTest") {
323323
childEnvironment.removeValue(forKey: key)
324324
}
325-
#elseif os(Linux)
325+
#endif
326+
326327
if childEnvironment["SWIFT_BACKTRACE"] == nil {
327328
// Disable interactive backtraces unless explicitly enabled to reduce
328-
// the noise level during the exit test. Only needed on Linux.
329+
// the noise level during the exit test.
329330
childEnvironment["SWIFT_BACKTRACE"] = "enable=no"
330331
}
331-
#endif
332+
332333
// Insert a specific variable that tells the child process which exit test
333334
// to run.
334335
try JSON.withEncoding(of: exitTest.sourceLocation) { json in
@@ -364,11 +365,11 @@ extension ExitTest {
364365
// use, so use this typealias to paper over the differences.
365366
#if SWT_TARGET_OS_APPLE
366367
typealias P<T> = T?
367-
#elseif os(Linux)
368+
#elseif os(Linux) || os(FreeBSD)
368369
typealias P<T> = T
369370
#endif
370371

371-
#if SWT_TARGET_OS_APPLE || os(Linux)
372+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD)
372373
let pid = try withUnsafeTemporaryAllocation(of: P<posix_spawn_file_actions_t>.self, capacity: 1) { fileActions in
373374
guard 0 == posix_spawn_file_actions_init(fileActions.baseAddress!) else {
374375
throw CError(rawValue: swt_errno())

Diff for: Sources/Testing/ExitTests/WaitFor.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
internal import _TestingInternals
1414

15-
#if SWT_TARGET_OS_APPLE || os(Linux)
15+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD)
1616
/// Block the calling thread, wait for the target process to exit, and return
1717
/// a value describing the conditions under which it exited.
1818
///
@@ -104,11 +104,16 @@ private let _createWaitThreadImpl: Void = {
104104
{ _ in
105105
// Set the thread name to help with diagnostics. Note that different
106106
// platforms support different thread name lengths. See MAXTHREADNAMESIZE
107-
// on Darwin and TASK_COMM_LEN on Linux.
107+
// on Darwin, TASK_COMM_LEN on Linux, and MAXCOMLEN on FreeBSD. We try to
108+
// maximize legibility in the available space.
108109
#if SWT_TARGET_OS_APPLE
109110
_ = pthread_setname_np("Swift Testing exit test monitor")
110-
#else
111+
#elseif os(Linux)
111112
_ = pthread_setname_np(pthread_self(), "SWT ExT monitor")
113+
#elseif os(FreeBSD)
114+
_ = pthread_set_name_np(pthread_self(), "SWT ex test monitor")
115+
#else
116+
#warning("Platform-specific implementation missing: thread naming unavailable")
112117
#endif
113118

114119
// Run an infinite loop that waits for child processes to terminate and

Diff for: Sources/Testing/SourceAttribution/Backtrace+Symbolication.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ extension Backtrace {
7070
result[i] = SymbolicatedAddress(address: address, offset: offset, symbolName: symbolName)
7171
}
7272
}
73-
#elseif os(Linux)
74-
// Although Linux has dladdr(), it does not have symbol names from ELF
75-
// binaries by default. The standard library's backtracing functionality has
76-
// implemented sufficient ELF/DWARF parsing to be able to symbolicate Linux
77-
// backtraces. TODO: adopt the standard library's Backtrace on Linux
78-
// Note that this means on Linux we don't have demangling capability (since
79-
// we don't have the mangled symbol names in the first place) so this code
80-
// does not check the mode argument.
73+
#elseif os(Linux) || os(FreeBSD) || os(Android)
74+
// Although these platforms have dladdr(), they do not have symbol names
75+
// from DWARF binaries by default, only from shared libraries. The standard
76+
// library's backtracing functionality has implemented sufficient ELF/DWARF
77+
// parsing to be able to symbolicate Linux backtraces.
78+
// TODO: adopt the standard library's Backtrace on these platforms
8179
#elseif os(Windows)
8280
_withDbgHelpLibrary { hProcess in
8381
guard let hProcess else {

Diff for: Sources/Testing/SourceAttribution/Backtrace.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct Backtrace: Sendable {
6969
initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in
7070
.init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
7171
}
72-
#elseif os(Linux)
72+
#elseif os(Linux) || os(FreeBSD)
7373
initializedCount = .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
7474
#elseif os(Windows)
7575
initializedCount = Int(clamping: RtlCaptureStackBackTrace(0, ULONG(clamping: addresses.count), addresses.baseAddress!, nil))

Diff for: Sources/Testing/Support/Additions/CommandLineAdditions.swift

+14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ extension CommandLine {
3838
buffer[readCount] = 0 // NUL-terminate the string.
3939
return String(cString: buffer.baseAddress!)
4040
}
41+
#elseif os(FreeBSD)
42+
var mib = [CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1]
43+
try mib.withUnsafeMutableBufferPointer { mib in
44+
var bufferCount = 0
45+
guard 0 == sysctl(mib.baseAddress!, .init(mib.count), nil, &bufferCount, nil, 0) else {
46+
throw CError(rawValue: swt_errno())
47+
}
48+
return try withUnsafeTemporaryAllocation(of: CChar.self, capacity: bufferCount) { buffer in
49+
guard 0 == sysctl(mib.baseAddress!, .init(mib.count), nil, &bufferCount, nil, 0) else {
50+
throw CError(rawValue: swt_errno())
51+
}
52+
return String(cString: buffer.baseAddress!)
53+
}
54+
}
4155
#elseif os(Windows)
4256
return try withUnsafeTemporaryAllocation(of: wchar_t.self, capacity: Int(MAX_PATH) * 2) { buffer in
4357
guard 0 != GetModuleFileNameW(nil, buffer.baseAddress!, DWORD(buffer.count)) else {

Diff for: Sources/Testing/Support/Environment.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enum Environment {
4242
}
4343
}
4444

45-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
45+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
4646
/// Get all environment variables from a POSIX environment block.
4747
///
4848
/// - Parameters:
@@ -103,7 +103,7 @@ enum Environment {
103103
}
104104
#endif
105105
return _get(fromEnviron: _NSGetEnviron()!.pointee!)
106-
#elseif os(Linux) || os(Android)
106+
#elseif os(Linux) || os(FreeBSD) || os(Android)
107107
_get(fromEnviron: swt_environ())
108108
#elseif os(WASI)
109109
_get(fromEnviron: __wasilibc_get_environ())
@@ -170,7 +170,7 @@ enum Environment {
170170
}
171171
return nil
172172
}
173-
#elseif SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
173+
#elseif SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
174174
getenv(name).flatMap { String(validatingCString: $0) }
175175
#elseif os(Windows)
176176
name.withCString(encodedAs: UTF16.self) { name in

Diff for: Sources/Testing/Support/FileHandle.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct FileHandle: ~Copyable, Sendable {
156156
/// descriptor, `nil` is passed to `body`.
157157
borrowing func withUnsafePOSIXFileDescriptor<R>(_ body: (CInt?) throws -> R) rethrows -> R {
158158
try withUnsafeCFILEHandle { handle in
159-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
159+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
160160
let fd = fileno(handle)
161161
#elseif os(Windows)
162162
let fd = _fileno(handle)
@@ -215,7 +215,7 @@ struct FileHandle: ~Copyable, Sendable {
215215
/// other threads.
216216
borrowing func withLock<R>(_ body: () throws -> R) rethrows -> R {
217217
try withUnsafeCFILEHandle { handle in
218-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
218+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
219219
flockfile(handle)
220220
defer {
221221
funlockfile(handle)
@@ -250,7 +250,7 @@ extension FileHandle {
250250
// If possible, reserve enough space in the resulting buffer to contain
251251
// the contents of the file being read.
252252
var size: Int?
253-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
253+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
254254
withUnsafePOSIXFileDescriptor { fd in
255255
var s = stat()
256256
if let fd, 0 == fstat(fd, &s) {
@@ -388,7 +388,7 @@ extension FileHandle {
388388
extension FileHandle {
389389
/// Is this file handle a TTY or PTY?
390390
var isTTY: Bool {
391-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
391+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
392392
// If stderr is a TTY and TERM is set, that's good enough for us.
393393
withUnsafePOSIXFileDescriptor { fd in
394394
if let fd, 0 != isatty(fd), let term = Environment.variable(named: "TERM"), !term.isEmpty {
@@ -414,7 +414,7 @@ extension FileHandle {
414414

415415
/// Is this file handle a pipe or FIFO?
416416
var isPipe: Bool {
417-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || os(WASI)
417+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
418418
withUnsafePOSIXFileDescriptor { fd in
419419
guard let fd else {
420420
return false

Diff for: Sources/Testing/Support/GetSymbol.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal import _TestingInternals
1313
#if !SWT_NO_DYNAMIC_LINKING
1414

1515
/// The platform-specific type of a loaded image handle.
16-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
16+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
1717
typealias ImageAddress = UnsafeMutableRawPointer
1818
#elseif os(Windows)
1919
typealias ImageAddress = HMODULE
@@ -28,7 +28,7 @@ typealias ImageAddress = Never
2828
/// and cannot be imported directly into Swift. As well, `RTLD_DEFAULT` is only
2929
/// defined on Linux when `_GNU_SOURCE` is defined, so it is not sufficient to
3030
/// declare a wrapper function in the internal module's Stubs.h file.
31-
#if SWT_TARGET_OS_APPLE
31+
#if SWT_TARGET_OS_APPLE || os(FreeBSD)
3232
private nonisolated(unsafe) let RTLD_DEFAULT = ImageAddress(bitPattern: -2)
3333
#elseif os(Android) && _pointerBitWidth(_32)
3434
private nonisolated(unsafe) let RTLD_DEFAULT = ImageAddress(bitPattern: UInt(0xFFFFFFFF))
@@ -59,7 +59,7 @@ private nonisolated(unsafe) let RTLD_DEFAULT = ImageAddress(bitPattern: 0)
5959
/// calling `EnumProcessModules()` and iterating over the returned handles
6060
/// looking for one containing the given function.
6161
func symbol(in handle: ImageAddress? = nil, named symbolName: String) -> UnsafeRawPointer? {
62-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android)
62+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
6363
dlsym(handle ?? RTLD_DEFAULT, symbolName).map(UnsafeRawPointer.init)
6464
#elseif os(Windows)
6565
symbolName.withCString { symbolName in

Diff for: Sources/Testing/Support/Locked.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
3636
/// To keep the implementation of this type as simple as possible,
3737
/// `pthread_mutex_t` is used on Apple platforms instead of `os_unfair_lock`
3838
/// or `OSAllocatedUnfairLock`.
39-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
39+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
4040
private typealias _Lock = pthread_mutex_t
4141
#elseif os(Windows)
4242
private typealias _Lock = SRWLOCK
@@ -52,7 +52,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
5252
private final class _Storage: ManagedBuffer<T, _Lock> {
5353
deinit {
5454
withUnsafeMutablePointerToElements { lock in
55-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
55+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
5656
_ = pthread_mutex_destroy(lock)
5757
#elseif os(Windows)
5858
// No deinitialization needed.
@@ -71,7 +71,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
7171
init(rawValue: T) {
7272
_storage = _Storage.create(minimumCapacity: 1, makingHeaderWith: { _ in rawValue })
7373
_storage.withUnsafeMutablePointerToElements { lock in
74-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
74+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
7575
_ = pthread_mutex_init(lock, nil)
7676
#elseif os(Windows)
7777
InitializeSRWLock(lock)
@@ -101,7 +101,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
101101
/// concurrency tools.
102102
nonmutating func withLock<R>(_ body: (inout T) throws -> R) rethrows -> R {
103103
try _storage.withUnsafeMutablePointers { rawValue, lock in
104-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
104+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
105105
_ = pthread_mutex_lock(lock)
106106
defer {
107107
_ = pthread_mutex_unlock(lock)
@@ -121,7 +121,7 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
121121
}
122122
}
123123

124-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
124+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
125125
/// Acquire the lock and invoke a function while it is held, yielding both the
126126
/// protected value and a reference to the lock itself.
127127
///

Diff for: Sources/Testing/Support/Versions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let operatingSystemVersion: String = {
3131
default:
3232
return "\(productVersion) (\(buildNumber))"
3333
}
34-
#elseif !SWT_NO_UNAME && (SWT_TARGET_OS_APPLE || os(Linux) || os(WASI))
34+
#elseif !SWT_NO_UNAME && (SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD))
3535
var name = utsname()
3636
if 0 == uname(&name) {
3737
let release = withUnsafeBytes(of: name.release) { release in

Diff for: Sources/Testing/Traits/Tags/Tag.Color+Loading.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
private import _TestingInternals
1212

1313
#if !SWT_NO_FILE_IO
14-
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux)
14+
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux) || os(FreeBSD)
1515
/// The path to the current user's home directory, if known.
1616
private var _homeDirectoryPath: String? {
1717
#if SWT_TARGET_OS_APPLE
@@ -57,7 +57,7 @@ var swiftTestingDirectoryPath: String? {
5757
// The (default) name of the .swift-testing directory.
5858
let swiftTestingDirectoryName = ".swift-testing"
5959

60-
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux)
60+
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux) || os(FreeBSD)
6161
if let homeDirectoryPath = _homeDirectoryPath {
6262
return appendPathComponent(swiftTestingDirectoryName, to: homeDirectoryPath)
6363
}

Diff for: Sources/_TestingInternals/Discovery.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void enumerateTypeMetadataSections(const SectionEnumerator& body) {
306306
}
307307
}
308308

309-
#elif defined(__linux__) || defined(_WIN32) || defined(__wasi__) || defined(__ANDROID__)
309+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(_WIN32) || defined(__wasi__) || defined(__ANDROID__)
310310
#pragma mark - Linux/Windows implementation
311311

312312
/// Specifies the address range corresponding to a section.

Diff for: Sources/_TestingInternals/include/Includes.h

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@
125125
#endif
126126
#endif
127127

128+
#if defined(__FreeBSD__)
129+
#include <sys/auxv.h>
130+
#include <sys/elf_common.h>
131+
#endif
132+
128133
#if defined(_WIN32)
129134
#define WIN32_LEAN_AND_MEAN
130135
#define NOMINMAX

Diff for: Sources/_TestingInternals/include/Stubs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static LANGID swt_MAKELANGID(int p, int s) {
8585
}
8686
#endif
8787

88-
#if defined(__linux__) || defined(__ANDROID__)
88+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__ANDROID__)
8989
/// The environment block.
9090
///
9191
/// By POSIX convention, the environment block variable is declared in client

0 commit comments

Comments
 (0)