From ff1aa40be0364faf703e94b55a39a4fe77b214ff Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 26 Sep 2024 18:04:04 +0900 Subject: [PATCH 1/3] Use `compiler(>=6.1)` to gate for the main branch toolchain We used a hack to distinguish the main branch toolchain and 6.0 branch toolchain, but the main branch has been bumped to 6.1, so we can use `compiler(>=6.1)` to gate for the main branch toolchain. --- Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift | 2 +- Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift | 2 +- Tests/JavaScriptEventLoopTests/WebWorkerTaskExecutorTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift index 871f374e..765746bb 100644 --- a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift @@ -61,7 +61,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { return _shared } - #if compiler(>=6.0) && hasFeature(IsolatedAny2) && _runtime(_multithreaded) + #if compiler(>=6.1) && _runtime(_multithreaded) // In multi-threaded environment, we have an event loop executor per // thread (per Web Worker). A job enqueued in one thread should be // executed in the same thread under this global executor. diff --git a/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift b/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift index 732a2e22..4ccfebe2 100644 --- a/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift +++ b/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift @@ -1,4 +1,4 @@ -#if compiler(>=6.0) && hasFeature(IsolatedAny2) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.0+ +#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.0+ import JavaScriptKit import _CJavaScriptKit diff --git a/Tests/JavaScriptEventLoopTests/WebWorkerTaskExecutorTests.swift b/Tests/JavaScriptEventLoopTests/WebWorkerTaskExecutorTests.swift index 589480cb..a31c783d 100644 --- a/Tests/JavaScriptEventLoopTests/WebWorkerTaskExecutorTests.swift +++ b/Tests/JavaScriptEventLoopTests/WebWorkerTaskExecutorTests.swift @@ -1,4 +1,4 @@ -#if compiler(>=6.0) && hasFeature(IsolatedAny2) && _runtime(_multithreaded) +#if compiler(>=6.1) && _runtime(_multithreaded) import XCTest import JavaScriptKit import _CJavaScriptKit // For swjs_get_worker_thread_id From 69b0f497dfd82585d6e00f49d91554074eb3b7dd Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 26 Sep 2024 18:07:00 +0900 Subject: [PATCH 2/3] Check Xcode 16 compatibility --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index edbc1e7b..bc07e6a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,10 +76,10 @@ jobs: strategy: matrix: include: - - os: macos-13 - xcode: Xcode_14.3 - os: macos-14 xcode: Xcode_15.2 + - os: macos-15 + xcode: Xcode_16 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From ba37ea450d0d3b99d2699b46141485f2b27ced4c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 26 Sep 2024 18:39:48 +0900 Subject: [PATCH 3/3] Gate pthread usage on wasip1-threads --- .../JavaScriptEventLoop/WebWorkerTaskExecutor.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift b/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift index 4ccfebe2..a70312e3 100644 --- a/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift +++ b/Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift @@ -1,4 +1,4 @@ -#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.0+ +#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.1+ import JavaScriptKit import _CJavaScriptKit @@ -274,6 +274,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor { } func start(timeout: Duration, checkInterval: Duration) async throws { + #if canImport(wasi_pthread) class Context: @unchecked Sendable { let executor: WebWorkerTaskExecutor.Executor let worker: Worker @@ -316,6 +317,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor { } while tid == 0 swjs_listen_message_from_worker_thread(tid) } + #else + fatalError("Unsupported platform") + #endif } func terminate() { @@ -420,6 +424,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor { /// /// This function must be called once before using the Web Worker task executor. public static func installGlobalExecutor() { + #if canImport(wasi_pthread) // Ensure this function is called only once. guard _mainThread == nil else { return } @@ -448,6 +453,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor { } } swift_task_enqueueGlobal_hook = unsafeBitCast(swift_task_enqueueGlobal_hook_impl, to: UnsafeMutableRawPointer?.self) + #else + fatalError("Unsupported platform") + #endif } }