Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ extension Array where Element == PackageDescription.CXXSetting {

.define("SWT_NO_LEGACY_TEST_DISCOVERY", .whenEmbedded()),
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),

// OpenBSD's version of clang doesn't support __has_embed.
.define("SWT_TESTING_LIBRARY_VERSION", to: "0", .when(platforms: [.openbsd]))
]

// Capture the testing library's commit info as C++ constants.
Expand Down
7 changes: 6 additions & 1 deletion Sources/_TestingInternals/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const char *swt_getTestingLibraryVersion(void) {
#if defined(SWT_TESTING_LIBRARY_VERSION)
// The current environment explicitly specifies a version string to return.
return SWT_TESTING_LIBRARY_VERSION;
#elif __has_embed("../../VERSION.txt")
#elif __clang_major__ >= 17 && defined(__has_embed)
#if __has_embed("../../VERSION.txt")
static constinit auto version = [] () constexpr {
// Read the version from version.txt at the root of the package's repo.
char version[] = {
Expand All @@ -43,6 +44,10 @@ const char *swt_getTestingLibraryVersion(void) {
#warning SWT_TESTING_LIBRARY_VERSION not defined and VERSION.txt not found: testing library version is unavailable
return nullptr;
#endif
#else
#warning SWT_TESTING_LIBRARY_VERSION not defined and could not read from VERSION.txt at compile time: testing library version is unavailable
return nullptr;
#endif
}

void swt_getTestingLibraryCommit(const char *_Nullable *_Nonnull outHash, bool *outModified) {
Expand Down
5 changes: 5 additions & 0 deletions cmake/modules/shared/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
add_compile_definitions("SWT_NO_DYNAMIC_LINKING")
add_compile_definitions("SWT_NO_PIPES")
endif()

# Avoid using C23's #embed when building with CMake as OpenBSD and Amazon Linux
# 2 are both using older clang versions that don't support it.
file(STRINGS "../VERSION.txt" SWT_TESTING_LIBRARY_VERSION LIMIT_COUNT 1)
add_compile_definitions("$<$<COMPILE_LANGUAGE:CXX>:SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">")
Loading