Skip to content

Commit f5c8317

Browse files
committed
Work around lack of embed in OpenBSD's clang.
For various reasons, the Swift toolchain for OpenBSD relies on using the platform's native clang, which is 16. clang 19 is the most recent version that will not emit an error with the new __has_embed features in C23. Since swift-testing is experimentally supported by OpenBSD and thus to make swift-testing build again on the platform, work around the issue with a platform-specific command-line specified macro override in swiftpm and in cmake, though this does not seem to block the cmake build. Furthermore, we can use cmake trickery to subsitute the version file contents instead of using embed. This may not be possible to do with swiftpm, but I don't know for sure.
1 parent 279629f commit f5c8317

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ let package = Package(
200200
.target(
201201
name: "_TestingInternals",
202202
exclude: ["CMakeLists.txt"],
203-
cxxSettings: .packageSettings
203+
cxxSettings: .packageSettings + [
204+
.unsafeFlags(["-D__has_embed(x)=0"], .when(platforms: [.openbsd]))
205+
],
204206
),
205207
.target(
206208
name: "_TestDiscovery",
@@ -466,6 +468,7 @@ extension Array where Element == PackageDescription.CXXSetting {
466468

467469
.define("SWT_NO_LEGACY_TEST_DISCOVERY", .whenEmbedded()),
468470
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),
471+
.define("SWT_TESTING_LIBRARY_VERSION", to: "\"0.0\"", .when(platforms: [.openbsd]))
469472
]
470473

471474
// Capture the testing library's commit info as C++ constants.

Sources/_TestingInternals/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ if("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC" OR
2323
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
2424
target_compile_options(_TestingInternals PRIVATE
2525
-fno-exceptions -fPIC)
26+
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
27+
target_compile_options(_TestingInternals PRIVATE
28+
-fno-exceptions
29+
-DSWT_TESTING_LIBRARY_VERSION="${SWT_VERSION_FILE_CONTENTS}")
2630
else()
2731
target_compile_options(_TestingInternals PRIVATE
2832
-fno-exceptions)

cmake/modules/shared/CompilerSettings.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
4242
add_compile_definitions("SWT_NO_DYNAMIC_LINKING")
4343
add_compile_definitions("SWT_NO_PIPES")
4444
endif()
45+
if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
46+
file(STRINGS "../VERSION.txt" SWT_VERSION_FILE_CONTENTS)
47+
endif()

0 commit comments

Comments
 (0)