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 Swift SDKs #1191

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

kabiroberai
Copy link

@kabiroberai kabiroberai commented Nov 2, 2024

This PR adds support for Swift SDKs when using the SwiftPM build system, as defined by SE-0387. These are already supported by SourceKit LSP, so adding support here is primarily a matter of plumbing the swift.swiftSDK parameter along to the swiftPM.swiftSDK field of SourceKit LSP's startup options.

Additionally, with swiftlang/swift-package-manager#6828 it is now possible to select Darwin triples as Swift SDKs on macOS — that is, you can build for iOS with swift build --swift-sdk arm64-apple-ios and so on. This support also applies to SourceKit LSP, and so we can update the "Select Target Platform" action to pick a Swift SDK instead.

Open questions

  • This PR mostly obsoletes the old swift.SDK parameter, but I haven't removed it yet because 1) Swift SDK support only works with SwiftPM right now and 2) I'm not sure whether removing swift.SDK would break the Windows-specific use cases for that parameter. Removing it would clean up a lot of code though. Would this be reasonable to do?
  • Support for Darwin SDKs as Swift SDKs is on main and has landed in time for the 6.1 release cut, but doesn't exist in 6.0. Is there a recommended pattern we can use for feature detection to only surface the "Select Target Platform" command if the compiler is new enough?

TODO:

  • Tests

@stevapple
Copy link
Contributor

We need a swiftlang/swift-package-manager#6828 like solution on Windows before we can get rid of swift.SDK

@award999
Copy link
Contributor

award999 commented Nov 5, 2024

@kabiroberai can you rebase please? We recently moved to GitHub actions to verify PRs

@kabiroberai
Copy link
Author

@award999 done!

@kabiroberai
Copy link
Author

Heya @award999, any updates on this? CI is green now ✅

@daveyc123
Copy link

daveyc123 commented Nov 13, 2024

Thanks for the contribution @kabiroberai!

In answer to your questions:

This PR mostly obsoletes the old swift.SDK parameter, but I haven't removed it yet because 1) Swift SDK support only works with SwiftPM right now and 2) I'm not sure whether removing swift.SDK would break the Windows-specific use cases for that parameter. Removing it would clean up a lot of code though. Would this be reasonable to do?

As long as SwiftPM continues to support the --sdk option, the old swift.SDK parameter should stick around.

Support for Darwin SDKs as Swift SDKs is on main and has landed in time for the 6.1 release cut, but doesn't exist in 6.0. Is there a recommended pattern we can use for feature detection to only surface the "Select Target Platform" command if the compiler is new enough?

The extension typically follows the pattern that the command is always enabled. If the command can't run, it presents an errorMessage. This allows presenting to the user the reason why the command couldn't be run (as opposed to it just not being there). For example "You don't have an SDK selected" vs. "This feature is only supported on Swift 6.0 and higher".

An example of this behaviour can be found at

if (!toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {

@kabiroberai
Copy link
Author

kabiroberai commented Nov 16, 2024

ty folks! since we're keeping the SDK parameter around (and I realized SourceKit LSP's swiftSDK option only works with the SwiftPM build system) I've removed the changes to switchPlatform from the scope of this PR. This PR is purely additive now, and we can always lean more on Swift SDKs if/when they're able to fully subsume the traditional --sdk flag.

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.

4 participants