Skip to content

Basic OpenBSD support. #3572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Basics/DispatchTimeInterval+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension DispatchTimeInterval {
}

// remove when available to all platforms
#if os(Linux) || os(Windows) || os(Android)
#if os(Linux) || os(Windows) || os(Android) || os(OpenBSD)
extension DispatchTime {
public func distance(to: DispatchTime) -> DispatchTimeInterval {
let duration = to.uptimeNanoseconds - self.uptimeNanoseconds
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public class SwiftTool {
#if os(Windows)
// Exit as if by signal()
TerminateProcess(GetCurrentProcess(), 3)
#elseif os(macOS)
#elseif os(macOS) || os(OpenBSD)
// Install the default signal handler.
var action = sigaction()
action.__sigaction_u.__sa_handler = SIG_DFL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ extension PackageModel.Platform {
self = PackageModel.Platform.windows
case let name where name.contains("wasi"):
self = PackageModel.Platform.wasi
case let name where name.contains("openbsd"):
self = PackageModel.Platform.openbsd
default:
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/PackageDescription/SupportedPlatforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public struct Platform: Encodable, Equatable {
/// The WebAssembly System Interface platform.
@available(_PackageDescription, introduced: 5.3)
public static let wasi: Platform = Platform(name: "wasi")

/// The OpenBSD platform.
@available(_PackageDescription, introduced: 999.0)
public static let openbsd: Platform = Platform(name: "openbsd")
}

/// A platform that the Swift package supports.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageLoading/PlatformRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public final class PlatformRegistry {

/// The static list of known platforms.
private static var _knownPlatforms: [Platform] {
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit]
return [.macOS, .macCatalyst, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit, .openbsd]
}
}
1 change: 1 addition & 0 deletions Sources/PackageModel/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public struct Platform: Equatable, Hashable, Codable {
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
public static let windows: Platform = Platform(name: "windows", oldestSupportedVersion: .unknown)
public static let wasi: Platform = Platform(name: "wasi", oldestSupportedVersion: .unknown)
public static let openbsd: Platform = Platform(name: "openbsd", oldestSupportedVersion: .unknown)

}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMBuildCore/BinaryTarget+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fileprivate extension Triple.OS {
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
var asXCFrameworkPlatformString: String? {
switch self {
case .darwin, .linux, .wasi, .windows:
case .darwin, .linux, .wasi, .windows, .openbsd:
return nil // XCFrameworks do not support any of these platforms today.
case .macOS:
return "macos"
Expand Down
2 changes: 2 additions & 0 deletions Sources/SPMBuildCore/BuildParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public struct BuildParameters: Encodable {
return .wasi
} else if self.triple.isWindows() {
return .windows
} else if self.triple.isOpenBSD() {
return .openbsd
} else {
return .linux
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/PackageCollectionsTests/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func makeMockSources(count: Int = Int.random(in: 5 ... 10)) -> [PackageCollectio
}

func makeMockCollections(count: Int = Int.random(in: 50 ... 100), maxPackages: Int = 50, signed: Bool = true) -> [PackageCollectionsModel.Collection] {
let platforms: [PackageModel.Platform] = [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .windows, .wasi]
let platforms: [PackageModel.Platform] = [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .windows, .wasi, .openbsd]
let supportedPlatforms: [PackageModel.SupportedPlatform] = [
.init(platform: .macOS, version: .init("10.15")),
.init(platform: .iOS, version: .init("13")),
Expand Down
2 changes: 2 additions & 0 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ class PackageBuilderTests: XCTestCase {
"android": "0.0",
"windows": "0.0",
"wasi": "0.0",
"openbsd": "0.0",
]

PackageBuilderTester(manifest, in: fs) { package, _ in
Expand Down Expand Up @@ -1746,6 +1747,7 @@ class PackageBuilderTests: XCTestCase {
"android": "0.0",
"windows": "0.0",
"wasi": "0.0",
"openbsd": "0.0",
]

PackageBuilderTester(manifest, in: fs) { package, _ in
Expand Down
9 changes: 8 additions & 1 deletion Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,12 @@ def get_swiftpm_flags(args):
# TensorFlow).
if platform.system() == "Darwin":
swift_library_rpath_prefix = "@executable_path/../"
elif platform.system() == 'Linux':
elif platform.system() == 'Linux' or platform.system() == 'OpenBSD':
# `$ORIGIN` is an ELF construct.
swift_library_rpath_prefix = "$ORIGIN/../"
if platform.system() == 'OpenBSD':
build_flags.extend(["-Xlinker", "-z", "-Xlinker", "origin"])

platform_path = None
for path in args.target_info["paths"]["runtimeLibraryPaths"]:
platform_path = re.search(r"(lib/swift/([^/]+))$", path)
Expand Down Expand Up @@ -812,6 +815,10 @@ def get_swiftpm_flags(args):
if 'ANDROID_DATA' in os.environ:
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])

if platform.system() == "OpenBSD":
build_flags.extend(["-Xcc", "-I/usr/local/include"])
build_flags.extend(["-Xlinker", "-L/usr/local/lib"])

# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
# installed executables and shared libraries.
if platform.system() != "Darwin" and args.command == 'install':
Expand Down