From 126cbefe9a174fd7fdc048a1803885a5ce5b8dd4 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Tue, 1 Jul 2025 19:06:01 -0700 Subject: [PATCH] FreeBSD: Gate GNU-only API (#1183) The FreeBSD builds are currently using the GlibC modulemap to import the C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in build failures. The use of this API was introduced in https://github.com/swiftlang/swift-testing/pull/1147 (cherry picked from commit 79c22ad7b9c372499c305ca0f8fef78af2a907c5) - **Explanation**: The FreeBSD builds are currently using the GlibC modulemap to import the C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in build failures. - **Scope**: Build failure on platforms using Glibc modulemap that don't have GNU extensions. (FreeBSD, OpenBSD) - **Issues**: https://github.com/swiftlang/swift-testing/issues/1193 - **Original PRs**: https://github.com/swiftlang/swift-testing/pull/1183 - **Risk**: Low risk. Removes use of unavailable API. - **Testing**: Built swift-testing on FreeBSD and Linux. - **Reviewers**: @grynspan @3405691582 Fixes: #1193 --- Sources/Testing/ExitTests/SpawnProcess.swift | 2 +- Sources/Testing/Support/Versions.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Testing/ExitTests/SpawnProcess.swift b/Sources/Testing/ExitTests/SpawnProcess.swift index 66143a7e0..fe51a7086 100644 --- a/Sources/Testing/ExitTests/SpawnProcess.swift +++ b/Sources/Testing/ExitTests/SpawnProcess.swift @@ -137,7 +137,7 @@ func spawnExecutable( // standardized in POSIX.1-2024 (see https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_adddup2.html // and https://www.austingroupbugs.net/view.php?id=411). _ = posix_spawn_file_actions_adddup2(fileActions, fd, fd) -#if canImport(Glibc) +#if canImport(Glibc) && !os(FreeBSD) && !os(OpenBSD) if _slowPath(glibcVersion.major < 2 || (glibcVersion.major == 2 && glibcVersion.minor < 29)) { // This system is using an older version of glibc that does not // implement FD_CLOEXEC clearing in posix_spawn_file_actions_adddup2(), diff --git a/Sources/Testing/Support/Versions.swift b/Sources/Testing/Support/Versions.swift index 1229e80b0..7f190ebb2 100644 --- a/Sources/Testing/Support/Versions.swift +++ b/Sources/Testing/Support/Versions.swift @@ -153,7 +153,7 @@ let swiftStandardLibraryVersion: String = { return "unknown" }() -#if canImport(Glibc) +#if canImport(Glibc) && !os(FreeBSD) && !os(OpenBSD) /// The (runtime, not compile-time) version of glibc in use on this system. /// /// This value is not part of the public interface of the testing library.