Skip to content

Commit

Permalink
Fix language mode compatibility (#158)
Browse files Browse the repository at this point in the history
* Setup further testing on CI

* Use swift(version) compiler condition instead of compiler(version)

* Revert it back to use compiler() instead of swift()

* Add nonisolated init under conditional compilation hasFeature(IsolatedDefaultValues)
  • Loading branch information
ra1028 authored Nov 20, 2024
1 parent 7b1510d commit 8dbffb9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,29 @@ jobs:
- name: Test example tvOS
run: scripts/test.sh example-cross-platform tvos

upcoming_feature:
name: Upcoming features
test_upcoming_features:
name: Test upcoming features with Xcode 15
runs-on: macos-14
env:
DEVELOPER_DIR: /Applications/Xcode_15.4.app
steps:
- uses: actions/checkout@v4
- name: Test with upcoming features
- name: Test upcoming features
run: ENABLE_UPCOMING_FEATURES=1 scripts/test.sh library ios

test_language_mode:
name: Test Swift 5 language mode
runs-on: macos-14
strategy:
matrix:
enable_upcoming_features:
- 0
- 1
steps:
- uses: actions/checkout@v4
- name: Test Swift 5 language mode
run: ENABLE_UPCOMING_FEATURES=${{ matrix.enable_upcoming_features }} scripts/test.sh library ios SWIFT_VERSION=5

benchmark:
name: Benchmark
runs-on: macos-14
Expand Down
19 changes: 16 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

import PackageDescription

let swiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("ExistentialAny")
]
let swiftSettings: [SwiftSetting]

if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
swiftSettings = [
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("InferSendableFromCaptures"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("ExistentialAny"),
]
}
else {
swiftSettings = [
.enableUpcomingFeature("ExistentialAny")
]
}

let package = Package(
name: "swiftui-atom-properties",
Expand Down
5 changes: 3 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import PackageDescription

let swiftSettings: [SwiftSetting]

if Context.environment["ENABLE_UPCOMING_FEATURES"] != nil {
if Context.environment["ENABLE_UPCOMING_FEATURES"] == "1" {
swiftSettings = [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("ExistentialAny"),
]
}
else {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Atoms/Core/SubscriberState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import Foundation
internal final class SubscriberState {
let token = SubscriberKey.Token()

#if !hasFeature(IsolatedDefaultValues)
nonisolated init() {}
#endif

#if compiler(>=6)
nonisolated(unsafe) var subscribing = Set<AtomKey>()
nonisolated(unsafe) var unsubscribe: ((Set<AtomKey>) -> Void)?
Expand Down Expand Up @@ -34,10 +38,6 @@ internal final class SubscriberState {
_modify { yield &_unsubscribe.value }
}

#if hasFeature(DisableOutwardActorInference)
nonisolated init() {}
#endif

deinit {
if Thread.isMainThread {
_unsubscribe.value?(_subscribing.value)
Expand Down
13 changes: 9 additions & 4 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -eu

TARGET=$1
PLATFORM=$2
ARGS=${@:3}

pushd "$(cd $(dirname $0)/.. && pwd)" &>/dev/null

Expand All @@ -22,20 +23,24 @@ watchos)
;;
esac

clean_test() {
xcodebuild clean test "$@" $ARGS
}

case $TARGET in
library)
xcodebuild clean test -scheme swiftui-atom-properties -destination platform="$platform"
clean_test -scheme swiftui-atom-properties -destination platform="$platform"
;;
example-ios)
cd Examples/Packages/iOS
xcodebuild clean test -scheme iOSExamples -destination platform="$platform"
clean_test -scheme iOSExamples -destination platform="$platform"
;;
example-cross-platform)
cd Examples/Packages/CrossPlatform
xcodebuild clean test -scheme CrossPlatformExamples -destination platform="$platform"
clean_test -scheme CrossPlatformExamples -destination platform="$platform"
;;
benchmark)
cd Benchmarks
xcodebuild clean test -scheme BenchmarkTests -destination platform="$platform"
clean_test -scheme BenchmarkTests -destination platform="$platform"
;;
esac

0 comments on commit 8dbffb9

Please sign in to comment.