Skip to content

Commit aad617e

Browse files
authored
Merge pull request #27 from jamf/ml_swift6_updates
Swift 6 updates
2 parents 9044073 + 668f2ed commit aad617e

14 files changed

+76
-61
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ All notable changes to this project will be documented in this file.
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10+
## [3.0.4] - 2024-07-01
11+
12+
### Changed
13+
- Swift 6 compatibility updates.
14+
1015
## 3.0.3 - 2024-04-15
1116

1217
### Changed

Package.swift

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ let package = Package(
5454
.target(name: "Subprocess")
5555
]
5656
)
57-
]
57+
],
58+
swiftLanguageVersions: [.v5, .version("6")]
5859
)
5960

6061
for target in package.targets {
@@ -65,60 +66,24 @@ for target in package.targets {
6566
// as upcoming features will result in a compiler error. Currently in the
6667
// latest 5.10 compiler this doesn't happen, the compiler ignores it.
6768
//
68-
// If the situation does change and enabling default language features
69-
// does result in an error in future versions we attempt to guard against
70-
// this by using the hasFeature(x) compiler directive to see if we have a
71-
// feature already, or if we can enable it. It's safe to enable features
72-
// that don't exist in older compiler versions as the compiler will ignore
73-
// features it doesn't have implemented.
74-
75-
// swift 6
76-
#if !hasFeature(ConciseMagicFile)
77-
swiftSettings.append(.enableUpcomingFeature("ConciseMagicFile"))
78-
#endif
79-
80-
#if !hasFeature(ForwardTrailingClosures)
81-
swiftSettings.append(.enableUpcomingFeature("ForwardTrailingClosures"))
82-
#endif
83-
84-
#if !hasFeature(StrictConcurrency)
85-
swiftSettings.append(.enableUpcomingFeature("StrictConcurrency"))
86-
// StrictConcurrency is under experimental features in Swift <=5.10 contrary to some posts and documentation
87-
swiftSettings.append(.enableExperimentalFeature("StrictConcurrency"))
88-
#endif
89-
90-
#if !hasFeature(BareSlashRegexLiterals)
91-
swiftSettings.append(.enableUpcomingFeature("BareSlashRegexLiterals"))
92-
#endif
93-
94-
#if !hasFeature(ImplicitOpenExistentials)
95-
swiftSettings.append(.enableUpcomingFeature("ImplicitOpenExistentials"))
96-
#endif
97-
98-
#if !hasFeature(ImportObjcForwardDeclarations)
99-
swiftSettings.append(.enableUpcomingFeature("ImportObjcForwardDeclarations"))
100-
#endif
101-
102-
#if !hasFeature(DisableOutwardActorInference)
103-
swiftSettings.append(.enableUpcomingFeature("DisableOutwardActorInference"))
104-
#endif
105-
106-
#if !hasFeature(InternalImportsByDefault)
107-
swiftSettings.append(.enableUpcomingFeature("InternalImportsByDefault"))
108-
#endif
109-
110-
#if !hasFeature(IsolatedDefaultValues)
111-
swiftSettings.append(.enableUpcomingFeature("IsolatedDefaultValues"))
112-
#endif
113-
114-
#if !hasFeature(GlobalConcurrency)
115-
swiftSettings.append(.enableUpcomingFeature("GlobalConcurrency"))
116-
#endif
69+
// The Swift 6 compiler on the other hand does emit errors when features
70+
// are enabled. Unfortunately it appears that the preprocessor
71+
// !hasFeature(xxx) cannot be used to test for this situation nor does
72+
// #if swift(<6) guard against this. There must be some sort of magic
73+
// used that is special for compiling the Package.swift manifest.
74+
// Instead a versioned Package.swift can be used (e.g. [email protected])
75+
// and the implemented now default features can be removed in Package.swift.
76+
//
77+
// Or you can just delete the Swift 6 features that are enabled instead of
78+
// creating another manifest file and test to see if building under Swift 5
79+
// still works (it should almost always work).
80+
//
81+
// It's still safe to enable features that don't exist in older compiler
82+
// versions as the compiler will ignore features it doesn't have implemented.
11783

11884
// swift 7
119-
#if !hasFeature(ExistentialAny)
12085
swiftSettings.append(.enableUpcomingFeature("ExistentialAny"))
121-
#endif
86+
swiftSettings.append(.enableUpcomingFeature("InternalImportsByDefault"))
12287

12388
target.swiftSettings = swiftSettings
12489
}

Sources/Subprocess/AsyncSequence+Additions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
extension AsyncSequence {
3135
/// Returns a sequence of all the elements.

Sources/Subprocess/AsyncStream+Yield.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
extension AsyncStream.Continuation where Element == UInt8 {
3135
/// Resume the task awaiting the next iteration point by having it return

Sources/Subprocess/Input.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
// SOFTWARE.
2626
//
27+
28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2731
import Foundation
32+
#endif
2833

2934
/// Interface representing input to the process
3035
public struct Input {

Sources/Subprocess/Pipe+AsyncBytes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
// `FileHandle.AsyncBytes` has a bug that can block reading of stdout when also reading stderr.
3135
// We can avoid this problem if we create independent handlers.

Sources/Subprocess/Shell.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
/// Class used for synchronous process execution
3135
@available(*, deprecated, message: "Use Swift Concurrency methods instead which are part of the Subprocess class")

Sources/Subprocess/Subprocess.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
public import Combine
31+
#else
2832
import Foundation
2933
import Combine
34+
#endif
3035

3136
/// Class used for asynchronous process execution
3237
public class Subprocess: @unchecked Sendable {

Sources/Subprocess/SubprocessDependencyBuilder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
/// Protocol call used for dependency injection
3135
public protocol SubprocessDependencyFactory {

Sources/SubprocessMocks/MockOutput.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
32+
#endif
2933

3034
/// A way to supply data to mock methods
3135
public protocol MockOutput: Sendable {

Sources/SubprocessMocks/MockProcess.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
29-
#if !COCOA_PODS
30-
import Subprocess
3132
#endif
33+
import Subprocess
3234

3335
/// Interface used for mocking a process
3436
public struct MockProcess: Sendable {
@@ -66,7 +68,7 @@ public struct MockProcess: Sendable {
6668
}
6769

6870
/// Subclass of `Process` used for mocking
69-
open class MockProcessReference: Process {
71+
open class MockProcessReference: Process, @unchecked Sendable {
7072
/// Context information and values used for overriden properties
7173
public struct Context {
7274

Sources/SubprocessMocks/MockShell.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
public import Subprocess
31+
#else
2832
import Foundation
29-
#if !COCOA_PODS
3033
import Subprocess
3134
#endif
3235

Sources/SubprocessMocks/MockSubprocess.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
public import Combine
31+
public import Subprocess
32+
#else
2833
import Foundation
2934
import Combine
30-
#if !COCOA_PODS
3135
import Subprocess
3236
#endif
3337

Sources/SubprocessMocks/MockSubprocessDependencyBuilder.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
// SOFTWARE.
2626
//
2727

28+
#if swift(>=6.0)
29+
public import Foundation
30+
#else
2831
import Foundation
29-
#if !COCOA_PODS
30-
import Subprocess
3132
#endif
33+
import Subprocess
3234

3335
/// Error representing a failed call to Subprocess.expect or Shell.expect
3436
public struct ExpectationError: Error {
@@ -66,11 +68,11 @@ public extension SubprocessMockObject {
6668
static func reset() { MockSubprocessDependencyBuilder.shared.reset() }
6769
}
6870

69-
public class MockFileHandle: FileHandle {
71+
public class MockFileHandle: FileHandle, @unchecked Sendable {
7072
public var url: URL?
7173
}
7274

73-
public final class MockPipe: Pipe {
75+
public final class MockPipe: Pipe, @unchecked Sendable {
7476
private static let queue = DispatchQueue(label: "\(MockPipe.self)")
7577
private var _data: Data?
7678
public var data: Data? {

0 commit comments

Comments
 (0)