Skip to content

Commit

Permalink
Merge pull request #123 from unsignedapps/swift-6
Browse files Browse the repository at this point in the history
Added support for Xcode 16 and Swift 6
  • Loading branch information
bok- authored Jul 16, 2024
2 parents 247228a + 5ad35d1 commit 85175ff
Show file tree
Hide file tree
Showing 18 changed files with 801 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ios-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: check-changes
strategy:
matrix:
xcode: [ "15.4" ]
xcode: [ "15.4", "16.0" ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ jobs:
needs: check-changes
strategy:
matrix:
swift: [ "5.10.1" ]
os: [ amazonlinux2, bookworm, focal, jammy, rhel-ubi9, mantic, noble ]
swift: [ "swift:5.10.1", "swiftlang/swift:nightly-6.0" ]
os: [ amazonlinux2, bookworm, focal, jammy, rhel-ubi9, mantic, noble ]
exclude:
- swift: "swiftlang/swift:nightly-6.0"
os: "bookworm"
- swift: "swiftlang/swift:nightly-6.0"
os: "mantic"
- swift: "swiftlang/swift:nightly-6.0"
os: "noble"

container:
image: swift:${{ matrix.swift }}-${{ matrix.os }}
image: ${{ matrix.swift }}-${{ matrix.os }}

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: check-changes
strategy:
matrix:
xcode: [ "15.4" ]
xcode: [ "15.4", "16.0" ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tvos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: check-changes
strategy:
matrix:
xcode: [ "15.4" ]
xcode: [ "15.4", "16.0" ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/visionos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: check-changes
strategy:
matrix:
xcode: [ "15.4" ]
xcode: [ "15.4", "16.0" ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/watchos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: check-changes
strategy:
matrix:
xcode: [ "15.4" ]
xcode: [ "15.4", "16.0" ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SWIFT := swift
SWIFTFORMAT := $(SWIFT) package plugin --allow-writing-to-package-directory swiftformat
DOCKER := docker
SWIFT_DOCKER_IMAGE = swift:latest
SWIFT_DOCKER_IMAGE = swiftlang/swift:nightly-6.0-jammy

XCBEAUTIFY := $(shell command -v xcbeautify 2> /dev/null)
ifndef XCBEAUTIFY
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
Expand All @@ -23,7 +23,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.54.1"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "510.0.0"),
.package(url: "https://github.com/apple/swift-syntax.git", exact: "600.0.0-prerelease-2024-06-12"),
],

targets: {
Expand Down Expand Up @@ -96,6 +96,6 @@ let package = Package(
}(),

swiftLanguageVersions: [
.v5,
.v6,
]
)
101 changes: 101 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "Vexil",

platforms: [
.iOS(.v15),
.macOS(.v12),
.tvOS(.v15),
.watchOS(.v8),
],

products: [
// Automatic
.library(name: "Vexil", targets: [ "Vexil" ]),
// .library(name: "Vexillographer", targets: [ "Vexillographer" ]),
],

dependencies: [
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.54.1"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "510.0.0"),
],

targets: {
var targets: [Target] = [

// Vexil

.target(
name: "Vexil",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
name: "VexilTests",
dependencies: [
.target(name: "Vexil"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),

// Vexillographer

// .target(
// name: "Vexillographer",
// dependencies: [
// .target(name: "Vexil"),
// ]
// ),

// Macros

.macro(
name: "VexilMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),

]

#if !os(Linux)
targets += [
.testTarget(
name: "VexilMacroTests",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
]
#endif

return targets
}(),

swiftLanguageVersions: [
.v5,
]
)
2 changes: 1 addition & 1 deletion Sources/Vexil/Pole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public final class FlagPole<RootGroup>: Sendable where RootGroup: FlagContainer
/// - snapshot: The `Snapshot` to be inserted
/// - at: The index at which to insert the `Snapshot`.
///
public func insert(snapshot: Snapshot<RootGroup>, at index: Array<FlagValueSource>.Index) {
public func insert(snapshot: Snapshot<RootGroup>, at index: Array<any FlagValueSource>.Index) {
_sources.insert(snapshot, at: index)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,23 @@ extension NSUbiquitousKeyValueStore: NonSendableFlagValueSource {

private static let didChangeInternallyNotification = NSNotification.Name(rawValue: "NSUbiquitousKeyValueStore.didChangeExternallyNotification")

public typealias ChangeStream = AsyncMapSequence<AsyncChain2Sequence<NotificationCenter.Notifications, NotificationCenter.Notifications>, FlagChange>
public typealias ChangeStream = AsyncThrowingMapSequence<
AsyncChain2Sequence<
AsyncFilterSequence<NotificationCenter.Notifications>,
AsyncFilterSequence<NotificationCenter.Notifications>
>,
FlagChange
>

public var flagValueChanges: ChangeStream {
chain(
NotificationCenter.default.notifications(named: Self.didChangeExternallyNotification, object: self),
NotificationCenter.default.notifications(named: Self.didChangeInternallyNotification, object: self)
let this = ObjectIdentifier(self)
return chain(
NotificationCenter.default
.notifications(named: Self.didChangeExternallyNotification, object: nil)
.filter { $0.object.isIdentical(to: this) },
NotificationCenter.default
.notifications(named: Self.didChangeInternallyNotification, object: nil)
.filter { $0.object.isIdentical(to: this) }
)
.map { _ in
FlagChange.all
Expand All @@ -73,4 +84,13 @@ extension NSUbiquitousKeyValueStore: NonSendableFlagValueSource {

}

private extension Any? {
func isIdentical(to object: ObjectIdentifier) -> Bool {
guard let self = self as? AnyObject else {
return false
}
return ObjectIdentifier(self) == object
}
}

#endif
46 changes: 38 additions & 8 deletions Sources/Vexil/Sources/UserDefaults+FlagValueSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,34 @@ extension UserDefaults: NonSendableFlagValueSource {

#if os(watchOS)

public typealias ChangeStream = AsyncMapSequence<NotificationCenter.Notifications, FlagChange>
public typealias ChangeStream = AsyncMapSequence<AsyncFilterSequence<NotificationCenter.Notifications>, FlagChange>

public var flagValueChanges: ChangeStream {
NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification, object: self)
let this = ObjectIdentifier(self)
return NotificationCenter.default
.notifications(named: UserDefaults.didChangeNotification)
.filter { $0.object.isIdentical(to: this) }
.map { _ in
FlagChange.all
}
}

#elseif os(macOS)

public typealias ChangeStream = AsyncMapSequence<AsyncChain2Sequence<NotificationCenter.Notifications, NotificationCenter.Notifications>, FlagChange>
public typealias ChangeStream = AsyncMapSequence<
AsyncChain2Sequence<
AsyncFilterSequence<NotificationCenter.Notifications>,
NotificationCenter.Notifications
>,
FlagChange
>

public var flagValueChanges: ChangeStream {
chain(
NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification, object: self),
let this = ObjectIdentifier(self)
return chain(
NotificationCenter.default
.notifications(named: UserDefaults.didChangeNotification)
.filter { $0.object.isIdentical(to: this) },

// We use the raw value here because the class property is painfully @MainActor
NotificationCenter.default.notifications(named: .init("NSApplicationDidBecomeActiveNotification"))
Expand All @@ -92,11 +104,20 @@ extension UserDefaults: NonSendableFlagValueSource {

#elseif canImport(UIKit)

public typealias ChangeStream = AsyncMapSequence<AsyncChain2Sequence<NotificationCenter.Notifications, NotificationCenter.Notifications>, FlagChange>
public typealias ChangeStream = AsyncMapSequence<
AsyncChain2Sequence<
AsyncFilterSequence<NotificationCenter.Notifications>,
NotificationCenter.Notifications
>,
FlagChange
>

public var flagValueChanges: ChangeStream {
chain(
NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification, object: self),
let this = ObjectIdentifier(self)
return chain(
NotificationCenter.default
.notifications(named: UserDefaults.didChangeNotification)
.filter { $0.object.isIdentical(to: this) },

// We use the raw value here because the class property is painfully @MainActor
NotificationCenter.default.notifications(named: .init("UIApplicationDidBecomeActiveNotification"))
Expand All @@ -115,3 +136,12 @@ extension UserDefaults: NonSendableFlagValueSource {

#endif
}

private extension Any? {
func isIdentical(to object: ObjectIdentifier) -> Bool {
guard let self = self as? AnyObject else {
return false
}
return ObjectIdentifier(self) == object
}
}
Loading

0 comments on commit 85175ff

Please sign in to comment.