Skip to content

Commit 4fd8aeb

Browse files
authored
Fix FreeBSD build and test (#1149)
1 parent 2b5bdf1 commit 4fd8aeb

File tree

14 files changed

+41
-15
lines changed

14 files changed

+41
-15
lines changed

Sources/SwiftDocC/Benchmark/Benchmark.swift

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class Benchmark: Encodable {
4646
public let platform = "Linux"
4747
#elseif os(Android)
4848
public let platform = "Android"
49+
#elseif os(FreeBSD)
50+
public let platform = "FreeBSD"
4951
#else
5052
public let platform = "unsupported"
5153
#endif

Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ extension Benchmark {
6767
) else { return nil }
6868
return Int64(pmcStats.PeakWorkingSetSize)
6969
}
70+
#elseif os(FreeBSD)
71+
private static func peakMemory() -> Int64? {
72+
var usage = rusage()
73+
if (getrusage(RUSAGE_SELF, &usage) == -1) {
74+
return nil
75+
} else {
76+
return Int64(usage.ru_maxrss * 1024)
77+
}
78+
}
7079
#endif
7180

7281
public var result: MetricValue? {

Sources/SwiftDocC/Infrastructure/External Data/OutOfProcessReferenceResolver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private class LongRunningService: ExternalLinkResolving {
291291
/// This private class is only used by the ``OutOfProcessReferenceResolver`` and shouldn't be used for general communication with other processes.
292292
private class LongRunningProcess: ExternalLinkResolving {
293293

294-
#if os(macOS) || os(Linux) || os(Android)
294+
#if os(macOS) || os(Linux) || os(Android) || os(FreeBSD)
295295
private let process: Process
296296

297297
init(location: URL, errorOutputHandler: @escaping (String) -> Void) throws {

Sources/SwiftDocC/Model/Rendering/RenderContext.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public struct RenderContext {
6161
)
6262
}
6363

64-
#if os(macOS) || os(iOS) || os(Android) || os(Windows)
64+
#if os(macOS) || os(iOS) || os(Android) || os(Windows) || os(FreeBSD)
6565
// Concurrently render content on macOS/iOS, Windows & Android
6666
let results: [(reference: ResolvedTopicReference, content: RenderReferenceStore.TopicContent)] = references.concurrentPerform { reference, results in
6767
results.append((reference, renderContentFor(reference)))

Sources/SwiftDocC/Utility/FoundationExtensions/AutoreleasepoolShim.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
#if os(Linux) || os(Android) || os(Windows)
11+
#if os(Linux) || os(Android) || os(Windows) || os(FreeBSD)
1212
/// A shim for non-ObjC targets that runs the given block of code.
1313
///
1414
/// The existence of this shim allows you the use of auto-release pools to optimize memory footprint on Darwin platforms while maintaining

Sources/SwiftDocC/Utility/Synchronization.swift

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class Synchronized<Value> {
3535
#elseif os(Linux) || os(Android)
3636
/// A lock type appropriate for the current platform.
3737
var lock: UnsafeMutablePointer<pthread_mutex_t>
38+
#elseif os(FreeBSD)
39+
/// A lock type appropriate for the current platform.
40+
var lock: UnsafeMutablePointer<pthread_mutex_t?>
3841
#elseif os(Windows)
3942
var lock: UnsafeMutablePointer<SRWLOCK>
4043
#else
@@ -53,6 +56,10 @@ public class Synchronized<Value> {
5356
lock = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
5457
lock.initialize(to: pthread_mutex_t())
5558
pthread_mutex_init(lock, nil)
59+
#elseif os(FreeBSD)
60+
lock = UnsafeMutablePointer<pthread_mutex_t?>.allocate(capacity: 1)
61+
lock.initialize(to: nil)
62+
pthread_mutex_init(lock, nil)
5663
#elseif os(Windows)
5764
lock = UnsafeMutablePointer<SRWLOCK>.allocate(capacity: 1)
5865
InitializeSRWLock(lock)
@@ -77,6 +84,9 @@ public class Synchronized<Value> {
7784
#elseif os(Linux) || os(Android)
7885
pthread_mutex_lock(lock)
7986
defer { pthread_mutex_unlock(lock) }
87+
#elseif os(FreeBSD)
88+
pthread_mutex_lock(lock)
89+
defer { pthread_mutex_unlock(lock) }
8090
#elseif os(Windows)
8191
AcquireSRWLockExclusive(lock)
8292
defer { ReleaseSRWLockExclusive(lock) }
@@ -113,6 +123,9 @@ extension Lock {
113123
#elseif os(Linux) || os(Android)
114124
pthread_mutex_lock(lock)
115125
defer { pthread_mutex_unlock(lock) }
126+
#elseif os(FreeBSD)
127+
pthread_mutex_lock(lock)
128+
defer { pthread_mutex_unlock(lock) }
116129
#elseif os(Windows)
117130
AcquireSRWLockExclusive(lock)
118131
defer { ReleaseSRWLockExclusive(lock) }

Sources/SwiftDocCUtilities/Utility/DirectoryMonitor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Foundation
1212
import SwiftDocC
1313

14-
#if !os(Linux) && !os(Android) && !os(Windows)
14+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
1515
import Darwin
1616

1717
/// A throttle object to filter events that come too fast.

Sources/SwiftDocCUtilities/Utility/Signal.swift

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public struct Signal {
2525
signalAction.__sigaction_handler = unsafeBitCast(callback, to: sigaction.__Unnamed_union___sigaction_handler.self)
2626
#elseif os(Android)
2727
signalAction.sa_handler = callback
28+
#elseif os(FreeBSD)
29+
signalAction.__sigaction_u.__sa_handler = callback
2830
#else
2931
signalAction.__sigaction_u = unsafeBitCast(callback, to: __sigaction_u.self)
3032
#endif

Sources/docc/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
#if os(macOS) || os(Linux) || os(Android) || os(Windows)
11+
#if os(macOS) || os(Linux) || os(Android) || os(Windows) || os(FreeBSD)
1212
import SwiftDocCUtilities
1313

1414
await Task {

Tests/SwiftDocCTests/Servers/DocumentationSchemeHandlerTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DocumentationSchemeHandlerTests: XCTestCase {
2424
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
2525

2626
func testDocumentationSchemeHandler() {
27-
#if !os(Linux) && !os(Android) && !os(Windows)
27+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
2828
let topicSchemeHandler = DocumentationSchemeHandler(withTemplateURL: templateURL)
2929

3030
let request = URLRequest(url: baseURL.appendingPathComponent("/images/figure1.jpg"))
@@ -50,7 +50,7 @@ class DocumentationSchemeHandlerTests: XCTestCase {
5050
}
5151

5252
func testSetData() {
53-
#if !os(Linux) && !os(Android) && !os(Windows)
53+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
5454
let topicSchemeHandler = DocumentationSchemeHandler(withTemplateURL: templateURL)
5555

5656
let data = "hello!".data(using: .utf8)!

Tests/SwiftDocCTests/Servers/FileServerTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class FileServerTests: XCTestCase {
164164
(response, data) = fileServer.response(to: failingRequest)
165165
XCTAssertNil(data)
166166
// Initializing a URLResponse with `nil` as MIME type in Linux returns nil
167-
#if os(Linux) || os(Android) || os(Windows)
167+
#if os(Linux) || os(Android) || os(Windows) || os(FreeBSD)
168168
XCTAssertNil(response.mimeType)
169169
#else
170170
// Doing the same in macOS or iOS returns the default MIME type

Tests/SwiftDocCTests/Utility/LMDBTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ final class SwiftLMDBTests: XCTestCase {
237237
}
238238

239239
func testArrayOfInt() throws {
240-
#if !os(Linux) && !os(Android) && !os(Windows)
240+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
241241
let database = try environment.openDatabase()
242242

243243
var array: [UInt32] = []

Tests/SwiftDocCUtilitiesTests/C+Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Foundation
1212
#if os(Windows)
1313
import ucrt
14-
#elseif os(Linux) || os(Android)
14+
#elseif os(Linux) || os(Android) || os(FreeBSD)
1515
import Glibc
1616
#else
1717
import Darwin

Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import XCTest
1212
@testable import SwiftDocCUtilities
1313

14-
#if !os(Linux) && !os(Android) && !os(Windows)
14+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
1515
fileprivate extension NSNotification.Name {
1616
static let testNodeUpdated = NSNotification.Name(rawValue: "testNodeUpdated")
1717
static let testDirectoryReloaded = NSNotification.Name(rawValue: "testDirectoryReloaded")
@@ -24,7 +24,7 @@ func fileURLsAreEqual(_ url1: URL, _ url2: URL) -> Bool {
2424
#endif
2525

2626
class DirectoryMonitorTests: XCTestCase {
27-
#if !os(Linux) && !os(Android) && !os(Windows)
27+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
2828
// - MARK: Directory watching test infra
2929

3030
/// Method that automates setting up a directory monitor, setting up the relevant expectations for a test,
@@ -118,7 +118,7 @@ class DirectoryMonitorTests: XCTestCase {
118118
/// Tests a succession of file system changes and verifies that they produce
119119
/// the expected monitor events.
120120
func testMonitorUpdates() throws {
121-
#if !os(Linux) && !os(Android) && !os(Windows)
121+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
122122

123123
// Create temp folder & sub-folder.
124124
let tempSubfolderURL = try createTemporaryDirectory(named: "subfolder")
@@ -167,7 +167,7 @@ class DirectoryMonitorTests: XCTestCase {
167167
}
168168

169169
func testMonitorDoesNotTriggerUpdates() throws {
170-
#if !os(Linux) && !os(Android) && !os(Windows)
170+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
171171

172172
// Create temp folder & sub-folder.
173173
let tempSubfolderURL = try createTemporaryDirectory(named: "subfolder")
@@ -200,7 +200,7 @@ class DirectoryMonitorTests: XCTestCase {
200200

201201
/// Tests a zero sum change aggregation triggers an event.
202202
func testMonitorZeroSumSizeChangesUpdates() throws {
203-
#if !os(Linux) && !os(Android) && !os(Windows)
203+
#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD)
204204

205205
// Create temp folder & sub-folder.
206206
let tempSubfolderURL = try createTemporaryDirectory(named: "subfolder")

0 commit comments

Comments
 (0)