-
Notifications
You must be signed in to change notification settings - Fork 89
Add support for the libswiftCompatibilitySpan.dylib backward deployment library #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
slavapestov
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
slavapestov:compatibility-span
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,9 +73,12 @@ public final class Platform: Sendable { | |
/// Minimum OS version for Swift-in-the-OS support. If this is `nil`, the platform does not support Swift-in-the-OS at all. | ||
fileprivate(set) var minimumOSForSwiftInTheOS: Version? = nil | ||
|
||
/// Minimum OS version for built-in Swift concurrency support. If this is `nil`, the platform does not support Swift concurrency at all. | ||
/// Minimum OS version for Swift concurrency (Swift 5.5). If this is `nil`, the platform does not support Swift concurrency at all. | ||
fileprivate(set) var minimumOSForSwiftConcurrency: Version? = nil | ||
|
||
/// 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. | ||
fileprivate(set) var minimumOSForSwiftSpan: Version? = nil | ||
|
||
/// The canonical name of the public SDK for this platform. | ||
/// - remark: This does not mean that this SDK exists, just that this is its canonical name if it does exist. | ||
@_spi(Testing) public let sdkCanonicalName: String? | ||
|
@@ -244,6 +247,11 @@ extension Platform { | |
return self.minimumOSForSwiftConcurrency ?? self.correspondingDevicePlatform?.minimumOSForSwiftConcurrency ?? nil | ||
} | ||
|
||
/// Determines the deployment version to use for Swift Span support. | ||
fileprivate func swiftOSSpanVersion(_ deploymentTarget: StringMacroDeclaration) -> Version? { | ||
return self.minimumOSForSwiftSpan ?? self.correspondingDevicePlatform?.minimumOSForSwiftSpan ?? nil | ||
} | ||
|
||
/// Determines if the platform supports Swift in the OS. | ||
public func supportsSwiftInTheOS(_ scope: MacroEvaluationScope, forceNextMajorVersion: Bool = false, considerTargetDeviceOSVersion: Bool = true) -> Bool { | ||
guard let deploymentTarget = self.deploymentTargetMacro else { return false } | ||
|
@@ -265,7 +273,7 @@ extension Platform { | |
return version >= minimumSwiftInTheOSVersion | ||
} | ||
|
||
/// 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. | ||
/// 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. | ||
public func supportsSwiftConcurrencyNatively(_ scope: MacroEvaluationScope, forceNextMajorVersion: Bool = false, considerTargetDeviceOSVersion: Bool = true) -> Bool? { | ||
guard let deploymentTarget = self.deploymentTargetMacro else { return false } | ||
|
||
|
@@ -287,6 +295,29 @@ extension Platform { | |
|
||
return version >= minimumSwiftConcurrencyVersion | ||
} | ||
|
||
/// 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. | ||
public func supportsSwiftSpanNatively(_ scope: MacroEvaluationScope, forceNextMajorVersion: Bool = false, considerTargetDeviceOSVersion: Bool = true) -> Bool? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why add default values for the arguments? This is only ever called in one place. |
||
guard let deploymentTarget = self.deploymentTargetMacro else { return false } | ||
|
||
// If we have target device info and its platform matches the build platform, compare the device OS version | ||
let targetDeviceVersion: Version? | ||
if considerTargetDeviceOSVersion && scope.evaluate(BuiltinMacros.TARGET_DEVICE_PLATFORM_NAME) == self.name { | ||
targetDeviceVersion = try? Version(scope.evaluate(BuiltinMacros.TARGET_DEVICE_OS_VERSION)) | ||
} else { | ||
targetDeviceVersion = nil | ||
} | ||
|
||
// Otherwise fall back to comparing the minimum deployment target | ||
let deploymentTargetVersion = try? Version(scope.evaluate(deploymentTarget)) | ||
|
||
guard let version = targetDeviceVersion ?? deploymentTargetVersion else { return false } | ||
|
||
// Return `nil` here as there is no metadata for the platform to allow downstream clients to be aware of this. | ||
guard let minimumSwiftSpanVersion = swiftOSSpanVersion(deploymentTarget) else { return nil } | ||
|
||
return version >= minimumSwiftSpanVersion | ||
} | ||
} | ||
|
||
extension Platform: CustomStringConvertible { | ||
|
@@ -676,6 +707,7 @@ public final class PlatformRegistry { | |
if let variant = platform.defaultSDKVariant { | ||
platform.minimumOSForSwiftInTheOS = variant.minimumOSForSwiftInTheOS | ||
platform.minimumOSForSwiftConcurrency = variant.minimumOSForSwiftConcurrency | ||
platform.minimumOSForSwiftSpan = variant.minimumOSForSwiftSpan | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the platform does not support Swift concurrency at all."
Think this needs to be updated to reflect Span, rather than Swift Concurrency