Skip to content

Commit 808f059

Browse files
committed
Fix build on macOS 13
1 parent a98ec30 commit 808f059

17 files changed

+75
-65
lines changed

Sources/Subprocess/API.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif

Sources/Subprocess/AsyncBufferSequence.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif
1717

1818
#if SubprocessSpan
1919
@available(SubprocessSpan, *)
2020
#endif
21-
internal struct AsyncBufferSequence: AsyncSequence, Sendable {
22-
internal typealias Failure = any Swift.Error
23-
24-
internal typealias Element = SequenceOutput.Buffer
21+
public struct AsyncBufferSequence: AsyncSequence, Sendable {
22+
public typealias Failure = any Swift.Error
23+
public typealias Element = SequenceOutput.Buffer
2524

2625
@_nonSendable
27-
internal struct Iterator: AsyncIteratorProtocol {
28-
internal typealias Element = SequenceOutput.Buffer
26+
public struct Iterator: AsyncIteratorProtocol {
27+
public typealias Element = SequenceOutput.Buffer
2928

3029
private let fileDescriptor: TrackedFileDescriptor
3130
private var buffer: [UInt8]
@@ -39,7 +38,7 @@ internal struct AsyncBufferSequence: AsyncSequence, Sendable {
3938
self.finished = false
4039
}
4140

42-
internal mutating func next() async throws -> SequenceOutput.Buffer? {
41+
public mutating func next() async throws -> SequenceOutput.Buffer? {
4342
let data = try await self.fileDescriptor.wrapped.readChunk(
4443
upToLength: readBufferSize
4544
)
@@ -58,7 +57,7 @@ internal struct AsyncBufferSequence: AsyncSequence, Sendable {
5857
self.fileDescriptor = fileDescriptor
5958
}
6059

61-
internal func makeAsyncIterator() -> Iterator {
60+
public func makeAsyncIterator() -> Iterator {
6261
return Iterator(fileDescriptor: self.fileDescriptor)
6362
}
6463
}

Sources/Subprocess/Atomic.swift

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,41 @@ import WinSDK
3030

3131
#endif // canImport(Synchronization)
3232

33-
internal protocol AtomicBoxProtocol: ~Copyable, Sendable {
34-
borrowing func bitwiseXor(
35-
_ operand: OutputConsumptionState
36-
) -> OutputConsumptionState
37-
38-
init(_ initialValue: OutputConsumptionState)
39-
}
33+
internal struct AtomicBox: Sendable, ~Copyable {
34+
internal typealias BitwiseXorFunc = (OutputConsumptionState) -> OutputConsumptionState
4035

41-
internal struct AtomicBox<Wrapped: AtomicBoxProtocol & ~Copyable>: ~Copyable, Sendable {
36+
private let storage: @Sendable () -> BitwiseXorFunc
4237

43-
private let storage: Wrapped
44-
45-
internal init(_ storage: consuming Wrapped) {
46-
self.storage = storage
38+
internal init() {
39+
#if canImport(Synchronization)
40+
guard #available(macOS 15, *) else {
41+
fatalError("Unexpected configuration")
42+
}
43+
let box = Atomic(UInt8(0))
44+
self.storage = {
45+
return { input in
46+
return box._bitwiseXor(input)
47+
}
48+
}
49+
#else
50+
let state = LockedState(OutputConsumptionState(rawValue: 0))
51+
self.storage = {
52+
return state._bitwiseXor
53+
}
54+
#endif
4755
}
4856

49-
borrowing internal func bitwiseXor(
57+
internal func bitwiseXor(
5058
_ operand: OutputConsumptionState
5159
) -> OutputConsumptionState {
52-
return self.storage.bitwiseXor(operand)
60+
return self.storage()(operand)
5361
}
5462
}
5563

5664
#if canImport(Synchronization)
5765
@available(macOS 15, *)
58-
extension Atomic: AtomicBoxProtocol where Value == UInt8 {
59-
borrowing func bitwiseXor(
66+
extension Atomic where Value == UInt8 {
67+
borrowing func _bitwiseXor(
6068
_ operand: OutputConsumptionState
6169
) -> OutputConsumptionState {
6270
let newState = self.bitwiseXor(
@@ -72,12 +80,12 @@ extension Atomic: AtomicBoxProtocol where Value == UInt8 {
7280
}
7381
#else
7482
// Fallback to LockedState if `Synchronization` is not available
75-
extension LockedState: AtomicBoxProtocol where State == OutputConsumptionState {
83+
extension LockedState where State == OutputConsumptionState {
7684
init(_ initialValue: OutputConsumptionState) {
7785
self.init(initialState: initialValue)
7886
}
7987

80-
func bitwiseXor(
88+
func _bitwiseXor(
8189
_ operand: OutputConsumptionState
8290
) -> OutputConsumptionState {
8391
return self.withLock { state in

Sources/Subprocess/Configuration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif

Sources/Subprocess/Execution.swift

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif
@@ -27,10 +27,6 @@ import Musl
2727
import WinSDK
2828
#endif
2929

30-
#if canImport(Synchronization)
31-
import Synchronization
32-
#endif
33-
3430
/// An object that repersents a subprocess that has been
3531
/// executed. You can use this object to send signals to the
3632
/// child process as well as stream its output and error.
@@ -48,11 +44,8 @@ public final class Execution<
4844
internal let error: Error
4945
internal let outputPipe: CreatedPipe
5046
internal let errorPipe: CreatedPipe
51-
#if canImport(Synchronization)
52-
internal let outputConsumptionState: AtomicBox<Atomic<OutputConsumptionState.RawValue>>
53-
#else
54-
internal let outputConsumptionState: AtomicBox<LockedState<OutputConsumptionState>>
55-
#endif
47+
internal let outputConsumptionState: AtomicBox
48+
5649
#if os(Windows)
5750
internal let consoleBehavior: PlatformOptions.ConsoleBehavior
5851

@@ -69,11 +62,7 @@ public final class Execution<
6962
self.error = error
7063
self.outputPipe = outputPipe
7164
self.errorPipe = errorPipe
72-
#if canImport(Synchronization)
73-
self.outputConsumptionState = AtomicBox(Atomic(0))
74-
#else
75-
self.outputConsumptionState = AtomicBox(LockedState(OutputConsumptionState(rawValue: 0)))
76-
#endif
65+
self.outputConsumptionState = AtomicBox()
7766
self.consoleBehavior = consoleBehavior
7867
}
7968
#else
@@ -89,11 +78,7 @@ public final class Execution<
8978
self.error = error
9079
self.outputPipe = outputPipe
9180
self.errorPipe = errorPipe
92-
#if canImport(Synchronization)
93-
self.outputConsumptionState = AtomicBox(Atomic(0))
94-
#else
95-
self.outputConsumptionState = AtomicBox(LockedState(OutputConsumptionState(rawValue: 0)))
96-
#endif
81+
self.outputConsumptionState = AtomicBox()
9782
}
9883
#endif // os(Windows)
9984
}
@@ -107,9 +92,9 @@ extension Execution where Output == SequenceOutput {
10792
/// Accessing this property will **fatalError** if this property was
10893
/// accessed multiple times. Subprocess communicates with parent process
10994
/// via pipe under the hood and each pipe can only be consumed once.
110-
public var standardOutput: some AsyncSequence<SequenceOutput.Buffer, any Swift.Error> {
95+
public var standardOutput: AsyncBufferSequence {
11196
let consumptionState = self.outputConsumptionState.bitwiseXor(
112-
OutputConsumptionState.standardOutputConsumed,
97+
OutputConsumptionState.standardOutputConsumed
11398
)
11499

115100
guard consumptionState.contains(.standardOutputConsumed),
@@ -130,9 +115,9 @@ extension Execution where Error == SequenceOutput {
130115
/// Accessing this property will **fatalError** if this property was
131116
/// accessed multiple times. Subprocess communicates with parent process
132117
/// via pipe under the hood and each pipe can only be consumed once.
133-
public var standardError: some AsyncSequence<SequenceOutput.Buffer, any Swift.Error> {
118+
public var standardError: AsyncBufferSequence {
134119
let consumptionState = self.outputConsumptionState.bitwiseXor(
135-
OutputConsumptionState.standardOutputConsumed,
120+
OutputConsumptionState.standardOutputConsumed
136121
)
137122

138123
guard consumptionState.contains(.standardErrorConsumed),

Sources/Subprocess/IO/Input.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif

Sources/Subprocess/IO/Output.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#if canImport(System)
13-
import System
13+
@preconcurrency import System
1414
#else
1515
@preconcurrency import SystemPackage
1616
#endif

Sources/Subprocess/Platforms/Subprocess+Darwin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import Darwin
1515
internal import Dispatch
1616
#if canImport(System)
17-
import System
17+
@preconcurrency import System
1818
#else
1919
@preconcurrency import SystemPackage
2020
#endif

Sources/Subprocess/Platforms/Subprocess+Linux.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#if canImport(Glibc) || canImport(Bionic) || canImport(Musl)
1313

1414
#if canImport(System)
15-
import System
15+
@preconcurrency import System
1616
#else
1717
@preconcurrency import SystemPackage
1818
#endif

Sources/Subprocess/Platforms/Subprocess+Unix.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#if canImport(Darwin) || canImport(Glibc) || canImport(Bionic) || canImport(Musl)
1313

1414
#if canImport(System)
15-
import System
15+
@preconcurrency import System
1616
#else
1717
@preconcurrency import SystemPackage
1818
#endif

0 commit comments

Comments
 (0)