Skip to content

Commit d454771

Browse files
[CMAKE] Fix layering issue between Concurrency and Darwin overlay (swiftlang#82973)
Concurrency from the Core project is importing the Darwin platform overlay, which in turn depends on SwiftCore from the Core project, breaking the project layering. Concurrency only needs the Clang module, but Swift does not have a mechanism to only import a clang module. For now import the functionality needed from Darwin by importing and wrapping the associated functions from `<dlfcn.h>` within `CFExecutor.cpp` Also remove Darwin import from `AsyncStreamBuffer.swift` because it is not used
1 parent 49febcd commit d454771

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ add_library(swift_Concurrency
9999
"${CMAKE_CURRENT_BINARY_DIR}/TaskGroup+addTask.swift"
100100
"${CMAKE_CURRENT_BINARY_DIR}/Task+immediate.swift")
101101

102+
if(APPLE)
103+
target_sources(swift_Concurrency PRIVATE
104+
CFExecutor.swift
105+
CFExecutor.cpp)
106+
endif()
107+
102108
include(${SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR}.cmake)
103109
target_compile_definitions(swift_Concurrency PRIVATE
104110
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===--- CFExecutor.cpp ----------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
#include "swift/Runtime/Concurrency.h"
13+
#include <dlfcn.h>
14+
15+
using namespace swift;
16+
17+
SWIFT_CC(swift)
18+
extern "C" void * _swift_concurrency_dlopen_noload(const char * __path) {
19+
return dlopen( __path, RTLD_NOLOAD);
20+
}
21+
22+
SWIFT_CC(swift)
23+
extern "C" void * _swift_concurrency_dlsym(void * __handle, const char * __symbol) {
24+
return dlsym(__handle, __symbol);
25+
}

stdlib/public/Concurrency/CFExecutor.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414

1515
import Swift
1616

17-
internal import Darwin
17+
@_silgen_name("_swift_concurrency_dlopen_noload")
18+
private func dlopen_noload(_ path: UnsafePointer<CChar>?) -> OpaquePointer?
19+
20+
@_silgen_name("_swift_concurrency_dlsym")
21+
private func dlsym(_ handle: OpaquePointer?, _ symbol: UnsafePointer<CChar>?) -> OpaquePointer?
1822

1923
// .. Dynamic binding ..........................................................
2024

2125
enum CoreFoundation {
2226
static let path =
2327
"/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
2428

25-
static let handle = unsafe dlopen(path, RTLD_NOLOAD)
29+
static let handle = unsafe dlopen_noload(path)
2630

2731
static var isPresent: Bool { return unsafe handle != nil }
2832

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
184184
CFExecutor.swift
185185
ExecutorImpl.swift
186186
)
187+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
188+
list(APPEND SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES CFExecutor.cpp)
189+
endif()
187190
elseif("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "singlethreaded")
188191
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES
189192
ExecutorImpl.swift
@@ -200,6 +203,7 @@ set(LLVM_OPTIONAL_SOURCES
200203
DispatchGlobalExecutor.cpp
201204
CooperativeGlobalExecutor.cpp
202205
DispatchGlobalExecutor.cpp
206+
CFExecutor.cpp
203207
)
204208

205209
set(SWIFT_CONCURRENCY_DEPENDENCIES)

0 commit comments

Comments
 (0)