@@ -73,9 +73,12 @@ public final class Platform: Sendable {
7373 /// Minimum OS version for Swift-in-the-OS support. If this is `nil`, the platform does not support Swift-in-the-OS at all.
7474 fileprivate( set) var minimumOSForSwiftInTheOS : Version ? = nil
7575
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.
7777 fileprivate( set) var minimumOSForSwiftConcurrency : Version ? = nil
7878
79+ /// Minimum OS version for Span in the standard library (Swift 6.2). If this is `nil`, Span, MutableSpan, and related types are not available.
80+ fileprivate( set) var minimumOSForSwiftSpan : Version ? = nil
81+
7982 /// The canonical name of the public SDK for this platform.
8083 /// - remark: This does not mean that this SDK exists, just that this is its canonical name if it does exist.
8184 @_spi ( Testing) public let sdkCanonicalName : String ?
@@ -244,6 +247,11 @@ extension Platform {
244247 return self . minimumOSForSwiftConcurrency ?? self . correspondingDevicePlatform? . minimumOSForSwiftConcurrency ?? nil
245248 }
246249
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+
247255 /// Determines if the platform supports Swift in the OS.
248256 public func supportsSwiftInTheOS( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool = false , considerTargetDeviceOSVersion: Bool = true ) -> Bool {
249257 guard let deploymentTarget = self . deploymentTargetMacro else { return false }
@@ -265,7 +273,7 @@ extension Platform {
265273 return version >= minimumSwiftInTheOSVersion
266274 }
267275
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.
269277 public func supportsSwiftConcurrencyNatively( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool = false , considerTargetDeviceOSVersion: Bool = true ) -> Bool ? {
270278 guard let deploymentTarget = self . deploymentTargetMacro else { return false }
271279
@@ -287,6 +295,29 @@ extension Platform {
287295
288296 return version >= minimumSwiftConcurrencyVersion
289297 }
298+
299+ /// Determines if the platform natively supports Swift 6.2's Span type. If `false`, then the Swift Span back-compat lib needs to be copied into the app/framework's bundle.
300+ public func supportsSwiftSpanNatively( _ scope: MacroEvaluationScope , forceNextMajorVersion: Bool , considerTargetDeviceOSVersion: Bool ) -> 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+ }
290321}
291322
292323extension Platform : CustomStringConvertible {
@@ -633,6 +664,7 @@ public final class PlatformRegistry {
633664 if let variant = platform. defaultSDKVariant {
634665 platform. minimumOSForSwiftInTheOS = variant. minimumOSForSwiftInTheOS
635666 platform. minimumOSForSwiftConcurrency = variant. minimumOSForSwiftConcurrency
667+ platform. minimumOSForSwiftSpan = variant. minimumOSForSwiftSpan
636668 }
637669 }
638670
0 commit comments