Skip to content

Commit 7bb860b

Browse files
committed
Basic OpenBSD support.
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 22bfd6b commit 7bb860b

File tree

9 files changed

+21
-5
lines changed

9 files changed

+21
-5
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)
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
}

Utilities/bootstrap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,12 @@ def get_swiftpm_flags(args):
776776
# TensorFlow).
777777
if platform.system() == "Darwin":
778778
swift_library_rpath_prefix = "@executable_path/../"
779-
elif platform.system() == 'Linux':
779+
elif platform.system() == 'Linux' or platform.system() == 'OpenBSD':
780780
# `$ORIGIN` is an ELF construct.
781781
swift_library_rpath_prefix = "$ORIGIN/../"
782+
if platform.system() == 'OpenBSD':
783+
build_flags.extend(["-Xlinker", "-z", "-Xlinker", "origin"])
784+
782785
platform_path = None
783786
for path in args.target_info["paths"]["runtimeLibraryPaths"]:
784787
platform_path = re.search(r"(lib/swift/([^/]+))$", path)
@@ -812,6 +815,10 @@ def get_swiftpm_flags(args):
812815
if 'ANDROID_DATA' in os.environ:
813816
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
814817

818+
if platform.system() == "OpenBSD":
819+
build_flags.extend(["-Xcc", "-I/usr/local/include"])
820+
build_flags.extend(["-Xlinker", "-L/usr/local/lib"])
821+
815822
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
816823
# installed executables and shared libraries.
817824
if platform.system() != "Darwin" and args.command == 'install':

0 commit comments

Comments
 (0)