Skip to content

Commit

Permalink
Add Swift 5.10 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Mar 12, 2024
1 parent 75db6ca commit 911d870
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 33 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/swift-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
variables:
outputs:
max-supported-swift-version: '5.9'
max-supported-swift-version: '5.10'
xcode-scheme: color-components-Package
xcode-platform-version: latest
fail-if-codecov-fails: true
Expand All @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ macOS, ubuntu ]
swift-version-offset: [ 0 ]
swift-version-offset: [ 0, 1 ]
uses: sersoft-gmbh/oss-common-actions/.github/workflows/swift-test-spm.yml@main
with:
os: ${{ matrix.os }}
Expand All @@ -45,7 +45,8 @@ jobs:
- iPadOS
- tvOS
- watchOS
swift-version-offset: [ 0 ]
- visionOS
swift-version-offset: [ 0, 1 ]
uses: sersoft-gmbh/oss-common-actions/.github/workflows/swift-test-xcode.yml@main
with:
xcode-scheme: ${{ needs.variables.outputs.xcode-scheme }}
Expand Down
21 changes: 14 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -8,9 +8,16 @@ let swiftSettings: Array<SwiftSetting> = [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("DeprecateApplicationMain"),
// .enableExperimentalFeature("AccessLevelOnImport"),
// .enableExperimentalFeature("VariadicGenerics"),
// .unsafeFlags(["-warn-concurrency"], .when(configuration: .debug)),
]

let concurrencySwiftSettings: Array<SwiftSetting> = [
// Not yet possible for ColorCalculations due to CIFormat constants being mutable.
.enableExperimentalFeature("StrictConcurrency"),
.enableExperimentalFeature("GlobalConcurrency"),
]

let package = Package(
Expand All @@ -32,24 +39,24 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ColorComponents",
swiftSettings: swiftSettings),
swiftSettings: swiftSettings + concurrencySwiftSettings),
.target(
name: "ColorCalculations",
dependencies: ["ColorComponents"],
swiftSettings: swiftSettings),
.target(
name: "XCHelpers",
swiftSettings: swiftSettings,
swiftSettings: swiftSettings + concurrencySwiftSettings,
linkerSettings: [
.linkedFramework("XCTest", .when(platforms: [.iOS, .macOS, .macCatalyst, .tvOS, .watchOS])),
.linkedFramework("XCTest", .when(platforms: [.iOS, .macOS, .macCatalyst, .tvOS, .watchOS, .visionOS])),
]),
.testTarget(
name: "ColorComponentsTests",
dependencies: [
"ColorComponents",
"XCHelpers",
],
swiftSettings: swiftSettings),
swiftSettings: swiftSettings + concurrencySwiftSettings),
.testTarget(
name: "ColorCalculationsTests",
dependencies: [
Expand All @@ -59,6 +66,6 @@ let package = Package(
resources: [
.copy("TestImages"),
],
swiftSettings: swiftSettings),
swiftSettings: swiftSettings + concurrencySwiftSettings),
]
)
67 changes: 67 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let swiftSettings: Array<SwiftSetting> = [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("DisableOutwardActorInference"),
// .enableExperimentalFeature("VariadicGenerics"),
]

let concurrencySwiftSettings: Array<SwiftSetting> = [
// Not yet possible for ColorCalculations due to CIFormat constants being mutable.
.enableExperimentalFeature("StrictConcurrency"),
]

let package = Package(
name: "color-components",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ColorComponents",
targets: ["ColorComponents"]),
.library(
name: "ColorCalculations",
targets: ["ColorCalculations"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ColorComponents",
swiftSettings: swiftSettings + concurrencySwiftSettings),
.target(
name: "ColorCalculations",
dependencies: ["ColorComponents"],
swiftSettings: swiftSettings),
.target(
name: "XCHelpers",
swiftSettings: swiftSettings + concurrencySwiftSettings,
linkerSettings: [
.linkedFramework("XCTest", .when(platforms: [.iOS, .macOS, .macCatalyst, .tvOS, .watchOS, .visionOS])),
]),
.testTarget(
name: "ColorComponentsTests",
dependencies: [
"ColorComponents",
"XCHelpers",
],
swiftSettings: swiftSettings + concurrencySwiftSettings),
.testTarget(
name: "ColorCalculationsTests",
dependencies: [
"ColorCalculations",
"XCHelpers",
],
resources: [
.copy("TestImages"),
],
swiftSettings: swiftSettings + concurrencySwiftSettings),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGColor {
func _extractBW(alpha: UnsafeMutablePointer<CGFloat>? = nil) -> BW<CGFloat> {
let color = _requireColorSpace(named: CGColorSpace.genericGray)
let components = color._requireCompontens(in: 1...2)
if let alpha = alpha {
if let alpha {
alpha.pointee = color.alpha
}
return .init(white: components[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGColor {
func _extractCIEXYZ(alpha: UnsafeMutablePointer<CGFloat>? = nil) -> CIE.XYZ<CGFloat> {
let color = _requireColorSpace(named: CGColorSpace.genericXYZ)
let components = color._requireCompontens(in: 3...4)
if let alpha = alpha {
if let alpha {
alpha.pointee = color.alpha
}
return .init(x: components[0], y: components[1], z: components[2])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import CoreGraphics

extension CGColorSpace {
// There seems to be no constants for these in CoreGraphics...
#if compiler(>=5.10) && hasFeature(StrictConcurrency) && hasFeature(GlobalConcurrency)
static nonisolated(unsafe) let genericGray: CFString = "kCGColorSpaceGenericGray" as CFString
static nonisolated(unsafe) let genericRGB: CFString = "kCGColorSpaceGenericRGB" as CFString
#else
static let genericGray: CFString = "kCGColorSpaceGenericGray" as CFString
static let genericRGB: CFString = "kCGColorSpaceGenericRGB" as CFString
#endif
}

extension CGColorSpace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGColor {
func _extractRGB(alpha: UnsafeMutablePointer<CGFloat>? = nil) -> RGB<CGFloat> {
let color = _requireColorSpace(named: CGColorSpace.genericRGB)
let components = color._requireCompontens(in: 3...4)
if let alpha = alpha {
if let alpha {
alpha.pointee = color.alpha
}
return .init(red: components[0], green: components[1], blue: components[2])
Expand Down
8 changes: 4 additions & 4 deletions Tests/ColorCalculationsTests/ImageColorsCalculatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ final class ImageColorsCalculatorTests: XCTestCase {
#endif
}

func testUIImageInitializer() throws {
func testUIImageInitializer() async throws {
#if !canImport(CoreImage) || !canImport(UIKit)
try skipUnavailableAPI()
#else
Expand All @@ -182,13 +182,13 @@ final class ImageColorsCalculatorTests: XCTestCase {
let uiImage = try XCTUnwrap(UIImage(contentsOfFile: img1URL.path))
let calculator = ImageColorsCalculator(uiImage: uiImage)
XCTAssertNotNil(calculator)
let uiImage2 = try XCTUnwrap(NonCIUIImage(contentsOfFile: img2URL.path))
let uiImage2 = try await MainActor.run { [img2URL] in try XCTUnwrap(NonCIUIImage(contentsOfFile: img2URL.path)) }
let calculator2 = ImageColorsCalculator(uiImage: uiImage2)
XCTAssertNotNil(calculator2)
let uiImage3 = try NonCGUIImage(ciImage: XCTUnwrap(CIImage(contentsOf: img1URL)))
let uiImage3 = try await MainActor.run { [img1URL] in try NonCGUIImage(ciImage: XCTUnwrap(CIImage(contentsOf: img1URL))) }
let calculator3 = ImageColorsCalculator(uiImage: uiImage3)
XCTAssertNotNil(calculator3)
let uiImage4 = try XCTUnwrap(NonBackingUIImage(contentsOfFile: img1URL.path))
let uiImage4 = try await MainActor.run { [img1URL] in try XCTUnwrap(NonBackingUIImage(contentsOfFile: img1URL.path)) }
let calculator4 = ImageColorsCalculator(uiImage: uiImage4)
XCTAssertNil(calculator4)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ final class BWA_SwiftUITests: XCTestCase {
#endif
}

func testViewConformance() throws {
func testViewConformance() async throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine) && (canImport(UIKit) || (canImport(AppKit) && !targetEnvironment(macCatalyst)) || canImport(CoreGraphics))
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -117,8 +117,10 @@ final class BWA_SwiftUITests: XCTestCase {
let bw = BW<Double>(white: 0.5)
let bwa = BWA(bw: bw, alpha: 0.25)

XCTAssertEqual(bw.body as? Color, Color(bw))
XCTAssertEqual(bwa.body as? Color, Color(bwa))
await MainActor.run {
XCTAssertEqual(bw.body as? Color, Color(bw))
XCTAssertEqual(bwa.body as? Color, Color(bwa))
}
#else
try skipUnavailableAPI()
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ final class CIEXYZA_SwiftUITests: XCTestCase {
#endif
}

func testViewConformance() throws {
func testViewConformance() async throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine) && (canImport(UIKit) || (canImport(AppKit) && !targetEnvironment(macCatalyst)) || canImport(CoreGraphics))
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -129,8 +129,10 @@ final class CIEXYZA_SwiftUITests: XCTestCase {
let cieXYZ = CIE.XYZ<Double>(x: 0.5, y: 0.25, z: 0.75)
let cieXYZA = CIE.XYZA(xyz: cieXYZ, alpha: 0.25)

XCTAssertEqual(cieXYZ.body as? Color, Color(cieXYZ))
XCTAssertEqual(cieXYZA.body as? Color, Color(cieXYZA))
await MainActor.run {
XCTAssertEqual(cieXYZ.body as? Color, Color(cieXYZ))
XCTAssertEqual(cieXYZA.body as? Color, Color(cieXYZA))
}
#else
try skipUnavailableAPI()
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class HSBA_SwiftUITests: XCTestCase {
#endif
}

func testViewConformance() throws {
func testViewConformance() async throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine) && (canImport(UIKit) || (canImport(AppKit) && !targetEnvironment(macCatalyst)) || canImport(CoreGraphics))
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -133,8 +133,10 @@ final class HSBA_SwiftUITests: XCTestCase {
let hsb = HSB<Double>(hue: 0.5, saturation: 0.25, brightness: 0.75)
let hsba = HSBA(hsb: hsb, alpha: 0.25)

XCTAssertEqual(hsb.body as? Color, Color(hsb))
XCTAssertEqual(hsba.body as? Color, Color(hsba))
await MainActor.run {
XCTAssertEqual(hsb.body as? Color, Color(hsb))
XCTAssertEqual(hsba.body as? Color, Color(hsba))
}
#else
try skipUnavailableAPI()
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ final class HSLA_SwiftUITests: XCTestCase {
#endif
}

func testViewConformance() throws {
func testViewConformance() async throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine) && (canImport(UIKit) || (canImport(AppKit) && !targetEnvironment(macCatalyst)) || canImport(CoreGraphics))
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -133,8 +133,10 @@ final class HSLA_SwiftUITests: XCTestCase {
let hsl = HSL<Double>(hue: 0.5, saturation: 0.25, luminance: 0.75)
let hsla = HSLA(hsl: hsl, alpha: 0.25)

XCTAssertEqual(hsl.body as? Color, Color(hsl))
XCTAssertEqual(hsla.body as? Color, Color(hsla))
await MainActor.run {
XCTAssertEqual(hsl.body as? Color, Color(hsl))
XCTAssertEqual(hsla.body as? Color, Color(hsla))
}
#else
try skipUnavailableAPI()
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ final class RGBA_SwiftUITests: XCTestCase {
#endif
}

func testViewConformance() throws {
func testViewConformance() async throws {
#if arch(arm64) || arch(x86_64)
#if canImport(SwiftUI) && canImport(Combine) && (canImport(UIKit) || (canImport(AppKit) && !targetEnvironment(macCatalyst)) || canImport(CoreGraphics))
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -132,8 +132,10 @@ final class RGBA_SwiftUITests: XCTestCase {
let rgb = RGB<Double>(red: 0.5, green: 0.25, blue: 0.75)
let rgba = RGBA(rgb: rgb, alpha: 0.25)

XCTAssertEqual(rgb.body as? Color, Color(rgb))
XCTAssertEqual(rgba.body as? Color, Color(rgba))
await MainActor.run {
XCTAssertEqual(rgb.body as? Color, Color(rgb))
XCTAssertEqual(rgba.body as? Color, Color(rgba))
}
#else
try skipUnavailableAPI()
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/ColorComponentsTests/RGBA/RGBA+HexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class RGBA_HexTests: XCTestCase {
XCTAssertNil(rgbInvalid)
XCTAssertNil(rgbaInvalid)

if let rgb = rgb {
if let rgb {
XCTAssertEqual(rgb.red, 1, accuracy: .ulpOfOne)
XCTAssertEqual(rgb.green, 0x80 / 0xFF, accuracy: .ulpOfOne)
XCTAssertEqual(rgb.blue, 0x55 / 0xFF, accuracy: .ulpOfOne)
Expand Down

0 comments on commit 911d870

Please sign in to comment.