Skip to content

Commit e718730

Browse files
authored
Remove platforms from manifest (#203)
Motivation: Adding or raising the deployment platforms in the package manifest is a SemVer major breaking change as consumers must also add or raise their deployment platforms. This is a known limitation of SwiftPM. Unforunately this means that it's very difficult for non-leaf packages to adopt packages which declare their platforms in the manifest. Doing so puts the brakes on adoption and ecosystem growth. For 'core' packages like this one availability constraints should be expressed on declarations rather than in the manifest. Modifications: - Remove platforms from the package manifest - Add availability annotations to types which require it Result: This package can be more widely adopted
1 parent c7b291b commit e718730

11 files changed

+33
-7
lines changed

Package.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import PackageDescription
33

44
let package = Package(
55
name: "swift-service-lifecycle",
6-
platforms: [
7-
.macOS(.v10_15),
8-
.iOS(.v13),
9-
.watchOS(.v6),
10-
.tvOS(.v13),
11-
],
126
products: [
137
.library(
148
name: "ServiceLifecycle",
@@ -30,7 +24,7 @@ let package = Package(
3024
),
3125
.package(
3226
url: "https://github.com/apple/swift-async-algorithms.git",
33-
from: "1.0.0"
27+
from: "1.0.4"
3428
),
3529
],
3630
targets: [

Sources/ServiceLifecycle/AsyncCancelOnGracefulShutdownSequence.swift

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import AsyncAlgorithms
1616

17+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1718
extension AsyncSequence where Self: Sendable, Element: Sendable {
1819
/// Creates an asynchronous sequence that is cancelled once graceful shutdown has triggered.
1920
///
@@ -24,6 +25,7 @@ extension AsyncSequence where Self: Sendable, Element: Sendable {
2425
}
2526

2627
/// An asynchronous sequence that is cancelled once graceful shutdown has triggered.
28+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2729
public struct AsyncCancelOnGracefulShutdownSequence<Base: AsyncSequence & Sendable>: AsyncSequence, Sendable
2830
where Base.Element: Sendable {
2931
@usableFromInline
@@ -101,6 +103,7 @@ where Base.Element: Sendable {
101103
/// This is just a helper extension and sequence to allow us to get the `nil` value as an element of the sequence.
102104
/// We need this since merge is only finishing when both upstreams are finished but we need to finish when either is done.
103105
/// In the future, we should move to something in async algorithms if it exists.
106+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
104107
extension AsyncSequence where Self: Sendable, Element: Sendable {
105108
@inlinable
106109
func mapNil() -> AsyncMapNilSequence<Self> {
@@ -109,6 +112,7 @@ extension AsyncSequence where Self: Sendable, Element: Sendable {
109112
}
110113

111114
@usableFromInline
115+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
112116
struct AsyncMapNilSequence<Base: AsyncSequence & Sendable>: AsyncSequence, Sendable where Base.Element: Sendable {
113117
@usableFromInline
114118
enum ElementOrEnd: Sendable {

Sources/ServiceLifecycle/AsyncGracefulShutdownSequence.swift

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
///
1919
/// - Note: This sequence respects cancellation and thus is `throwing`.
2020
@usableFromInline
21+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2122
struct AsyncGracefulShutdownSequence: AsyncSequence, Sendable {
2223
@usableFromInline
2324
typealias Element = CancellationWaiter.Reason

Sources/ServiceLifecycle/CancellationWaiter.swift

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/// An actor that provides a function to wait on cancellation/graceful shutdown.
1616
@usableFromInline
17+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1718
actor CancellationWaiter {
1819
@usableFromInline
1920
enum Reason: Sendable {

Sources/ServiceLifecycle/GracefulShutdown.swift

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import ConcurrencyHelpers
3737
/// - handler: The handler which is invoked once graceful shutdown has been triggered.
3838
// Unsafely inheriting the executor is safe to do here since we are not calling any other async method
3939
// except the operation. This makes sure no other executor hops would occur here.
40+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
4041
public func withGracefulShutdownHandler<T>(
4142
isolation: isolated (any Actor)? = #isolation,
4243
operation: () async throws -> T,
@@ -58,6 +59,7 @@ public func withGracefulShutdownHandler<T>(
5859
}
5960

6061
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
62+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
6163
@_disfavoredOverload
6264
public func withGracefulShutdownHandler<T>(
6365
operation: () async throws -> T,
@@ -83,6 +85,7 @@ public func withGracefulShutdownHandler<T>(
8385
// Swift versions since the semantics changed.
8486
@_disfavoredOverload
8587
@_unsafeInheritExecutor
88+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
8689
public func withGracefulShutdownHandler<T>(
8790
operation: () async throws -> T,
8891
onGracefulShutdown handler: @Sendable @escaping () -> Void
@@ -127,6 +130,7 @@ public func withGracefulShutdownHandler<T>(
127130
/// - handler: The handler which is invoked once graceful shutdown or task cancellation has been triggered.
128131
// Unsafely inheriting the executor is safe to do here since we are not calling any other async method
129132
// except the operation. This makes sure no other executor hops would occur here.
133+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
130134
public func withTaskCancellationOrGracefulShutdownHandler<T>(
131135
isolation: isolated (any Actor)? = #isolation,
132136
operation: () async throws -> T,
@@ -139,6 +143,7 @@ public func withTaskCancellationOrGracefulShutdownHandler<T>(
139143
}
140144
}
141145
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
146+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
142147
@_disfavoredOverload
143148
public func withTaskCancellationOrGracefulShutdownHandler<T>(
144149
operation: () async throws -> T,
@@ -152,6 +157,7 @@ public func withTaskCancellationOrGracefulShutdownHandler<T>(
152157
}
153158
#else
154159
@available(*, deprecated, message: "Use the method with the isolation parameter instead.")
160+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
155161
@_disfavoredOverload
156162
@_unsafeInheritExecutor
157163
public func withTaskCancellationOrGracefulShutdownHandler<T>(
@@ -172,6 +178,7 @@ public func withTaskCancellationOrGracefulShutdownHandler<T>(
172178
/// graceful shutdown is triggered then this method will throw a `CancellationError`.
173179
///
174180
/// - Throws: `CancellationError` if the task is cancelled.
181+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
175182
public func gracefulShutdown() async throws {
176183
switch await AsyncGracefulShutdownSequence().first(where: { _ in true }) {
177184
case .cancelled:
@@ -193,6 +200,7 @@ enum ValueOrGracefulShutdown<T: Sendable>: Sendable {
193200
/// Cancels the closure when a graceful shutdown was triggered.
194201
///
195202
/// - Parameter operation: The actual operation.
203+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
196204
public func cancelWhenGracefulShutdown<T: Sendable>(
197205
_ operation: @Sendable @escaping () async throws -> T
198206
) async rethrows -> T {
@@ -243,12 +251,14 @@ public func cancelWhenGracefulShutdown<T: Sendable>(
243251
// renamed pattern has been shown to cause compiler crashes in 5.x compilers.
244252
@available(*, deprecated, message: "renamed to cancelWhenGracefulShutdown")
245253
#endif
254+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
246255
public func cancelOnGracefulShutdown<T: Sendable>(
247256
_ operation: @Sendable @escaping () async throws -> T
248257
) async rethrows -> T? {
249258
return try await cancelWhenGracefulShutdown(operation)
250259
}
251260

261+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
252262
extension Task where Success == Never, Failure == Never {
253263
/// A Boolean value that indicates whether the task is gracefully shutting down
254264
///
@@ -263,13 +273,15 @@ extension Task where Success == Never, Failure == Never {
263273
}
264274

265275
@_spi(TestKit)
276+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
266277
public enum TaskLocals {
267278
@TaskLocal
268279
@_spi(TestKit)
269280
public static var gracefulShutdownManager: GracefulShutdownManager?
270281
}
271282

272283
@_spi(TestKit)
284+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
273285
public final class GracefulShutdownManager: @unchecked Sendable {
274286
struct Handler {
275287
/// The id of the handler.

Sources/ServiceLifecycle/Service.swift

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
/// This is the basic protocol that a service has to implement.
16+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1617
public protocol Service: Sendable {
1718
/// This method is called when the ``ServiceGroup`` is starting all the services.
1819
///

Sources/ServiceLifecycle/ServiceGroup.swift

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import UnixSignals
1717
import AsyncAlgorithms
1818

1919
/// A ``ServiceGroup`` is responsible for running a number of services, setting up signal handling and signalling graceful shutdown to the services.
20+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2021
public actor ServiceGroup: Sendable, Service {
2122
/// The internal state of the ``ServiceGroup``.
2223
private enum State {
@@ -893,6 +894,7 @@ public actor ServiceGroup: Sendable, Service {
893894
}
894895

895896
// This should be removed once we support Swift 5.9+
897+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
896898
extension AsyncStream {
897899
fileprivate static func makeStream(
898900
of elementType: Element.Type = Element.self,

Sources/ServiceLifecycle/ServiceGroupConfiguration.swift

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import UnixSignals
1818
let deprecatedLoggerLabel = "service-lifecycle-deprecated-method-logger"
1919

2020
/// The configuration for the ``ServiceGroup``.
21+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2122
public struct ServiceGroupConfiguration: Sendable {
2223
/// The group's logging configuration.
2324
public struct LoggingConfiguration: Sendable {

Sources/ServiceLifecycleTestKit/GracefulShutdown.swift

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
///
1919
/// It is passed to the `operation` closure of the ``testGracefulShutdown(operation:)`` method and allows
2020
/// to trigger the graceful shutdown for testing purposes.
21+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2122
public struct GracefulShutdownTestTrigger: Sendable {
2223
private let gracefulShutdownManager: GracefulShutdownManager
2324

@@ -35,6 +36,7 @@ public struct GracefulShutdownTestTrigger: Sendable {
3536
///
3637
/// Call the code that you want to test inside the `operation` closure and trigger the graceful shutdown by calling ``GracefulShutdownTestTrigger/triggerGracefulShutdown()``
3738
/// on the ``GracefulShutdownTestTrigger`` that is passed to the `operation` closure.
39+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3840
public func testGracefulShutdown<T>(operation: (GracefulShutdownTestTrigger) async throws -> T) async rethrows -> T {
3941
let gracefulShutdownManager = GracefulShutdownManager()
4042
return try await TaskLocals.$gracefulShutdownManager.withValue(gracefulShutdownManager) {

Sources/UnixSignals/UnixSignalsSequence.swift

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import ConcurrencyHelpers
3333
///
3434
/// - Important: There can only be a single signal handler for a signal installed. So you should avoid creating multiple handlers
3535
/// for the same signal.
36+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3637
public struct UnixSignalsSequence: AsyncSequence, Sendable {
3738
private static let queue = DispatchQueue(label: "com.service-lifecycle.unix-signals")
3839

@@ -74,6 +75,7 @@ public struct UnixSignalsSequence: AsyncSequence, Sendable {
7475
}
7576
}
7677

78+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
7779
extension UnixSignalsSequence {
7880
fileprivate final class Storage: @unchecked Sendable {
7981
private let stateMachine: LockedValueBox<StateMachine>
@@ -169,6 +171,7 @@ extension UnixSignalsSequence {
169171
}
170172
}
171173

174+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
172175
extension UnixSignalsSequence {
173176
fileprivate struct StateMachine {
174177
private enum State {

Tests/ServiceLifecycleTests/GracefulShutdownTests.swift

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ServiceLifecycle
1616
import ServiceLifecycleTestKit
1717
import XCTest
1818

19+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1920
final class GracefulShutdownTests: XCTestCase {
2021
func testWithGracefulShutdownHandler() async {
2122
var cont: AsyncStream<Void>.Continuation!
@@ -255,6 +256,7 @@ final class GracefulShutdownTests: XCTestCase {
255256
}
256257
}
257258

259+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
258260
func testWaitForGracefulShutdown() async throws {
259261
try await testGracefulShutdown { gracefulShutdownTestTrigger in
260262
try await withThrowingTaskGroup(of: Void.self) { group in
@@ -274,6 +276,7 @@ final class GracefulShutdownTests: XCTestCase {
274276
}
275277
}
276278

279+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
277280
func testWaitForGracefulShutdown_WhenAlreadyShutdown() async throws {
278281
try await testGracefulShutdown { gracefulShutdownTestTrigger in
279282
gracefulShutdownTestTrigger.triggerGracefulShutdown()
@@ -355,6 +358,7 @@ final class GracefulShutdownTests: XCTestCase {
355358
}
356359
}
357360

361+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
358362
func testCancelWhenGracefulShutdownSurvivesCancellation() async throws {
359363
await withTaskGroup(of: Void.self) { group in
360364
group.addTask {
@@ -375,6 +379,7 @@ final class GracefulShutdownTests: XCTestCase {
375379
}
376380
}
377381

382+
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
378383
func testCancelWhenGracefulShutdownSurvivesErrorThrown() async throws {
379384
struct MyError: Error, Equatable {}
380385

0 commit comments

Comments
 (0)