Skip to content

Commit 5847726

Browse files
committed
Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal with progressing the build to completion on OpenBSD or addressing minor portability issues. This is not the full set of changes to get a successful build; other portability issues will be addressed in future commits. Most of this is just adding the relevant clauses to the ifdefs, but of note in this commit: * StdlibUnittest.swift: the default conditional in _getOSVersion assumes an Apple platform, therefore the explicit conditional and the relevant enums need filling out. The default conditional should be #error, but we'll fix this in a different commit. * tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r. Tests are updated correspondingly. * ThreadLocalStorage.h: we use the pthread implementation, so it seems we should typedef __swift_thread_key_t as pthread_key_t. However, that's also a tweak for another commit.
1 parent bd30df9 commit 5847726

File tree

16 files changed

+35
-19
lines changed

16 files changed

+35
-19
lines changed

include/swift/Runtime/Mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <type_traits>
2222

23-
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__))
23+
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__))
2424
#include "swift/Runtime/MutexPThread.h"
2525
#elif defined(_WIN32)
2626
#include "swift/Runtime/MutexWin32.h"

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import SwiftPrivateLibcExtras
4141
import SwiftPrivateThreadExtras
4242
#if os(macOS) || os(iOS)
4343
import Darwin
44-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
44+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
4545
import Glibc
4646
#elseif os(Windows)
4747
import MSVCRT

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SwiftPrivate
1414
import SwiftPrivateLibcExtras
1515
#if os(macOS) || os(iOS)
1616
import Darwin
17-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
17+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
1818
import Glibc
1919
#elseif os(Windows)
2020
import MSVCRT

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftPrivateLibcExtras
1818
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1919
import Foundation
2020
import Darwin
21-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
21+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
2222
import Glibc
2323
#elseif os(Windows)
2424
import MSVCRT
@@ -1744,6 +1744,7 @@ public enum OSVersion : CustomStringConvertible {
17441744
case watchOSSimulator
17451745
case linux
17461746
case freeBSD
1747+
case openBSD
17471748
case android
17481749
case ps4
17491750
case windowsCygnus
@@ -1771,6 +1772,8 @@ public enum OSVersion : CustomStringConvertible {
17711772
return "Linux"
17721773
case .freeBSD:
17731774
return "FreeBSD"
1775+
case .openBSD:
1776+
return "OpenBSD"
17741777
case .ps4:
17751778
return "PS4"
17761779
case .android:
@@ -1817,6 +1820,8 @@ func _getOSVersion() -> OSVersion {
18171820
return .linux
18181821
#elseif os(FreeBSD)
18191822
return .freeBSD
1823+
#elseif os(OpenBSD)
1824+
return .openBSD
18201825
#elseif os(PS4)
18211826
return .ps4
18221827
#elseif os(Android)

stdlib/private/StdlibUnittest/SymbolLookup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
1414
import Darwin
15-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
15+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
1616
import Glibc
1717
#elseif os(Windows)
1818
import MSVCRT
@@ -21,7 +21,7 @@
2121
#error("Unsupported platform")
2222
#endif
2323

24-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
24+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(OpenBSD)
2525
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
2626
#elseif os(Linux)
2727
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: 0)

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SwiftPrivate
1414
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
16+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
1717
import Glibc
1818
#elseif os(Windows)
1919
import MSVCRT

stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SwiftPrivate
1414
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
16+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
1717
import Glibc
1818
#elseif os(Windows)
1919
import MSVCRT

stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1919
import Darwin
20-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
20+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(Cygwin) || os(Haiku)
2121
import Glibc
2222
#elseif os(Windows)
2323
import MSVCRT

stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1414
import Darwin
15-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
15+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(OpenBSD)
1616
import Glibc
1717
#elseif os(Windows)
1818
import MSVCRT
@@ -33,7 +33,7 @@ public struct _stdlib_thread_barrier_t {
3333
#if os(Windows)
3434
var mutex: UnsafeMutablePointer<SRWLOCK>?
3535
var cond: UnsafeMutablePointer<CONDITION_VARIABLE>?
36-
#elseif os(Cygwin) || os(FreeBSD)
36+
#elseif os(Cygwin) || os(FreeBSD) || os(OpenBSD)
3737
var mutex: UnsafeMutablePointer<pthread_mutex_t?>?
3838
var cond: UnsafeMutablePointer<pthread_cond_t?>?
3939
#else

stdlib/public/Platform/Platform.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ public var SIG_DFL: sig_t? { return nil }
332332
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
333333
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
334334
public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) }
335+
#elseif os(OpenBSD)
336+
public var SIG_DFL: sig_t? { return nil }
337+
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
338+
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
339+
public var SIG_HOLD: sig_t { return unsafeBitCast(3, to: sig_t.self) }
335340
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Haiku)
336341
public typealias sighandler_t = __sighandler_t
337342

@@ -382,7 +387,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
382387
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
383388
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
384389
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
385-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
390+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
386391
// The value is ABI. Value verified to be correct on Glibc.
387392
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
388393
#else
@@ -412,7 +417,7 @@ public func sem_open(
412417
//===----------------------------------------------------------------------===//
413418

414419
// Some platforms don't have `extern char** environ` imported from C.
415-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
420+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(OpenBSD) || os(PS4)
416421
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {
417422
return _swift_stdlib_getEnviron()
418423
}

0 commit comments

Comments
 (0)