Skip to content

Dynamically determine the swift compiler version. #8707

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

Merged

Conversation

dschaefer2
Copy link
Member

Prebuilts for macros and the automated downloading of SwiftSDKs need to know the version of the compiler so we can fetch compatible binaries. The swiftc compiler has a --print-target-info options which dumps out a JSON structure that contains the compilerVersion. We already use info in this structure to determine the hostTriple for the UserToolchain.

This adds the swiftCompilerVersion to UserToolchain that uses a couple of regex's to pull out the Swift compiler version. This is then used by the prebuilts feature instead of our current hardcodeing of the swift toolchain version.

This also turns the prebuilts feature on by default which was supposed to be done in the last update.

Prebuilts for macros and the automated downloading of SwiftSDKs
need to know the version of the compiler so we can fetch
compatible binaries. The swiftc compiler has a --print-target-info
options which dumps out a JSON structure that contains the
compilerVersion. We already use info in this structure to
determine the hostTriple for the UserToolchain.

This adds the swiftCompilerVersion to UserToolchain that uses
a couple of regex's to pull out the Swift compiler version.
This is then used by the prebuilts feature instead of our current
hardcodeing of the swift toolchain version.

This also turns the prebuilts feature on by default which was
supposed to be done in the last update.
@dschaefer2
Copy link
Member Author

@swift-ci please test

return nil
}

// Extract the swift version using regex from the description if available
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure what you have captures the necessary variations, but here is what SwiftBuild is doing for the record: https://github.com/swiftlang/swift-build/blob/8e71bde5ac572174bc7e65f505abf3559bf05455/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift#L3607

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm about to put a patch up for swift-build. It's way too specific right now 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

All the mocks failed. Another commit incoming.

The mocks we use in the tests need to be able to provide their
own swift version since the swift compiler path is usually
faked out.
@dschaefer2 dschaefer2 enabled auto-merge (squash) May 22, 2025 02:58
@dschaefer2
Copy link
Member Author

@swift-ci please test

@dschaefer2
Copy link
Member Author

@swift-ci please test windows

@dschaefer2 dschaefer2 merged commit 275b91b into swiftlang:release/6.2 May 22, 2025
6 checks passed
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