Skip to content

Conversation

3405691582
Copy link
Member

@3405691582 3405691582 commented Sep 17, 2025

Work around lack of embed in OpenBSD's clang.

Motivation:

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.

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.

Resolves rdar://160591315.

Modifications:

  • Add -D__has_embed=0 and use cmake's file(STRINGS) to the cmake build.
  • Add -D__has_embed=0 to Package.swift when the platform is OpenBSD.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@3405691582
Copy link
Member Author

@swift-ci please test.

@3405691582
Copy link
Member Author

3405691582 commented Sep 17, 2025

cc @grynspan from our conversation in #1304.

@grynspan grynspan added bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process openbsd 🐡 OpenBSD support labels Sep 17, 2025
@grynspan grynspan added this to the Swift 6.x (main) milestone Sep 17, 2025
@3405691582 3405691582 requested a review from grynspan September 17, 2025 01:26
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_compile_options(_TestingInternals PRIVATE
-fno-exceptions
-DSWT_TESTING_LIBRARY_VERSION="${SWT_VERSION_FILE_CONTENTS}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you moved the definition of ${SWT_VERSION_FILE_CONTENTS} to CompilerSettings.cmake, but not that of SWT_TESTING_LIBRARY_VERSION.

What' I'd ask you do here is:

  • Remove this -D line from this file, as it's inconsistent with how we define other C++ macros
  • Add an equivalent add_compile_definitions() call in CompilerSettings.cmake after the call to file(STRINGS)
  • And this last one is nitpicky but call the intermediate CMake value ${SWT_TESTING_LIBRARY_VERSION} instead of ${SWT_VERSION_FILE_CONTENTS} for consistency and so it's clear they refer to the same value.

Thanks much! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. I thought to keep it more local to where it is used but got this to apply neatly with some generator expression magic.

@3405691582 3405691582 force-pushed the embed branch 2 times, most recently from 2e3612c to 5484a49 Compare September 17, 2025 02:17
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.

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.
@grynspan
Copy link
Contributor

I assume you've been able to test this change, yes? Ideally both the package and CMake avenues, but since OpenBSD support is experimental I'll be okay with "whatever @3405691582 thinks is sufficient." 😬

@3405691582
Copy link
Member Author

Yes, I have been running swift build and the CMake build as part of the toolchain to test.

Always define SWT_TESTING_LIBRARY_VERSION in CMake
Check the major clang version before attempting to use `__has_embed` or `__clang_major__`.
@grynspan grynspan added the linux 🐧 Linux support (all distros) label Sep 17, 2025
@grynspan grynspan changed the title Work around lack of embed in OpenBSD's clang. Work around lack of embed in clang on OpenBSD and Amazon Linux 2. Sep 17, 2025
@grynspan
Copy link
Contributor

I've updated the PR description to cover the Amazon Linux 2 failure. See here: https://ci.swift.org/job/oss-swift-package-amazon-linux-2-aarch64/4545

The buildbot over yonder has clang 13:

[2025-09-15T04:17:46.060Z] -- The C compiler identification is Clang 13.0.0
[2025-09-15T04:17:46.060Z] -- The CXX compiler identification is Clang 13.0.0

clang in CI jobs is 17.x but can handle `__has_embed`.
@grynspan
Copy link
Contributor

Sorry, looks like an earlier comment I made didn't land? We noticed the same issue on Amazon Linux 2 which has clang 13 😱 hence me adjusting the PR. Thanks!

@3405691582
Copy link
Member Author

Out of curiosity -- do you need to adjust the Package.swift for the Linux variants?

@grynspan
Copy link
Contributor

We can't reliably distinguish Amazon Linux 2 in the package, so no. The effect is that there will be a build warning when building from a package on AL2, but that's unavoidable. AL2 is quite old and an outlier in various other ways, so this doesn't bother me too too much.

grynspan added a commit to grynspan/github-workflows that referenced this pull request Sep 17, 2025
This change adds a call to `clang --version` after `swift --version` in the PR
workflow YML file. The result of this command is useful for investigating issues
stemming from out-of-date clang builds such as
swiftlang/swift-testing#1320.
shahmishal pushed a commit to swiftlang/github-workflows that referenced this pull request Sep 17, 2025
This change adds a call to `clang --version` after `swift --version` in the PR
workflow YML file. The result of this command is useful for investigating issues
stemming from out-of-date clang builds such as
swiftlang/swift-testing#1320.
…the cause of the failure rather than #embed itself)
@grynspan grynspan added the android 🤖 Android support label Sep 17, 2025
@grynspan
Copy link
Contributor

Looks like Android was impacted as well. https://ci-external.swift.org/job/swift-main-windows-toolchain/1597

@grynspan
Copy link
Contributor

Sorry for the noise, @3405691582! Just working through CI problems here. We'll merge this change shortly.

@3405691582
Copy link
Member Author

No problems, it's interesting to see the ancillary changes :D

@grynspan grynspan merged commit 05b4639 into swiftlang:main Sep 17, 2025
18 checks passed
grynspan added a commit that referenced this pull request Sep 17, 2025
grynspan added a commit that referenced this pull request Sep 17, 2025
Fixes a bug introduced in #1320.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@grynspan
Copy link
Contributor

grynspan commented Oct 4, 2025

@3405691582 I put together a branch here that uses .incbin instead of #embed. However, given that OpenBSD's maintainers merged LLVM 19 in June, it's only a matter of time before a new release includes it and this all becomes moot. So I haven't opened a PR, but it's in our back pocket if it becomes critical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android 🤖 Android support bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process linux 🐧 Linux support (all distros) openbsd 🐡 OpenBSD support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants