Skip to content

Allow omitting the target triple for swift sdk configure #8856

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

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

Conversation

marcprux
Copy link
Contributor

@marcprux marcprux commented Jun 21, 2025

You can now run swift sdk configure --sdk-root-path /some/sdk/root sdk-id without needing to specify the target triple

Motivation:

The Android SDK (swiftlang/swift#80788 (comment)) needs to have its sdkRootPath configured to point to an external NDK sysroot. But it contains many different target triples, like armv7-unknown-linux-androideabi33 and x86_64-unknown-linux-android29, all of which need to be configured to point to the same sysroot. Following on to #8687 and swiftlang/swift-evolution#2888, this PR enables running a single command to configure the entire SDK, like so:

swift run swift-sdk configure --sdk-root-path ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot swift-6.1-RELEASE-android-24-0.1

This will result in configurations being created for each of the target triples for the SDK ID.

% swift run swift-sdk configure --sdk-root-path ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot swift-6.1-RELEASE-android-24-0.1
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android25` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi33` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android26` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi35` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android31` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi29` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android32` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android34` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android27` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi25` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi26` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi24` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android33` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android35` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android29` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android32` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android25` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android24` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi30` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android26` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android33` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi32` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android35` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android34` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android31` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android28` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android27` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android24` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android30` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi28` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android28` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi27` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android30` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi34` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi31` were successfully updated: sdkRootPath.
info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android29` were successfully updated: sdkRootPath.

% ls ~/Library/org.swift.swiftpm/swift-sdks/configuration/
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android24.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android25.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android26.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android27.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android28.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android29.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android30.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android31.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android32.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android33.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android34.json
swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android35.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi24.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi25.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi26.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi27.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi28.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi29.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi30.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi31.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi32.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi33.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi34.json
swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi35.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android24.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android25.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android26.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android27.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android28.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android29.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android30.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android31.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android32.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android33.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android34.json
swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android35.json

% cat ~/Library/org.swift.swiftpm/swift-sdks/configuration/swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android31.json
{
  "sdkRootPath" : "/Users/marc/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot",
  "swiftResourcesPath" : "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/android-27c-sysroot/usr/lib/swift",
  "swiftStaticResourcesPath" : "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/android-27c-sysroot/usr/lib/swift_static-x86_64",
  "toolsetPaths" : [
    "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/swift-toolset.json"
  ]
}

In addition, this fixes #8584, where swift sdk configure with a specified target triple didn't work at all, and instead would configure some random target triple for the specified SDK.

Modifications:

Make the targetTriple flag for ConfigureSwiftSDK optional and, when nil, apply the command to all triples included in the specified SDK.

Result:

Fixes #8584 and enables configuring multiple target triples with a single swift sdk configure command.

@marcprux
Copy link
Contributor Author

CC @finagolfin, @etcwilde, @MaxDesiatov

@finagolfin
Copy link
Member

Seems good, I think the reviewers will ask for a test though. Running it through self-hosted CI to make sure the patch didn't break anything.

@finagolfin
Copy link
Member

@swift-ci test self hosted

@marcprux
Copy link
Contributor Author

I think the reviewers will ask for a test

There's no existing test support for the sdk configure command. I could probably implement something, but it would be a fairly major refactor, since much of the ConfigureSwiftSDK.run() logic would need to be relocated to somewhere more testable, like SwiftSDKConfigurationStore.

I'd be willing to undertake it if the reviewers want/need it.

@MaxDesiatov
Copy link
Contributor

I think the reviewers will ask for a test

There's no existing test support for the sdk configure command. I could probably implement something, but it would be a fairly major refactor, since much of the ConfigureSwiftSDK.run() logic would need to be relocated to somewhere more testable, like SwiftSDKConfigurationStore.

I'd be willing to undertake it if the reviewers want/need it.

Yes please!

@marcprux
Copy link
Contributor Author

OK, I'll work on implementing test support.

Are there any other common use cases for swift sdk configure, either existing or envisioned? I'd like to make sure my tests cover as many plausible scenarios as possible, and not just the Android SDK sysroot setup.

@marcprux marcprux marked this pull request as draft June 23, 2025 15:41
@MaxDesiatov
Copy link
Contributor

OK, I'll work on implementing test support.

Are there any other common use cases for swift sdk configure, either existing or envisioned? I'd like to make sure my tests cover as many plausible scenarios as possible, and not just the Android SDK sysroot setup.

Not at the moment, I've designed it almost exclusively to support out-of-tree sysroots like NDK 😅

@marcprux
Copy link
Contributor Author

I've added a SwiftSDKBundleTests.testConfigureSDKRootPath test, which is supported by moving the SDK configuration logic from the ConfigureSwiftSDK command to the SwiftSDKConfigurationStore. In doing so, I also centralized the config properties by making SwiftSDK.PathsConfiguration generic, so String and AbsolutePath variants will share the same structure; should new configuration properties ever need to be added in the future, it will be simpler to have them in this one place.

Lastly, I cleaned up some of the logic for the PathsConfiguration initializers which can accept an optional swiftSDKDirectory base directory and condensed it by eliminating the branch on nil to instead use the AbsolutePath initializer extension that accepts an optional relativeTo argument (which I had to relocate there anyway).

@marcprux marcprux marked this pull request as ready for review June 24, 2025 02:53
@finagolfin
Copy link
Member

@swift-ci test self hosted

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Thanks! Other than formatting nits (see CONTRIBUTING.md "Creating PRs" section, p. 7) and unnecessary use of public, I think that new and existing functions and types deserve more doc comments while we're at it.

@MaxDesiatov MaxDesiatov added needs documentation and removed needs tests This change needs test coverage labels Jun 24, 2025
@MaxDesiatov MaxDesiatov changed the title Allow omitting the target triple for swift sdk configure Allow omitting the target triple for swift sdk configure Jun 24, 2025
Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Thanks!

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

1 similar comment
@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@marcprux
Copy link
Contributor Author

@swift-ci test windows

I see that the Windows CI failed, but the link returns 404. Maybe the log expired? Can you run it again and I can take a look?

@MaxDesiatov
Copy link
Contributor

@swift-ci test self hosted windows

@marcprux
Copy link
Contributor Author

Windows error was:

11:51:14  C:\source\swiftpm\Tests\PackageModelTests\SwiftSDKBundleTests.swift:635: error: SwiftSDKBundleTests.testConfigureSDKRootPath : XCTAssertEqual failed: ("Optional("/some/sdk/root/path")") is not equal to ("Optional("\\some\\sdk\\root\\path")") - 

I fixed it in b155f05. Can I get another CI run?

@finagolfin
Copy link
Member

@swift-ci test self hosted windows

@marcprux
Copy link
Contributor Author

marcprux commented Jul 1, 2025

CI passed. Is there anything else preventing this PR from getting merged?

@MaxDesiatov
Copy link
Contributor

It needs a review from someone on the SwiftPM team.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swift sdk configure updates a random target triple rather than the specified one
3 participants