From 7d212080c39b76327997c9f2031d9534b2ccd41d Mon Sep 17 00:00:00 2001 From: michael-yuji Date: Tue, 17 Jun 2025 14:49:16 -0700 Subject: [PATCH 1/2] [FreeBSD] Enable CFRunLoop support (#5188) * Enable CFRunLoop for FreeBSD * match definition of dispatch_runloop_handle_t in libdispatch --- Sources/CoreFoundation/CFRunLoop.c | 6 ++++-- Sources/Foundation/RunLoop.swift | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/CoreFoundation/CFRunLoop.c b/Sources/CoreFoundation/CFRunLoop.c index 91299fc530..3a6a0aaa73 100644 --- a/Sources/CoreFoundation/CFRunLoop.c +++ b/Sources/CoreFoundation/CFRunLoop.c @@ -72,12 +72,14 @@ extern bool _dispatch_runloop_root_queue_perform_4CF(dispatch_queue_t queue); #if TARGET_OS_MAC typedef mach_port_t dispatch_runloop_handle_t; -#elif defined(__linux__) || defined(__FreeBSD__) +#elif TARGET_OS_LINUX typedef int dispatch_runloop_handle_t; +#elif TARGET_OS_BSD +typedef uint64_t dispatch_runloop_handle_t; #elif TARGET_OS_WIN32 typedef HANDLE dispatch_runloop_handle_t; #else -typedef uint64_t dispatch_runloop_handle_t; +#error "runloop support not implemented on this platform" #endif #if TARGET_OS_MAC diff --git a/Sources/Foundation/RunLoop.swift b/Sources/Foundation/RunLoop.swift index a03dab976d..0a476ea400 100644 --- a/Sources/Foundation/RunLoop.swift +++ b/Sources/Foundation/RunLoop.swift @@ -120,7 +120,7 @@ open class RunLoop: NSObject { // Make sure we honor the override -- var currentCFRunLoop will do so on platforms where overrides are available. // TODO: This has been removed as public API in port to the package, because CoreFoundation cannot be available as both toolchain "CoreFoundation" and package "_CoreFoundation" - #if os(Linux) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(OpenBSD) + #if os(Linux) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(OpenBSD) || os(FreeBSD) internal var currentCFRunLoop: CFRunLoop { getCFRunLoop() } internal func getCFRunLoop() -> CFRunLoop { From 51be7d175dd71d5b630b6a5fcdc9063b15d282f4 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 20 Jun 2025 15:57:46 -0700 Subject: [PATCH 2/2] build: define `CF_WINDOWS_EXECUTABLE_INITIALIZER` (#5224) When building statically, define `CF_WINDOWS_EXECUTABLE_INITIALIZER` to ensure that the runtime constructor is registered and invoked properly. This is required to initialise CoreFoundation and `Foundation.Bundle`. --- Sources/CoreFoundation/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/CoreFoundation/CMakeLists.txt b/Sources/CoreFoundation/CMakeLists.txt index 9afac9e972..bb01502580 100644 --- a/Sources/CoreFoundation/CMakeLists.txt +++ b/Sources/CoreFoundation/CMakeLists.txt @@ -99,7 +99,8 @@ add_library(CoreFoundation STATIC CFWindowsUtilities.c CFXMLPreferencesDomain.c uuid.c) - +target_compile_definitions(CoreFoundation PRIVATE + $<$,$>>:CF_WINDOWS_EXECUTABLE_INITIALIZER>) target_include_directories(CoreFoundation PUBLIC include