Skip to content

Commit 018512a

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 018512a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Package.swift

Lines changed: 3 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",

Sources/_TestingInternals/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ 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+
file(STRINGS "../../VERSION.txt" SWT_VERSION_FILE_CONTENTS)
28+
target_compile_options(_TestingInternals PRIVATE
29+
-fno-exceptions
30+
"-D__has_embed(x)=0"
31+
-DSWT_TESTING_LIBRARY_VERSION="${SWT_VERSION_FILE_CONTENTS}")
2632
else()
2733
target_compile_options(_TestingInternals PRIVATE
2834
-fno-exceptions)

0 commit comments

Comments
 (0)