@@ -73,9 +73,12 @@ public final class Platform: Sendable {
73
73
/// Minimum OS version for Swift-in-the-OS support. If this is `nil`, the platform does not support Swift-in-the-OS at all.
74
74
fileprivate( set) var minimumOSForSwiftInTheOS : Version ? = nil
75
75
76
- /// Minimum OS version for built-in Swift concurrency support . If this is `nil`, the platform does not support Swift concurrency at all.
76
+ /// Minimum OS version for Swift concurrency (Swift 5.5) . If this is `nil`, the platform does not support Swift concurrency at all.
77
77
fileprivate( set) var minimumOSForSwiftConcurrency : Version ? = nil
78
78
79
+ /// Minimum OS version for Span in the standard library (Swift 6.2). If this is `nil`, the platform does not support Swift concurrency at all.
80
+ fileprivate( set) var minimumOSForSwiftSpan : Version ? = nil
81
+
79
82
/// The canonical name of the public SDK for this platform.
80
83
/// - remark: This does not mean that this SDK exists, just that this is its canonical name if it does exist.
81
84
@_spi ( Testing) public let sdkCanonicalName : String ?
@@ -244,6 +247,11 @@ extension Platform {
244
247
return self . minimumOSForSwiftConcurrency ?? self . correspondingDevicePlatform? . minimumOSForSwiftConcurrency ?? nil
245
248
}
246
249
250
+ /// Determines the deployment version to use for Swift Span support.
251
+ fileprivate func swiftOSSpanVersion( _ deploymentTarget: StringMacroDeclaration ) -> Version ? {
252
+ return self . minimumOSForSwiftSpan ?? self . correspondingDevicePlatform? . minimumOSForSwiftSpan ?? nil
253
+ }
254
+
247
255
/// Determines if the platform supports Swift in the OS.
248
256
public func supportsSwiftInTheOS( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool = false , considerTargetDeviceOSVersion: Bool = true ) -> Bool {
249
257
guard let deploymentTarget = self . deploymentTargetMacro else { return false }
@@ -265,7 +273,7 @@ extension Platform {
265
273
return version >= minimumSwiftInTheOSVersion
266
274
}
267
275
268
- /// Determines if the platform natively supports Swift concurrency. If `false`, then the Swift back-compat concurrency libs needs to be copied into the app/framework's bundle.
276
+ /// Determines if the platform natively supports Swift concurrency. If `false`, then the Swift concurrency back-compat concurrency libs needs to be copied into the app/framework's bundle.
269
277
public func supportsSwiftConcurrencyNatively( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool = false , considerTargetDeviceOSVersion: Bool = true ) -> Bool ? {
270
278
guard let deploymentTarget = self . deploymentTargetMacro else { return false }
271
279
@@ -287,6 +295,29 @@ extension Platform {
287
295
288
296
return version >= minimumSwiftConcurrencyVersion
289
297
}
298
+
299
+ /// Determines if the platform natively supports Swift 6.2's Span type. If `false`, then the Swift Span back-compat concurrency libs needs to be copied into the app/framework's bundle.
300
+ public func supportsSwiftSpanNatively( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool = false , considerTargetDeviceOSVersion: Bool = true ) -> Bool ? {
301
+ guard let deploymentTarget = self . deploymentTargetMacro else { return false }
302
+
303
+ // If we have target device info and its platform matches the build platform, compare the device OS version
304
+ let targetDeviceVersion : Version ?
305
+ if considerTargetDeviceOSVersion && scope. evaluate ( BuiltinMacros . TARGET_DEVICE_PLATFORM_NAME) == self . name {
306
+ targetDeviceVersion = try ? Version ( scope. evaluate ( BuiltinMacros . TARGET_DEVICE_OS_VERSION) )
307
+ } else {
308
+ targetDeviceVersion = nil
309
+ }
310
+
311
+ // Otherwise fall back to comparing the minimum deployment target
312
+ let deploymentTargetVersion = try ? Version ( scope. evaluate ( deploymentTarget) )
313
+
314
+ guard let version = targetDeviceVersion ?? deploymentTargetVersion else { return false }
315
+
316
+ // Return `nil` here as there is no metadata for the platform to allow downstream clients to be aware of this.
317
+ guard let minimumSwiftSpanVersion = swiftOSSpanVersion ( deploymentTarget) else { return nil }
318
+
319
+ return version >= minimumSwiftSpanVersion
320
+ }
290
321
}
291
322
292
323
extension Platform : CustomStringConvertible {
@@ -676,6 +707,7 @@ public final class PlatformRegistry {
676
707
if let variant = platform. defaultSDKVariant {
677
708
platform. minimumOSForSwiftInTheOS = variant. minimumOSForSwiftInTheOS
678
709
platform. minimumOSForSwiftConcurrency = variant. minimumOSForSwiftConcurrency
710
+ platform. minimumOSForSwiftSpan = variant. minimumOSForSwiftSpan
679
711
}
680
712
}
681
713
0 commit comments