Skip to content

WIP: Add linkage of SwiftSyntax, to set the stage for future PRs that need it. #3669

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed

Conversation

abertelrud
Copy link
Contributor

The way in which this is done is based on #3034 but it's possible we'll need to tweak it. It's not great to only get the dependency in 5.5 or later but there might not be much to do about that if the compiler ABI changed.

The idea here is to shake out the issues around this separately, so that the PRs that need SwiftSyntax can focus on just their changes.

@abertelrud abertelrud marked this pull request as draft August 16, 2021 20:01
@tomerd
Copy link
Contributor

tomerd commented Aug 16, 2021

cc @owenv

@@ -33,6 +33,10 @@ let swiftPMDataModelProduct = (
]
)

#if compiler(>=5.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just require 5.5 for SwiftPM?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did, it would allow dropping some of the conditional compilation in the manifest, but some would still be necessary elsewhere to account for SwiftSyntax being missing from the first stage cmake build when bootstrapping. It's probably still worth doing so long as it doesn't interfere with SourceKit-LSP (which currently has a minimum of 5.3).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of the toolchain CI is still using an older Swift version, so that might be problematic. But it would be great to start being able to rely on synthesized Codable of enums in particular, and that requires 5.5.

@@ -33,6 +33,10 @@ let swiftPMDataModelProduct = (
]
)

#if compiler(>=5.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did, it would allow dropping some of the conditional compilation in the manifest, but some would still be necessary elsewhere to account for SwiftSyntax being missing from the first stage cmake build when bootstrapping. It's probably still worth doing so long as it doesn't interfere with SourceKit-LSP (which currently has a minimum of 5.3).

@abertelrud abertelrud force-pushed the eng/link-against-swiftsyntax branch from 55459b8 to 4001857 Compare August 18, 2021 22:26
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

Package.swift Outdated
// should compile with any 5.5 compiler, it will only be functional when built
// with a toolchain that has a compatible parser library.
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [.package(url: "https://github.com/apple/swift-syntax.git", .branch("release/5.5"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long run, I think it would be better to target main/relatedDependenciesBranch here. That should ensure that the smoke-testing bot will always use a compatible parser lib and SwiftSyntax, which IMO is the most important configuration to always run tests in. For a self-hosted build, I think it's ok to assume the libraries will sometimes be incompatible and skip the test if so, since that config isn't used for distribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — I wasn't able to get that to work with being able to use any version of Xcode to work on SwiftPM at desktop unfortunately (as the newest Xcode (13.0) has Swift 5.5). So it's not just the self-hosted tests, it's also being able to run the tests locally, where it's less desirable to skip them.

@abertelrud
Copy link
Contributor Author

I guess the:

/home/buildnode/jenkins/workspace/swift-package-manager-self-hosted-Linux-smoke-test/branch-main/swiftpm/Tests/PackageSyntaxTests/PackageSyntaxTest.swift:19: error: PackageSyntaxTests.testDoingSomethingWithSwiftSyntax : XCTAssertEqual threw error "The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntax"

is coming from using the release/5.5 branch of SwiftSyntax rather than main. Looks like I do need to make the tests conditional (or possibly make the version of SwiftSyntax being used conditional on the exterior toolchain with which it's being built).

@owenv
Copy link
Contributor

owenv commented Aug 25, 2021

I've been thinking about this some more the past couple days and had a horrible hacky idea that might nonetheless unblock this in the short term. Right now, it looks like macOS is the only platform where we can't create a working executable/test bundle with certain toolchains. Maybe we could provide a binary target (to force dynamic linking) conditionalized to macOS which is ABI compatible with the parser library and has the same name. If it is able to dlopen the parser library, it would just forward all of the calls, and otherwise it would return an incompatible version hash, and tests would fail but we'd still produce a working executable. Running the tests locally would still require downloading a compatible toolchain, but I think it's fine to require that if somebody is going to modify a SwiftSyntax-based feature.

@abertelrud
Copy link
Contributor Author

I've been thinking about this some more the past couple days and had a horrible hacky idea that might nonetheless unblock this in the short term. Right now, it looks like macOS is the only platform where we can't create a working executable/test bundle with certain toolchains. Maybe we could provide a binary target (to force dynamic linking) conditionalized to macOS which is ABI compatible with the parser library and has the same name. If it is able to dlopen the parser library, it would just forward all of the calls, and otherwise it would return an incompatible version hash, and tests would fail but we'd still produce a working executable. Running the tests locally would still require downloading a compatible toolchain, but I think it's fine to require that if somebody is going to modify a SwiftSyntax-based feature.

@owenv that's pretty clever, and would require considerably less lead time than extending the binary target format to allow SwiftSyntax to deliver the real binary as a plain library on all platforms. I guess then it would come down to how often that shim would have to be revved, as the ABI evolves. I guess SwiftPM is in control of that since it would determine when to depend on a new version of SwiftSyntax.

This new binary target would be in SwiftPM itself, and not SwiftSyntax, right?

@tomerd tomerd added the WIP Work in progress label Aug 30, 2021
… need it. The way in which this is done is based on swiftlang#3034 but it's possible we'll need to tweak it.  It's not great to only get the dependency in 5.5 or later but there might not be much to do about that if the compiler ABI changed.
@abertelrud abertelrud force-pushed the eng/link-against-swiftsyntax branch from 4001857 to 416e69f Compare September 6, 2021 18:40
@abertelrud abertelrud added next waiting for next merge window and removed DO NOT MERGE labels Apr 25, 2022
@tomerd
Copy link
Contributor

tomerd commented Oct 28, 2022

@abertelrud I think this can be closed with @neonichu work to bring in the new parser?

@tomerd tomerd closed this Dec 21, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
next waiting for next merge window WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants