Skip to content
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

Support compiling project with Swift 5.5 #1049

Merged
merged 3 commits into from
Apr 5, 2022

Conversation

liamnichols
Copy link
Collaborator

@liamnichols liamnichols commented Apr 1, 2022

Background

When using SwiftSyntax and linking to a specific version of lib_internalSwiftSyntaxParser, it does not matter which toolchain you use to compile the project.

In #1037, we just updated Package.swift to require Swift 5.6 or later (Xcode 13.3+), enforced by setting swift-tools-version to 5.6 - Doing this then caused SPM to update the Package.resolved format to v2 and also required some syntax changes in Package.swift, but that's about it since using SwiftSyntax 0.50600.1 and linking to the right version of lib_internalSwiftSyntaxParser is something separate.

The downside locking into Swift 5.6+ is that you can no longer build the project using anything older than Xcode 13.3. While this is not common, since most users of Sorcery use the precompiled binary, there are still some users who want to be able to use tools such as Mint to compile from source but find themselves unable to (i.e if they user GitHub Actions, which don't currently support Xcode 13.3/macOS 12) - #1045

Initially I thought that if we wanted to support Xcode 13, 13.1 or 13.2 then we had to use SwiftSyntax 0.50500.0, and thus have essentially two different versions of Sourcery to test/maintain, I thought that this wouldn't be worth doing. But after testing, it seems like its simpler than that.

Changes

In this change, I update Package.swift to set swift-tools-version back to 5.5, revert some syntax changes and revert Package.resolved back to the v1 format (being careful to preserve the pins from before). This allows the following:

➜  Sourcery git:(ln/xcode-13) swift --version          
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: arm64-apple-macosx12.0
➜  Sourcery git:(ln/xcode-13) swift build
...
➜  Sourcery git:(ln/xcode-13) swift run sourcery --version
[0/0] Build complete!
1.8.0

We could continue to support Swift 5.5 like this until a point where we might want to use Swift 5.6 language specific features in the codebase.

I guess the one big thing to note here, since it is a bit meta and confusing, while you can compile the sourcery codebase with Swift 5.5, we still use SwiftSyntax 5.6 and therefore remain able to parse the AST of both Swift 5.5 and 5.6 source code.

Note: Since we downgrade swift tools here, this might need you to clear out .swiftpm or .build directories on local machines. I don't anticipate that to be much of a problem though.

@AF-cgi
Copy link

AF-cgi commented Apr 1, 2022

Looks fine for me and works perfect. Thanks @liamnichols

@liamnichols liamnichols marked this pull request as ready for review April 5, 2022 09:04
@liamnichols
Copy link
Collaborator Author

WDYT @krzysztofzablocki?

Looking back at this, we can think a little differently about this since lib_internalSwiftSyntaxParser is statically linked so as long as we don't want to leverage any Swift 5.6 language features in the codebase at this moment, it shouldn't be an issue.

@krzysztofzablocki
Copy link
Owner

krzysztofzablocki commented Apr 5, 2022

it looks ok to me, thanks @liamnichols 🙇

@krzysztofzablocki krzysztofzablocki merged commit fa3b01b into krzysztofzablocki:master Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants