-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Enable a more portable binary on macOS - Approach 1 #476
Enable a more portable binary on macOS - Approach 1 #476
Conversation
…nternalSwiftSyntaxParser regardless of compiler version
…e to work around spm bugs
@ileitch, please could you give this approval to run?
I'll add some more details shortly, but the added dependency to StaticSwiftSyntaxParser is hosted as a gist temporarily here: https://gist.github.com/liamnichols/92f8fdcf2864d0fd1619a18828acafb8 |
Sorry, it looks like I had to change the swift-tools-version and bump it to 5.3 in order to be able to declare a Please re-approve the workflow again 🙈 I guess this has to happen until I merge something so sorry if it fails again 😬 |
d5d87ac
to
bb33106
Compare
…yntaxParser on macOS.
bb33106
to
124ba30
Compare
Ok, I underestimated the amount of backwards/linux compatibility in the project and what that meant here 😄 Using StaticInternalSwiftSyntax parser is not possible on Linux, so we should stick with using SwiftSyntax regularly. In this change, I have done the following:
Please could you re-run the checks 🙏 I only have my hands on an M1 Mac now so I can't install older versions of Xcode and I don't have Docker setup to test Swift on Linux locally 😓 It should be good though 👍 |
This is awesome work, Liam! I will hopefully have some time to fully digest this on the weekend. I've added you as a collaborator so that I'm not blocking you on these checks 😄 . |
efbe514
to
45eff87
Compare
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.
Besides the caching issues solved in #479, the checks are good now and this is working 👍
I've left an inline comment about the approach for using StaticInternalSwiftSyntaxParser since there is a secondary alternative to the one I've used here 🙇
name: "StaticSwiftSyntaxParser", | ||
url: "https://gist.github.com/liamnichols/92f8fdcf2864d0fd1619a18828acafb8.git", | ||
.branch("main") |
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.
Ok, so recap on this.. I've had to move this out of Package.swift into a dedicated dependency because using .binaryTarget
in Package.swift currently breaks swift package describe
, which the tests rely on. SR-15243 (and SR-15065 when working around things with a local binary target).
If you'd be happy with this change and want to proceed, I'd recommend that you push the gist up to it's own repository under the peripheryapp org, then tag it with something like 5.6
so we can do this:
name: "StaticSwiftSyntaxParser", | |
url: "https://gist.github.com/liamnichols/92f8fdcf2864d0fd1619a18828acafb8.git", | |
.branch("main") | |
name: "StaticSwiftSyntaxParser", | |
url: "https://github.com/peripheryapp/static-swift-syntax-parser.git", | |
.exact("5.6") |
Another alternative that I had considered was to just fork https://github.com/apple/swift-syntax entirely and branch off 0.50600.1 and tweak the original Package.swift so that it uses StaticInternalSwiftSyntaxParser instead of the dylib. We'd then be able to update line 5 to something like this:
#if os(macOS) && compiler(>=5.5) || compiler(>=5.6)
- let swiftSyntaxVersion: Package.Dependency.Requirement = .exact("0.50600.1")
+ let swiftSyntaxVersion: Package.Dependency.Requirement = .exact("0.50600.1-static")
#elseif compiler(>=5.5)
let swiftSyntaxVersion: Package.Dependency.Requirement = .exact("0.50500.0")
As well as a few other tweaks
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.
I tried this out in #480
Closing this in favour of #480 |
Background
To make the
periphery
binary more portable on macOS, we want to have the lib_internalSwiftSyntaxParser library statically linked into the binary instead of having to link to a dylib version somewhere on the system.Approach 1
The main problem I'm trying to work around in these solutions is that I can't use binary targets in this Package.swift since it breaks
swift package describe
(SR-15243 and SR-15065).In this approach, I achieve that by extracting things out into a small placeholder-type package (StaticSwiftSyntaxParser) that declares the binary target and the dependency on swift-syntax's SwiftSyntaxParser library for the 5.6 version. This doesn't support 5.5, although it technically could but its just a little confusing because the SwiftSyntaxParser target was only added to swift-syntax in 5.6.
I feel like this approach is a little hackier than the second approach for a couple of reasons: