mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Concurrency][Linux] Fix WASI build.
This doesn't actually add proper WASI support - it just fixes the build so that we're no worse off than we were. rdar://141348916
This commit is contained in:
@@ -93,9 +93,12 @@ set(SWIFT_RUNTIME_CONCURRENCY_C_SOURCES
|
||||
linker-support/magic-symbols-for-install-name.c
|
||||
)
|
||||
|
||||
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES
|
||||
DispatchGlobalExecutor.cpp
|
||||
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES)
|
||||
if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
|
||||
set(SWIFT_RUNTIME_CONCURRENCY_EXECUTOR_SOURCES
|
||||
DispatchGlobalExecutor.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(LLVM_OPTIONAL_SOURCES
|
||||
CooperativeGlobalExecutor.cpp
|
||||
@@ -168,9 +171,11 @@ set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES
|
||||
TaskSleepDuration.swift
|
||||
DispatchExecutor.swift
|
||||
CFExecutor.swift
|
||||
DummyExecutor.swift
|
||||
PlatformExecutorDarwin.swift
|
||||
PlatformExecutorLinux.swift
|
||||
PlatformExecutorWindows.swift
|
||||
PlatformExecutorWASI.swift
|
||||
)
|
||||
|
||||
set(SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_SWIFT_SOURCES
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if !$Embedded
|
||||
#if !$Embedded && !os(WASI)
|
||||
|
||||
import Swift
|
||||
|
||||
@@ -200,4 +200,4 @@ extension DispatchGlobalTaskExecutor: DispatchExecutorProtocol {
|
||||
extension DispatchMainExecutor: DispatchExecutorProtocol {
|
||||
}
|
||||
|
||||
#endif // !$Embedded
|
||||
#endif // !$Embedded && !os(WASI)
|
||||
|
||||
51
stdlib/public/Concurrency/DummyExecutor.swift
Normal file
51
stdlib/public/Concurrency/DummyExecutor.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2020 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Swift
|
||||
|
||||
// .. Main Executor ............................................................
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public class DummyMainExecutor: MainExecutor, @unchecked Sendable {
|
||||
public init() {}
|
||||
|
||||
public func run() throws {
|
||||
fatalError("There is no executor implementation active")
|
||||
}
|
||||
|
||||
public func stop() {
|
||||
fatalError("There is no executor implementation active")
|
||||
}
|
||||
|
||||
public func enqueue(_ job: consuming ExecutorJob) {
|
||||
fatalError("There is no executor implementation active")
|
||||
}
|
||||
|
||||
public var isMainExecutor: Bool { true }
|
||||
|
||||
public func checkIsolated() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// .. Task Executor ............................................................
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public class DummyTaskExecutor: TaskExecutor, @unchecked Sendable {
|
||||
public init() {}
|
||||
|
||||
public func enqueue(_ job: consuming ExecutorJob) {
|
||||
fatalError("There is no executor implementation active")
|
||||
}
|
||||
|
||||
public var isMainExecutor: Bool { false }
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if !SWIFT_CONCURRENCY_EMBEDDED
|
||||
#if SWIFT_CONCURRENCY_USES_DISPATCH
|
||||
#include <dispatch/dispatch.h>
|
||||
#endif
|
||||
|
||||
@@ -119,38 +119,7 @@ void *swift_job_getExecutorPrivateData(Job *job) {
|
||||
return &job->SchedulerPrivate[0];
|
||||
}
|
||||
|
||||
#if !SWIFT_CONCURRENCY_EMBEDDED
|
||||
extern "C" SWIFT_CC(swift)
|
||||
void *swift_createDispatchEventC(void (*handler)(void *), void *context) {
|
||||
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_OR,
|
||||
0, 0,
|
||||
dispatch_get_main_queue());
|
||||
dispatch_source_set_event_handler_f(source, handler);
|
||||
dispatch_activate(source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
extern "C" SWIFT_CC(swift)
|
||||
void swift_destroyDispatchEventC(void *event) {
|
||||
dispatch_source_t source = (dispatch_source_t)event;
|
||||
|
||||
dispatch_source_cancel(source);
|
||||
dispatch_release(source);
|
||||
}
|
||||
|
||||
extern "C" SWIFT_CC(swift)
|
||||
void *swift_getDispatchEventContext(void *event) {
|
||||
return dispatch_get_context((dispatch_source_t)event);
|
||||
}
|
||||
|
||||
extern "C" SWIFT_CC(swift)
|
||||
void swift_signalDispatchEvent(void *event) {
|
||||
dispatch_source_t source = (dispatch_source_t)event;
|
||||
|
||||
dispatch_source_merge_data(source, 1);
|
||||
}
|
||||
|
||||
#if SWIFT_CONCURRENCY_USES_DISPATCH
|
||||
extern "C" SWIFT_CC(swift) __attribute__((noreturn))
|
||||
void swift_dispatchMain() {
|
||||
dispatch_main();
|
||||
@@ -160,7 +129,6 @@ extern "C" SWIFT_CC(swift)
|
||||
void swift_dispatchAssertMainQueue() {
|
||||
dispatch_assert_queue(dispatch_get_main_queue());
|
||||
}
|
||||
|
||||
#endif // !SWIFT_CONCURRENCY_EMBEDDED
|
||||
#endif // SWIFT_CONCURRENCY_ENABLE_DISPATCH
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@@ -112,49 +112,3 @@ internal func _dispatchEnqueueWithDeadline(_ global: CBool,
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_silgen_name("swift_dispatchAssertMainQueue")
|
||||
internal func _dispatchAssertMainQueue()
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_silgen_name("swift_createDispatchEventC")
|
||||
internal func _createDispatchEventC(
|
||||
handler: @convention(c) @escaping (UnsafeMutableRawPointer) -> (),
|
||||
context: UnsafeMutableRawPointer
|
||||
) -> OpaquePointer
|
||||
|
||||
fileprivate class DispatchEventHandlerBox {
|
||||
var handler: @Sendable () -> ()
|
||||
init(handler: @escaping @Sendable () -> ()) {
|
||||
self.handler = handler
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
internal func _createDispatchEvent(handler: @escaping @Sendable () -> ()) -> OpaquePointer {
|
||||
let boxed = DispatchEventHandlerBox(handler: handler)
|
||||
let opaqueHandlerBox = unsafe Unmanaged.passRetained(boxed).toOpaque()
|
||||
return unsafe _createDispatchEventC(
|
||||
handler: { context in
|
||||
let unmanaged = unsafe Unmanaged<DispatchEventHandlerBox>.fromOpaque(context)
|
||||
unsafe unmanaged.takeUnretainedValue().handler()
|
||||
},
|
||||
context: opaqueHandlerBox
|
||||
)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_silgen_name("swift_destroyDispatchEventC")
|
||||
internal func _destroyDispatchEventC(_ event: OpaquePointer)
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_silgen_name("swift_getDispatchEventContext")
|
||||
internal func _getDispatchEventContext(_ event: OpaquePointer) -> UnsafeMutableRawPointer
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
internal func _destroyDispatchEvent(_ event: OpaquePointer) {
|
||||
let context = unsafe _getDispatchEventContext(event)
|
||||
unsafe Unmanaged<DispatchEventHandlerBox>.fromOpaque(context).release()
|
||||
unsafe _destroyDispatchEventC(event)
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_silgen_name("swift_signalDispatchEvent")
|
||||
internal func _signalDispatchEvent(_ event: OpaquePointer)
|
||||
|
||||
25
stdlib/public/Concurrency/PlatformExecutorWASI.swift
Normal file
25
stdlib/public/Concurrency/PlatformExecutorWASI.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2020 - 2025 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if os(WASI)
|
||||
|
||||
import Swift
|
||||
|
||||
// The default executors for now are Dispatch-based
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public struct PlatformExecutorFactory: ExecutorFactory {
|
||||
public static let mainExecutor: any MainExecutor = DummyMainExecutor()
|
||||
public static let defaultExecutor: any TaskExecutor
|
||||
= DummyTaskExecutor()
|
||||
}
|
||||
|
||||
#endif // os(WASI)
|
||||
Reference in New Issue
Block a user