Repository navigation
Map SWIFT_VERSION to a valid -swift-version language mode - #44
Merged
Merged
Conversation
swiftc only accepts language modes (4, 4.2, 5, 6) for -swift-version, but SWIFT_VERSION in Xcode projects is an arbitrary x.y value (6.0, 5.9, 4.0, ...). Xcode normalizes it before invoking swiftc; axe only trimmed a trailing .0, so anything else was passed through and the preview thunk failed to compile with e.g.: invalid value '5.9' in '-swift-version 5.9' Map any x.y to its major. 4.2 is a distinct language mode and is kept as-is. The previous special case that kept "4.0" literal is dropped: swiftc rejects it the same way (verified with Swift 6.3.3): -swift-version 4 OK -swift-version 4.0 error: invalid value '4.0' in '-swift-version 4.0' -swift-version 4.2 OK
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
-swift-versiononly accepts Swift language modes (4,4.2,5,6), butSWIFT_VERSIONin an Xcode project is an arbitraryx.ybuild setting (6.0,5.9,4.0, …). Xcode normalizes it before callingswiftc; axe only trimmed a trailing.0, so any other value was passed through verbatim and the preview thunk failed to compile.This PR maps any
x.yto its major version (keeping4.2, which is a real language mode) and drops the special case that preserved4.0.Problem
Projects that set
SWIFT_VERSION = 5.9in an xcconfig cannot capture any preview:The previous normalization was:
It handles
6.0→6and5.0→5, but5.9(or5.10,6.1, …) is left untouched. The4.0exception also turns out to be wrong:swiftcrejects4.0exactly like5.9.Fix
Any
x.ybecomesx.4.2is kept as-is because it is a distinct language mode.The literal
4.0is no longer preserved. Verified with Swift 6.3.3:Verification
TestCompileThunk_SwiftVersionTrimmingnow covers5.9 → 5and4.0 → 4alongside the existing cases.SWIFT_VERSION=5.9: the thunk is compiled with-swift-version 5and the capture succeeds.