Skip to content

Commit 479750b

Browse files
authored
Add Wasm/Windows support/CI (#1)
* Add Wasm/Windows CI * wip * wip * test * wip
1 parent e8af1c3 commit 479750b

File tree

4 files changed

+214
-175
lines changed

4 files changed

+214
-175
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,60 @@ concurrency:
1515

1616
jobs:
1717
library:
18-
runs-on: macos-13
18+
name: macOS
1919
strategy:
2020
matrix:
2121
xcode: ['14.3.1']
2222
config: ['debug', 'release']
23+
runs-on: macos-13
2324
steps:
2425
- uses: actions/checkout@v3
2526
- name: Select Xcode ${{ matrix.xcode }}
2627
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
2728
- name: Run ${{ matrix.config }} tests
2829
run: CONFIG=${{ matrix.config }} make test
2930

30-
ubuntu-tests:
31+
linux:
32+
name: Linux
3133
strategy:
3234
matrix:
3335
os: [ubuntu-20.04]
3436
config: ['debug', 'release']
35-
3637
runs-on: ${{ matrix.os }}
37-
3838
steps:
3939
- uses: actions/checkout@v3
4040
- name: Build
4141
run: swift build
4242
- name: Run tests
4343
run: swift test -c ${{ matrix.config }}
44+
45+
wasm:
46+
name: Wasm
47+
runs-on: ubuntu-latest
48+
strategy:
49+
matrix:
50+
include:
51+
- { toolchain: wasm-5.7.1-RELEASE }
52+
steps:
53+
- uses: actions/checkout@v3
54+
- run: echo "${{ matrix.toolchain }}" > .swift-version
55+
- uses: swiftwasm/swiftwasm-action@v5.7
56+
with:
57+
shell-action: carton test --environment node
58+
59+
windows:
60+
name: Windows
61+
strategy:
62+
matrix:
63+
os: [windows-latest]
64+
config: ['debug', 'release']
65+
runs-on: ${{ matrix.os }}
66+
steps:
67+
- uses: compnerd/gha-setup-swift@main
68+
with:
69+
branch: swift-5.8-release
70+
tag: 5.8-RELEASE
71+
72+
- uses: actions/checkout@v3
73+
- name: Run tests
74+
run: swift build -c ${{ matrix.config }}

Package.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ let package = Package(
1616
targets: ["ConcurrencyExtras"]
1717
)
1818
],
19-
dependencies: [
20-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
21-
],
2219
targets: [
2320
.target(
2421
name: "ConcurrencyExtras"
@@ -32,6 +29,13 @@ let package = Package(
3229
]
3330
)
3431

32+
#if !os(Windows)
33+
// Add the documentation compiler plugin if possible
34+
package.dependencies.append(
35+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
36+
)
37+
#endif
38+
3539
//for target in package.targets {
3640
// target.swiftSettings = target.swiftSettings ?? []
3741
// target.swiftSettings?.append(
Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,78 @@
1-
import Foundation
1+
#if !os(WASI) && !os(Windows)
2+
import Foundation
23

3-
/// Perform an operation on the main serial executor.
4-
///
5-
/// Some asynchronous code is [notoriously
6-
/// difficult](https://forums.swift.org/t/reliably-testing-code-that-adopts-swift-concurrency/57304)
7-
/// to test in Swift due to how suspension points are processed by the runtime. This function runs
8-
/// all tasks spawned in the given operation serially and deterministically. It makes asynchronous
9-
/// tests faster and less flakey.
10-
///
11-
/// ```swift
12-
/// await withMainSerialExecutor {
13-
/// // Everything performed in this scope is performed serially...
14-
/// }
15-
/// ```
16-
///
17-
/// - Parameter operation: An operation to be performed on the main serial executor.
18-
@MainActor
19-
public func withMainSerialExecutor(
20-
@_implicitSelfCapture operation: @MainActor @Sendable () async throws -> Void
21-
) async rethrows {
22-
let didUseMainSerialExecutor = uncheckedUseMainSerialExecutor
23-
defer { uncheckedUseMainSerialExecutor = didUseMainSerialExecutor }
24-
uncheckedUseMainSerialExecutor = true
25-
try await operation()
26-
}
4+
/// Perform an operation on the main serial executor.
5+
///
6+
/// Some asynchronous code is [notoriously
7+
/// difficult](https://forums.swift.org/t/reliably-testing-code-that-adopts-swift-concurrency/57304)
8+
/// to test in Swift due to how suspension points are processed by the runtime. This function runs
9+
/// all tasks spawned in the given operation serially and deterministically. It makes asynchronous
10+
/// tests faster and less flakey.
11+
///
12+
/// ```swift
13+
/// await withMainSerialExecutor {
14+
/// // Everything performed in this scope is performed serially...
15+
/// }
16+
/// ```
17+
///
18+
/// - Parameter operation: An operation to be performed on the main serial executor.
19+
@MainActor
20+
public func withMainSerialExecutor(
21+
@_implicitSelfCapture operation: @MainActor @Sendable () async throws -> Void
22+
) async rethrows {
23+
let didUseMainSerialExecutor = uncheckedUseMainSerialExecutor
24+
defer { uncheckedUseMainSerialExecutor = didUseMainSerialExecutor }
25+
uncheckedUseMainSerialExecutor = true
26+
try await operation()
27+
}
2728

28-
/// Perform an operation on the main serial executor.
29-
///
30-
/// A synchronous version of ``withMainSerialExecutor(operation:)-79jpc`` that can be used in
31-
/// `XCTestCase.invokeTest` to ensure all async tests are performed serially:
32-
///
33-
/// ```swift
34-
/// class BaseTestCase: XCTestCase {
35-
/// override func invokeTest() {
36-
/// withMainSerialExecutor {
37-
/// super.invokeTest()
38-
/// }
39-
/// }
40-
/// }
41-
/// ```
42-
///
43-
/// - Parameter operation: An operation to be performed on the main serial executor.
44-
public func withMainSerialExecutor(
45-
@_implicitSelfCapture operation: () throws -> Void
46-
) rethrows {
47-
let didUseMainSerialExecutor = uncheckedUseMainSerialExecutor
48-
defer { uncheckedUseMainSerialExecutor = didUseMainSerialExecutor }
49-
uncheckedUseMainSerialExecutor = true
50-
try operation()
51-
}
29+
/// Perform an operation on the main serial executor.
30+
///
31+
/// A synchronous version of ``withMainSerialExecutor(operation:)-79jpc`` that can be used in
32+
/// `XCTestCase.invokeTest` to ensure all async tests are performed serially:
33+
///
34+
/// ```swift
35+
/// class BaseTestCase: XCTestCase {
36+
/// override func invokeTest() {
37+
/// withMainSerialExecutor {
38+
/// super.invokeTest()
39+
/// }
40+
/// }
41+
/// }
42+
/// ```
43+
///
44+
/// - Parameter operation: An operation to be performed on the main serial executor.
45+
public func withMainSerialExecutor(
46+
@_implicitSelfCapture operation: () throws -> Void
47+
) rethrows {
48+
let didUseMainSerialExecutor = uncheckedUseMainSerialExecutor
49+
defer { uncheckedUseMainSerialExecutor = didUseMainSerialExecutor }
50+
uncheckedUseMainSerialExecutor = true
51+
try operation()
52+
}
5253

53-
/// Overrides Swift's global executor with the main serial executor in an unchecked fashion.
54-
///
55-
/// > Warning: When set to `true`, all tasks will be enqueued on the main serial executor till set
56-
/// > back to `false`. Consider using ``withMainSerialExecutor(operation:)-79jpc``, instead, which
57-
/// > scopes this work to the duration of a given operation.
58-
public var uncheckedUseMainSerialExecutor: Bool {
59-
get { swift_task_enqueueGlobal_hook != nil }
60-
set {
61-
swift_task_enqueueGlobal_hook =
62-
newValue
63-
? { job, _ in MainActor.shared.enqueue(job) }
64-
: nil
54+
/// Overrides Swift's global executor with the main serial executor in an unchecked fashion.
55+
///
56+
/// > Warning: When set to `true`, all tasks will be enqueued on the main serial executor till set
57+
/// > back to `false`. Consider using ``withMainSerialExecutor(operation:)-79jpc``, instead, which
58+
/// > scopes this work to the duration of a given operation.
59+
public var uncheckedUseMainSerialExecutor: Bool {
60+
get { swift_task_enqueueGlobal_hook != nil }
61+
set {
62+
swift_task_enqueueGlobal_hook =
63+
newValue
64+
? { job, _ in MainActor.shared.enqueue(job) }
65+
: nil
66+
}
6567
}
66-
}
6768

68-
private typealias Original = @convention(thin) (UnownedJob) -> Void
69-
private typealias Hook = @convention(thin) (UnownedJob, Original) -> Void
69+
private typealias Original = @convention(thin) (UnownedJob) -> Void
70+
private typealias Hook = @convention(thin) (UnownedJob, Original) -> Void
7071

71-
private var swift_task_enqueueGlobal_hook: Hook? {
72-
get { _swift_task_enqueueGlobal_hook.pointee }
73-
set { _swift_task_enqueueGlobal_hook.pointee = newValue }
74-
}
75-
private let _swift_task_enqueueGlobal_hook: UnsafeMutablePointer<Hook?> =
76-
dlsym(dlopen(nil, 0), "swift_task_enqueueGlobal_hook").assumingMemoryBound(to: Hook?.self)
72+
private var swift_task_enqueueGlobal_hook: Hook? {
73+
get { _swift_task_enqueueGlobal_hook.pointee }
74+
set { _swift_task_enqueueGlobal_hook.pointee = newValue }
75+
}
76+
private let _swift_task_enqueueGlobal_hook: UnsafeMutablePointer<Hook?> =
77+
dlsym(dlopen(nil, 0), "swift_task_enqueueGlobal_hook").assumingMemoryBound(to: Hook?.self)
78+
#endif

0 commit comments

Comments
 (0)