Skip to content

Commit 5e4695d

Browse files
authored
Basic OpenBSD support. (#3572)
Pepper in the right conditionals throughout. The unversioned triple issue is still necessary for the bootstrap script (and only the bootstrap script) which we will deal with separately.
1 parent 38df7c3 commit 5e4695d

File tree

11 files changed

+24
-6
lines changed

11 files changed

+24
-6
lines changed

Sources/Basics/DispatchTimeInterval+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension DispatchTimeInterval {
5959
}
6060

6161
// remove when available to all platforms
62-
#if os(Linux) || os(Windows) || os(Android)
62+
#if os(Linux) || os(Windows) || os(Android) || os(OpenBSD)
6363
extension DispatchTime {
6464
public func distance(to: DispatchTime) -> DispatchTimeInterval {
6565
let duration = to.uptimeNanoseconds - self.uptimeNanoseconds

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public class SwiftTool {
380380
#if os(Windows)
381381
// Exit as if by signal()
382382
TerminateProcess(GetCurrentProcess(), 3)
383-
#elseif os(macOS)
383+
#elseif os(macOS) || os(OpenBSD)
384384
// Install the default signal handler.
385385
var action = sigaction()
386386
action.__sigaction_u.__sa_handler = SIG_DFL

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ extension PackageModel.Platform {
459459
self = PackageModel.Platform.windows
460460
case let name where name.contains("wasi"):
461461
self = PackageModel.Platform.wasi
462+
case let name where name.contains("openbsd"):
463+
self = PackageModel.Platform.openbsd
462464
default:
463465
return nil
464466
}

Sources/PackageDescription/SupportedPlatforms.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public struct Platform: Encodable, Equatable {
5151
/// The WebAssembly System Interface platform.
5252
@available(_PackageDescription, introduced: 5.3)
5353
public static let wasi: Platform = Platform(name: "wasi")
54+
55+
/// The OpenBSD platform.
56+
@available(_PackageDescription, introduced: 999.0)
57+
public static let openbsd: Platform = Platform(name: "openbsd")
5458
}
5559

5660
/// A platform that the Swift package supports.

Sources/PackageLoading/PlatformRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public final class PlatformRegistry {
3131

3232
/// The static list of known platforms.
3333
private static var _knownPlatforms: [Platform] {
34-
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit]
34+
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
3535
}
3636
}

Sources/PackageModel/Platform.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public struct Platform: Equatable, Hashable, Codable {
3535
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
3636
public static let windows: Platform = Platform(name: "windows", oldestSupportedVersion: .unknown)
3737
public static let wasi: Platform = Platform(name: "wasi", oldestSupportedVersion: .unknown)
38+
public static let openbsd: Platform = Platform(name: "openbsd", oldestSupportedVersion: .unknown)
3839

3940
}
4041

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fileprivate extension Triple.OS {
7676
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
7777
var asXCFrameworkPlatformString: String? {
7878
switch self {
79-
case .darwin, .linux, .wasi, .windows:
79+
case .darwin, .linux, .wasi, .windows, .openbsd:
8080
return nil // XCFrameworks do not support any of these platforms today.
8181
case .macOS:
8282
return "macos"

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public struct BuildParameters: Encodable {
148148
return .wasi
149149
} else if self.triple.isWindows() {
150150
return .windows
151+
} else if self.triple.isOpenBSD() {
152+
return .openbsd
151153
} else {
152154
return .linux
153155
}

Tests/PackageCollectionsTests/Utility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func makeMockSources(count: Int = Int.random(in: 5 ... 10)) -> [PackageCollectio
2828
}
2929

3030
func makeMockCollections(count: Int = Int.random(in: 50 ... 100), maxPackages: Int = 50, signed: Bool = true) -> [PackageCollectionsModel.Collection] {
31-
let platforms: [PackageModel.Platform] = [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .windows, .wasi]
31+
let platforms: [PackageModel.Platform] = [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .windows, .wasi, .openbsd]
3232
let supportedPlatforms: [PackageModel.SupportedPlatform] = [
3333
.init(platform: .macOS, version: .init("10.15")),
3434
.init(platform: .iOS, version: .init("13")),

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ class PackageBuilderTests: XCTestCase {
16881688
"android": "0.0",
16891689
"windows": "0.0",
16901690
"wasi": "0.0",
1691+
"openbsd": "0.0",
16911692
]
16921693

16931694
PackageBuilderTester(manifest, in: fs) { package, _ in
@@ -1746,6 +1747,7 @@ class PackageBuilderTests: XCTestCase {
17461747
"android": "0.0",
17471748
"windows": "0.0",
17481749
"wasi": "0.0",
1750+
"openbsd": "0.0",
17491751
]
17501752

17511753
PackageBuilderTester(manifest, in: fs) { package, _ in

Utilities/bootstrap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,12 @@ def get_swiftpm_flags(args):
782782
# TensorFlow).
783783
if platform.system() == "Darwin":
784784
swift_library_rpath_prefix = "@executable_path/../"
785-
elif platform.system() == 'Linux':
785+
elif platform.system() == 'Linux' or platform.system() == 'OpenBSD':
786786
# `$ORIGIN` is an ELF construct.
787787
swift_library_rpath_prefix = "$ORIGIN/../"
788+
if platform.system() == 'OpenBSD':
789+
build_flags.extend(["-Xlinker", "-z", "-Xlinker", "origin"])
790+
788791
platform_path = None
789792
for path in args.target_info["paths"]["runtimeLibraryPaths"]:
790793
platform_path = re.search(r"(lib/swift/([^/]+))$", path)
@@ -819,6 +822,10 @@ def get_swiftpm_flags(args):
819822
'android-', args.cross_compile_hosts)):
820823
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
821824

825+
if platform.system() == "OpenBSD":
826+
build_flags.extend(["-Xcc", "-I/usr/local/include"])
827+
build_flags.extend(["-Xlinker", "-L/usr/local/lib"])
828+
822829
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
823830
# installed executables and shared libraries.
824831
if platform.system() != "Darwin" and args.command == 'install':

0 commit comments

Comments
 (0)