swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.19k stars 405 forks source link

`600.0.0-prerelease-2024-07-24` fails to build on macOS 12 with Swift 5.10 #2784

Closed SimplyDanny closed 1 month ago

SimplyDanny commented 1 month ago

Description

The latest release of SwiftLint (0.56.1) incorporates SwiftSyntax 600.0.0-prerelease-2024-07-24 as a dependency. Supported are versions back to macOS 12. While everything builds fine for Homebrew on macOS 14 and 13 with Swift 5.10, the build fails on macOS 12 on the changes introduced by #2742.

Swift 5.10 is installed via Homebrew on macOS 13 and 12 since there is no Xcode version available on these platforms that ships with Swift 5.10 included.

I don't know how this is all related. Would be glad if you could shine some light on the issue and guide me to a fix.

Steps to Reproduce

My assumption is that any library depending on this SwiftSyntax version and built on macOS 12 would fail to build. I actually try to do that in SwiftLint on plain (non-Homebrew) machines with the same result (macOS 13 succeeds; macOS 12 fails).

ahoppen commented 1 month ago

Synced to Apple’s issue tracker as rdar://133401576

ahoppen commented 1 month ago

Are you trying to build swift-syntax with a Swift 5.7 compiler on macOS 12? swift-syntax requires a Swift 5.8 compiler to build since https://github.com/swiftlang/swift-syntax/pull/2742, the swift-tools-version just didn’t get updated.

Couldn’t you build with a newer Swift version and backdeploy to macOS 12?

SimplyDanny commented 1 month ago

Are you trying to build swift-syntax with a Swift 5.7 compiler on macOS 12? swift-syntax requires a Swift 5.8 compiler to build since https://github.com/swiftlang/swift-syntax/pull/2742, the swift-tools-version just didn’t get updated.

SwiftLint specifies // swift-tools-version:5.9. So if a Swift 5.7 compiler was actually used, it'd have refused to start building right from the beginning, wouldn't it?

Couldn’t you build with a newer Swift version and backdeploy to macOS 12?

I think this is not how Homebrew works. Everyone should be able to build things from source given a formula that defines the build steps. Downloading pre-built binaries is just a shortcut as a convenience for the impatient user (99% of users). SwiftLint provides binaries that should be runnable on older macOS versions, but not for Homebrew.

SimplyDanny commented 1 month ago

Seems like while a Swift 5.10 compiler is used, the SDK is still read from the Xcode installation. The outdated standard library would explain the compile errors. I'll report back ...

SimplyDanny commented 1 month ago

Seems like while a Swift 5.10 compiler is used, the SDK is still read from the Xcode installation. The outdated standard library would explain the compile errors. I'll report back ...

As the SDK is shipped with Xcode only and OS-dependent I won't get this to work at all if the new code now calls API the SDK doesn't provide. Right?

What confuses me is that the reference for [UnsafeMutableBufferPointer.deinitialize](https://developer.apple.com/documentation/swift/unsafemutablebufferpointer/deinitialize()) claims "macOS 10.10+". How does that relate?

ahoppen commented 1 month ago

The relevant variable here should be the SDK installed in the Xcode being used, not the host OS. Which Xcode are you using on macOS 12? Or, alternatively, which Xcode are you using to get a Swift 5.9+ compiler?

SimplyDanny commented 1 month ago

The relevant variable here should be the SDK installed in the Xcode being used, not the host OS. Which Xcode are you using on macOS 12? Or, alternatively, which Xcode are you using to get a Swift 5.9+ compiler?

It's Xcode 14.2 installed on the host. The Swift 5.10 toolchain is installed via Homebrew as well. It was built with Xcode 13.3 as far as I can see.

ahoppen commented 1 month ago

The Swift 5.10 toolchain is installed via Homebrew as well.

Just to be clear: By Swift 5.10 toolchain, you refer to a Swift open source toolchain from swift.org?

It was built with Xcode 13.3 as far as I can see.

And by this you mean that the 5.10 toolchain from swift.org was built using Xcode 13.3 to your best knowledge?

SimplyDanny commented 1 month ago

I should have made this clearer before. Sorry for that. Homebrew provides an own Swift package. So you can basically install it via brew install swift. It's not an official toolchain from swift.org but a manual build. In their formula, Xcode 13.3 is specified as a build dependency.

SimplyDanny commented 1 month ago

Seems like I got it now. The only requirement is to build the Swift 6 branch with a Swift 5.8+ compiler and a matching standard library.

The toolchain provided by Homebrew apparently misses some components compared to the regular toolchains. However, this needs to be sorted with the Homebrew folks, not here in this thread.

What's somehow missing is an overview about the API provided by the standard library with respect to the Swift versions that support it. Can that be found somewhere? The only documentation for the standard library is provided by Apple. swift.org even links there, but Apple's website only allows to show differences between the latest Xcode releases/betas. No mention of Swift versions at all. This would be a welcome feature.

SimplyDanny commented 1 month ago

I put up #2801 to increase the tool version.

Thank you very much for getting me on the right track with this issue. 🙏

vdhamer commented 3 weeks ago

Homebrew download of swift line 0.56..1 for Mac is available. Thank to both parties that investigated and fixed this.