diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index 3999710b..1961abc1 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -13,10 +13,8 @@ jobs: fail-fast: false matrix: include: - - os: macos-12 - xcode-version: "14.2" # Swift 5.7.2 - os: macos-13 - xcode-version: "15.1" # Swift 5.9.2 + xcode-version: "15.2" # Swift 5.9.2 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index eb43a1df..aefef7c6 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -13,12 +13,8 @@ jobs: fail-fast: false matrix: include: - - os: macos-12 - xcode-version: "14.2" # Swift 5.7.2 - os: macos-13 - xcode-version: "14.3.1" # Swift 5.8.1 - - os: macos-13 - xcode-version: "15.1" # Swift 5.9.2 + xcode-version: "15.2" # Swift 5.9.2 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/Package.swift b/Package.swift index 02285897..b7343aab 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.7 +// swift-tools-version:5.9 import Foundation import PackageDescription @@ -16,6 +16,7 @@ let supportedPlatforms: [Platform] = [ .android, .windows, .wasi, + .visionOS, ] let cOpenCombineHelpersTarget: Target = .target( diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift deleted file mode 100644 index b7343aab..00000000 --- a/Package@swift-5.9.swift +++ /dev/null @@ -1,147 +0,0 @@ -// swift-tools-version:5.9 - -import Foundation -import PackageDescription - -// This list should be updated whenever SwiftPM adds support for a new platform. -// See: https://bugs.swift.org/browse/SR-13814 -let supportedPlatforms: [Platform] = [ - .macOS, - .macCatalyst, - .iOS, - .watchOS, - .tvOS, - .driverKit, - .linux, - .android, - .windows, - .wasi, - .visionOS, -] - -let cOpenCombineHelpersTarget: Target = .target( - name: "COpenCombineHelpers" -) -let openCombineShimTarget: Target = .target( - name: "OpenCombineShim", - dependencies: [ - "OpenCombine", - .target(name: "OpenCombineDispatch", - condition: .when(platforms: supportedPlatforms.except([.wasi]))), - .target(name: "OpenCombineFoundation", - condition: .when(platforms: supportedPlatforms.except([.wasi]))), - ] -) -let openCombineTarget: Target = .target( - name: "OpenCombine", - dependencies: [ - .target( - name: "COpenCombineHelpers", - condition: .when(platforms: supportedPlatforms.except([.wasi])) - ), - ], - exclude: [ - "Concurrency/Publisher+Concurrency.swift.gyb", - "Publishers/Publishers.Encode.swift.gyb", - "Publishers/Publishers.MapKeyPath.swift.gyb", - "Publishers/Publishers.Catch.swift.gyb", - ] -) -let openCombineFoundationTarget: Target = .target( - name: "OpenCombineFoundation", - dependencies: [ - "OpenCombine", - .target( - name: "COpenCombineHelpers", - condition: .when(platforms: supportedPlatforms.except([.wasi])) - ), - ] -) -let openCombineDispatchTarget: Target = .target( - name: "OpenCombineDispatch", - dependencies: ["OpenCombine"] -) -let openCombineTestsTarget: Target = .testTarget( - name: "OpenCombineTests", - dependencies: [ - "OpenCombine", - .target(name: "OpenCombineDispatch", - condition: .when(platforms: supportedPlatforms.except([.wasi]))), - .target(name: "OpenCombineFoundation", - condition: .when(platforms: supportedPlatforms.except([.wasi]))), - ], - swiftSettings: [ - .unsafeFlags(["-enable-testing"]), - ] -) - -let package = Package( - name: "OpenCombine", - products: [ - .library(name: "OpenCombine", targets: ["OpenCombine"]), - .library(name: "OpenCombineDispatch", targets: ["OpenCombineDispatch"]), - .library(name: "OpenCombineFoundation", targets: ["OpenCombineFoundation"]), - .library(name: "OpenCombineShim", targets: ["OpenCombineShim"]), - ], - targets: [ - cOpenCombineHelpersTarget, - openCombineShimTarget, - openCombineTarget, - openCombineFoundationTarget, - openCombineDispatchTarget, - openCombineTestsTarget, - ], - cxxLanguageStandard: .cxx17 -) - -// MARK: Helpers - -extension [Platform] { - func except(_ exceptions: [Platform]) -> [Platform] { - filter { !exceptions.contains($0) } - } -} - -func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { - guard let value = ProcessInfo.processInfo.environment[key] else { - return defaultValue - } - if value == "1" { - return true - } else if value == "0" { - return false - } else { - return defaultValue - } -} - -let enableLibraryEvolution = envEnable("OPENCOMBINE_LIBRARY_EVOLUTION") -if enableLibraryEvolution { - let libraryEvolutionSetting: SwiftSetting = .unsafeFlags([ - "-Xfrontend", "-enable-library-evolution", - ]) - let targets = [openCombineTarget, openCombineFoundationTarget, openCombineDispatchTarget] - for target in targets { - var settings = target.swiftSettings ?? [] - settings.append(libraryEvolutionSetting) - target.swiftSettings = settings - } -} - -let enableCompatibilityTest = envEnable("OPENCOMBINE_COMPATIBILITY_TEST") -if enableCompatibilityTest { - var settings = openCombineTestsTarget.swiftSettings ?? [] - settings.append(.define("OPENCOMBINE_COMPATIBILITY_TEST")) - openCombineTestsTarget.swiftSettings = settings -} - -let enableOSLockPrivate = envEnable("OPENCOMBINE_OSLOCK_PRIVATE", default: true) -if enableOSLockPrivate { - var cSettings = cOpenCombineHelpersTarget.cSettings ?? [] - cSettings.append(.define("OPENCOMBINE_OSLOCK_PRIVATE")) - cOpenCombineHelpersTarget.cSettings = cSettings - - var cxxSettings = cOpenCombineHelpersTarget.cxxSettings ?? [] - cxxSettings.append(.define("OPENCOMBINE_OSLOCK_PRIVATE")) - cOpenCombineHelpersTarget.cxxSettings = cxxSettings -} diff --git a/Sources/OpenCombine/ObservableObject.swift b/Sources/OpenCombine/ObservableObject.swift index 2317bb87..d1e5d165 100644 --- a/Sources/OpenCombine/ObservableObject.swift +++ b/Sources/OpenCombine/ObservableObject.swift @@ -46,7 +46,6 @@ private protocol _ObservableObjectProperty { var objectWillChange: ObservableObjectPublisher? { get nonmutating set } } -#if swift(>=5.1) extension Published: _ObservableObjectProperty {} extension ObservableObject where ObjectWillChangePublisher == ObservableObjectPublisher { @@ -92,8 +91,6 @@ extension ObservableObject where ObjectWillChangePublisher == ObservableObjectPu } } -#endif - /// A publisher that publishes changes from observable objects. public final class ObservableObjectPublisher: Publisher { diff --git a/Sources/OpenCombine/Published.swift b/Sources/OpenCombine/Published.swift index f1d49278..62e40539 100644 --- a/Sources/OpenCombine/Published.swift +++ b/Sources/OpenCombine/Published.swift @@ -5,8 +5,6 @@ // Created by Евгений Богомолов on 01/09/2019. // -#if swift(>=5.1) - extension Publisher where Failure == Never { /// Republishes elements received from a publisher, by assigning them to a property @@ -79,7 +77,6 @@ extension Publisher where Failure == Never { /// ### See Also /// /// - `Publisher.assign(to:)` -@available(swift, introduced: 5.1) @propertyWrapper public struct Published { @@ -218,9 +215,3 @@ public struct Published { // TODO: Benchmark and explore a possibility to use _modify } } -#else - -@available(swift, introduced: 5.1) -public typealias Published = Never - -#endif // swift(>=5.1) diff --git a/Sources/OpenCombineFoundation/Helpers/Portability.swift b/Sources/OpenCombineFoundation/Helpers/Portability.swift index 3d778f6b..fc8eaca3 100644 --- a/Sources/OpenCombineFoundation/Helpers/Portability.swift +++ b/Sources/OpenCombineFoundation/Helpers/Portability.swift @@ -150,12 +150,7 @@ extension RunLoop.Mode { return CFRunLoopMode(rawValue as CFString) #else return rawValue.withCString { -#if swift(>=5.3) let encoding = CFStringBuiltInEncodings.UTF8.rawValue -#else - let encoding = CFStringEncoding(kCFStringEncodingUTF8) -#endif // swift(>=5.3) - return CFStringCreateWithCString( nil, $0, diff --git a/Tests/OpenCombineTests/Helpers/CommonTests.swift b/Tests/OpenCombineTests/Helpers/CommonTests.swift index d8607acf..5fd8a4a8 100644 --- a/Tests/OpenCombineTests/Helpers/CommonTests.swift +++ b/Tests/OpenCombineTests/Helpers/CommonTests.swift @@ -222,11 +222,7 @@ func fromNever(_ resultType: T.Type) -> (Never) -> T { // // The second variant compiles with all Swift versions, // but produces a warning in Swift 5.1. -#if swift(>=5.1) return { (_: Never) -> T in } -#else - return { switch $0 {} } -#endif } // swiftlint:enable generic_type_name diff --git a/Tests/OpenCombineTests/Helpers/XCTUnwrap.swift b/Tests/OpenCombineTests/Helpers/XCTUnwrap.swift deleted file mode 100644 index 1803620a..00000000 --- a/Tests/OpenCombineTests/Helpers/XCTUnwrap.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// XCTUnwrap.swift -// -// -// Created by Sergej Jaskiewicz on 15.06.2019. -// - -import XCTest - -// XCTUnwrap is not available when using Swift Package Manager. -// This has been fixed in Swift 5.2, but we want to maintain compatibility. -#if swift(<5.2) - -private struct UnwrappingFailure: Error, LocalizedError { - - let message: String - - var errorDescription: String? { - var failureDescription = "XCTUnwrap failed" - if !message.isEmpty { - failureDescription += ": " - failureDescription += message - } - return failureDescription - } -} - -/// Asserts that an expression is not `nil`, and returns its unwrapped value. -/// -/// Generates a failure when `expression == nil`. -/// -/// - Parameters: -/// - expression: An expression of type `T?` to compare against `nil`. Its type will -/// determine the type of the returned value. -/// - message: An optional description of the failure. -/// - file: The file in which failure occurred. Defaults to the file name of the test -/// case in which this function was called. -/// - line: The line number on which failure occurred. Defaults to the line number on -/// which this function was called. -/// - Returns: A value of type `T`, the result of evaluating and unwrapping the given -/// `expression`. -/// - Throws: An error when `expression == nil`. It will also rethrow any error thrown -/// while evaluating the given expression. -public func XCTUnwrap(_ expression: @autoclosure () throws -> Result?, - _ message: @autoclosure () -> String = "", - file: StaticString = #file, - line: UInt = #line) throws -> Result { - let result = try expression() - if let result = result { - return result - } else { - let error = UnwrappingFailure(message: message()) - XCTFail(error.errorDescription ?? "", file: file, line: line) - throw error - } -} -#endif diff --git a/Tests/OpenCombineTests/ObservableObjectTests.swift b/Tests/OpenCombineTests/ObservableObjectTests.swift index 439dd55e..bc2d0c73 100644 --- a/Tests/OpenCombineTests/ObservableObjectTests.swift +++ b/Tests/OpenCombineTests/ObservableObjectTests.swift @@ -7,8 +7,6 @@ import XCTest -#if swift(>=5.1) - #if OPENCOMBINE_COMPATIBILITY_TEST import Combine @@ -420,5 +418,3 @@ private final class TestObject: ObservableObject { nonPublished = initialValue } } - -#endif diff --git a/Tests/OpenCombineTests/PublishedTests.swift b/Tests/OpenCombineTests/PublishedTests.swift index 01c01ee3..60d0e6c1 100644 --- a/Tests/OpenCombineTests/PublishedTests.swift +++ b/Tests/OpenCombineTests/PublishedTests.swift @@ -7,8 +7,6 @@ import XCTest -#if swift(>=5.1) - #if OPENCOMBINE_COMPATIBILITY_TEST import Combine @@ -322,5 +320,3 @@ private final class TestObject: ObservableObject { _state = Published(initialValue: initialValue) } } - -#endif diff --git a/Tests/OpenCombineTests/PublisherTests/MapKeyPathTests.swift b/Tests/OpenCombineTests/PublisherTests/MapKeyPathTests.swift index f175d7ef..68ad0fba 100644 --- a/Tests/OpenCombineTests/PublisherTests/MapKeyPathTests.swift +++ b/Tests/OpenCombineTests/PublisherTests/MapKeyPathTests.swift @@ -118,7 +118,6 @@ final class MapKeyPathTests: XCTestCase { } } - #if swift(>=5.8) #if Xcode func testMapKeyPathReflection() throws { try testReflection(parentInput: Int.self, @@ -191,44 +190,6 @@ final class MapKeyPathTests: XCTestCase { { $0.map(\.doubled, \.tripled, \.quadrupled) }) } #endif - #else - // WASM Platform CI still use Swift 5.7 - // which will get old KeyPath.description behavior - func testMapKeyPathReflection() throws { - try testReflection(parentInput: Int.self, - parentFailure: Never.self, - description: "ValueForKey", - customMirror: expectedChildren( - ("keyPath", .contains("KeyPath")) - ), - playgroundDescription: "ValueForKey", - subscriberIsAlsoSubscription: false, - { $0.map(\.doubled) }) - - try testReflection(parentInput: Int.self, - parentFailure: Never.self, - description: "ValueForKeys", - customMirror: expectedChildren( - ("keyPath0", .contains("KeyPath")), - ("keyPath1", .contains("KeyPath")) - ), - playgroundDescription: "ValueForKeys", - subscriberIsAlsoSubscription: false, - { $0.map(\.doubled, \.tripled) }) - - try testReflection(parentInput: Int.self, - parentFailure: Never.self, - description: "ValueForKeys", - customMirror: expectedChildren( - ("keyPath0", .contains("KeyPath")), - ("keyPath1", .contains("KeyPath")), - ("keyPath2", .contains("KeyPath")) - ), - playgroundDescription: "ValueForKeys", - subscriberIsAlsoSubscription: false, - { $0.map(\.doubled, \.tripled, \.quadrupled) }) - } - #endif func testMapKeyPathReceiveValueBeforeSubscription() { testReceiveValueBeforeSubscription(value: 0,