[6.0] Handle Swift versions unsupported by XCBuild #7504
Merged
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.
XCBuild has its own notion of supported Swift versions which can differ from the ones SwiftPM's own build system and the used compiler support. Using a version outside of the supported range prevents building, so we'll try to obtain the list of supported versions and intersect it with the versions supported by a given package to find the best version supported by both.
(cherry picked from commit 3f9587c)
Explanation: XCBuild has its own notion of supported Swift versions that can be different from the toolchain/SwiftPM. To support packages that support multiple language versions, including Swift 6, we need to allow falling back to an older language version if the newest supported one is not supported by XCBuild.
Scope: Anyone using XCBuild from existing Xcodes together with a Swift 6 toolchain, specifically we're running into this when adopting Swift 6 in swift-syntax since the macOS toolchain build uses XCBuild to produce universal binaries.
Issue: rdar://126952308 (Building a package that supports Swift 6 mode using a Swift 6 toolchain but with a RainbowE Xcode fails with:
SWIFT_VERSION '6' is unsupported, supported versions are: 4.0, 4.2, 5.0
)Original PR: #7499
Risk: Low risk
Testing: Manually tested with a few different Xcodes, added a unit test for the specific scenario.
Reviewer: @MaxDesiatov