From 301a0c49fc2b12828b25eb292d8a9fc2b21e6caf Mon Sep 17 00:00:00 2001 From: 3405691582 Date: Fri, 29 Nov 2024 22:36:54 -0500 Subject: [PATCH] Swift on OpenBSD supports arm64. However, to do this, we end up changing how amd64 is supported too. Previously, I had tried to keep some meaningful separation between platform spelling and LLVM spelling, but this is becoming more difficult to meaningfully maintain. Target specifications are trivially converted LLVM triples, and the module files are looked up by LLVM triples. We can make sure that the targets align, but then the Glibc to SwiftGlibc import breaks. That could also be addressed, but then we get to a point where the targets set up by build-script and referenced by cmake begin to misalign. There are references in build-script-impl for a potential renaming site, but it's not quite enough. It's far simpler to give up and rename to LLVM spellings right at the beginning. This does mean that this commit is less constrained to just adding the necessary parts to enable arm64, but it should mean less headaches overall from differing architecture spellings. --- cmake/modules/SwiftConfigureSDK.cmake | 4 ++-- stdlib/cmake/modules/AddSwiftStdlib.cmake | 1 + stdlib/public/core/CTypes.swift | 2 ++ utils/build-script-impl | 3 ++- utils/swift_build_support/swift_build_support/targets.py | 6 ++++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake index 134a3f37abb55..b1dbea4f99919 100644 --- a/cmake/modules/SwiftConfigureSDK.cmake +++ b/cmake/modules/SwiftConfigureSDK.cmake @@ -429,14 +429,14 @@ macro(configure_sdk_unix name architectures) set(SWIFT_SDK_FREEBSD_ARCH_${arch}_TRIPLE "${arch}-unknown-freebsd${freebsd_system_version}") elseif("${prefix}" STREQUAL "OPENBSD") - if(NOT arch STREQUAL "amd64") + if(NOT arch STREQUAL "x86_64" AND NOT arch STREQUAL "aarch64") message(FATAL_ERROR "unsupported arch for OpenBSD: ${arch}") endif() set(openbsd_system_version ${CMAKE_SYSTEM_VERSION}) message(STATUS "OpenBSD Version: ${openbsd_system_version}") - set(SWIFT_SDK_OPENBSD_ARCH_amd64_TRIPLE "amd64-unknown-openbsd${openbsd_system_version}") + set(SWIFT_SDK_OPENBSD_ARCH_${arch}_TRIPLE "${arch}-unknown-openbsd${openbsd_system_version}") if(CMAKE_SYSROOT) set(SWIFT_SDK_OPENBSD_ARCH_${arch}_PATH "${CMAKE_SYSROOT}${SWIFT_SDK_OPENBSD_ARCH_${arch}_PATH}" CACHE INTERNAL "sysroot path" FORCE) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 55f4ac8225e3a..a078854dc95ca 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -529,6 +529,7 @@ function(_add_target_variant_link_flags) list(APPEND link_libraries "pthread") elseif("${LFLAGS_SDK}" STREQUAL "OPENBSD") list(APPEND link_libraries "pthread") + list(APPEND result "-Wl,-Bsymbolic") elseif("${LFLAGS_SDK}" STREQUAL "CYGWIN") # No extra libraries required. elseif("${LFLAGS_SDK}" STREQUAL "WINDOWS") diff --git a/stdlib/public/core/CTypes.swift b/stdlib/public/core/CTypes.swift index 87995bf616d92..628ba99a0312e 100644 --- a/stdlib/public/core/CTypes.swift +++ b/stdlib/public/core/CTypes.swift @@ -108,6 +108,8 @@ public typealias CLongDouble = Double #elseif os(OpenBSD) #if arch(x86_64) public typealias CLongDouble = Float80 +#elseif arch(arm64) +public typealias CLongDouble = Double #else #error("CLongDouble needs to be defined for this OpenBSD architecture") #endif diff --git a/utils/build-script-impl b/utils/build-script-impl index ff7abb2c04e99..05d9070cda52e 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -459,7 +459,8 @@ function verify_host_is_supported() { case ${host} in freebsd-arm64 \ | freebsd-x86_64 \ - | openbsd-amd64 \ + | openbsd-x86_64 \ + | openbsd-aarch64 \ | cygwin-x86_64 \ | haiku-x86_64 \ | linux-x86_64 \ diff --git a/utils/swift_build_support/swift_build_support/targets.py b/utils/swift_build_support/swift_build_support/targets.py index f5a2748914c22..508d6204eaf68 100644 --- a/utils/swift_build_support/swift_build_support/targets.py +++ b/utils/swift_build_support/swift_build_support/targets.py @@ -296,7 +296,7 @@ class StdlibDeploymentTarget(object): 'x86_64', 'aarch64']) - OpenBSD = OpenBSDPlatform("openbsd", archs=["amd64"]) + OpenBSD = OpenBSDPlatform("openbsd", archs=["x86_64", "aarch64"]) Cygwin = Platform("cygwin", archs=["x86_64"]) @@ -403,7 +403,9 @@ def host_target(): elif system == 'OpenBSD': if machine == 'amd64': - return StdlibDeploymentTarget.OpenBSD.amd64 + return StdlibDeploymentTarget.OpenBSD.x86_64 + elif machine == 'arm64': + return StdlibDeploymentTarget.OpenBSD.aarch64 elif system == 'CYGWIN_NT-10.0': if machine == 'x86_64':