Skip to content

Add new options that control whether host toolchain is included #165

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

xtremekforever
Copy link
Contributor

@xtremekforever xtremekforever commented Dec 20, 2024

I'm fully prepared for this to be torn apart, but this is hopefully a good "first PR" for this configuration. @euanh @MaxDesiatov

This adds a new --no-include-host-toolchain flag to the make-linux-sdk sub-command, making it possible to generate an SDK for x86_64 or aarch64 with only the target sysroot and Swift libraries, like this:

# x86_64
swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --target x86_64-unknown-linux-gnu --no-include-host-toolchain
# aarch64
swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --target aarch64-unknown-linux-gnu --no-include-host-toolchain

I tested the generated SDKs on both Ubuntu 22.04 and macOS 15 and they work just fine.

Ubuntu x86_64 -> aarch64:

> swift build --swift-sdk 6.0.3-RELEASE_ubuntu_jammy_aarch64
Building for debugging...
warning: Could not read SDKSettings.json for SDK at: ~/.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_jammy_aarch64.artifactbundle/6.0.3-RELEASE_ubuntu_jammy_aarch64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk
[485/485] Linking ConsumePublishServices
Build complete! (25.37s)

macOS arm64 -> x86_64:

>  swift build --swift-sdk 6.0.3-RELEASE_ubuntu_jammy_x86_64
Building for debugging...
warning: Could not read SDKSettings.json for SDK at: /Users/xtremek/Library/org.swift.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_jammy_x86_64.artifactbundle/6.0.3-RELEASE_ubuntu_jammy_x86_64/x86_64-unknown-linux-gnu/ubuntu-jammy.sdk
<unknown>:0: warning: libc not found for 'x86_64-unknown-linux-gnu'; C stdlib may be unavailable
[1171/1171] Linking ConsumePublishServices
Build complete! (39.43s)

Also, is there a need/desire to add some unit testing for this flag?

 - So we end up with no swift.xctoolchain so that the toolchain installed on the host is used instead.
 - Also don't download host LLVM if excluding host toolchain
 - This way since 5.9 and 5.10 require the supportedTriples in info.json, they will still work, and all supported host versions of Swift can compile for the SDK.
@xtremekforever
Copy link
Contributor Author

xtremekforever commented Dec 29, 2024

Update: since both 5.9 and 5.10 require the supportedTriples to be included in info.json, I've opted to add all the supported host triples when building the SDK with --no-include-host-toolchain:

          "supportedTriples" : [
            "x86_64-unknown-linux-gnu",
            "aarch64-unknown-linux-gnu",
            "x86_64-apple-macos",
            "arm64-apple-macos"
          ],

Then, either Linux x86_64/aarch64 or macOS x86_64/arm64 hosts can cross compile with the SDK.

Since the SDK doesn't contain the Swift toolchain, though, the open source Swift toolchain is required to be used on macOS for it to compile. I think this is also the case with the Linux Static SDK.

@euanh @MaxDesiatov please have a look here and see what you think!

@xtremekforever xtremekforever marked this pull request as ready for review December 29, 2024 20:28
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Jan 2, 2025
@MaxDesiatov MaxDesiatov changed the title Add a new --no-host-toolchain flag that generates an SDK without the host Swift toolchain Add new options that control whether host toolchain is included Jan 2, 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.

Phrasing nit: we should not call these "SDK", but use "Swift SDK" wording instead, since these terms are separate from each other. In the Swift context, plain "SDK" is an Xcode-specific term, where its Darwin SDKs have a distinct file system layout that Xcode build system can consume. "Swift SDK" is a SwiftPM feature, unrelated to plain "SDK"s for Darwin. These are different features in different products and are not interchangeable with each other.

It's unfortunate though that swift.org website doesn't make this distinction, but that would have to be resolved with swift.org website maintainers.

 - Pass --no-host-include-toolchain to build the Swift SDK without the host toolchain.
…nd 5.10

 - Both of these versions require supportedTriples to be set and populated, but 6.0 and later can simply exclude the field for supporting all hosts.
@MaxDesiatov
Copy link
Contributor

Also, is there a need/desire to add some unit testing for this flag?

Yes please, that would be much appreciated.

 - Instead set rootPath to nil in Toolset if toolchain is preinstalled.
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

Thanks!

@xtremekforever
Copy link
Contributor Author

xtremekforever commented Jan 5, 2025

Also, is there a need/desire to add some unit testing for this flag?

Yes please, that would be much appreciated.

@MaxDesiatov I added tests that check the following pieces of functionality in LinuxRecipe that are affected by the .preinstalled host Swift enum:

  • Toolset options
  • Downloadable artifacts
  • Host triples (supportedTriples in info.json)

I did not add tests for all of the functionality of LinuxRecipe, but I think that can be added later if desired.

@kateinoigakukun
Copy link
Member

@swift-ci test

@@ -27,7 +27,6 @@ extension SwiftSDKGenerator {
let toolsetJSONPath = pathsConfiguration.swiftSDKRootPath.appending("toolset.json")

var relativeToolchainBinDir = pathsConfiguration.toolchainBinDirPath

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary newline that only adds to the diff as an unrelated change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

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.

LGTM modulo a super minor formatting nit

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@xtremekforever
Copy link
Contributor Author

All good to merge since everything's in there?

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 6, 2025

I wonder if @euanh would have any feedback, since he contributed to the Linux generator a lot recently and also enabled e2e tests for it?

@euanh
Copy link
Contributor

euanh commented Jan 7, 2025

I've run the EndToEnd tests. They didn't find any regressions (they take a while):

SWIFT_SDK_GENERATOR_RUN_SLOW_TESTS=1 swift test --disable-swift-testing --filter EndToEndTests
...
Test Suite 'Swift60_UbuntuEndToEndTests' passed at 2025-01-07 10:29:19.900.
         Executed 4 tests, with 0 failures (0 unexpected) in 447.902 (447.902) seconds
Test Suite 'swift-sdk-generatorPackageTests.xctest' passed at 2025-01-07 10:29:19.900.
         Executed 18 tests, with 0 failures (0 unexpected) in 2034.483 (2034.484) seconds
Test Suite 'Selected tests' passed at 2025-01-07 10:29:19.900.
         Executed 18 tests, with 0 failures (0 unexpected) in 2034.483 (2034.485) seconds

but requires exactly the same version of the swift.org toolchain to be installed for it to work.
"""
)
var includeHostToolchain: Bool = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about a request coming this late, just noticed that --no-include-host-toolchain reads quite weird to me? Although I'm not a native English speaker, so take this concern with a grain of salt. If you agree that --no-host-toolchain reads better, let's use that shorter wording and I'm ready to merge immediately after that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, --no-host-toolchain sounds better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:

  --host-toolchain/--no-host-toolchain
                          Whether or not to include the host toolchain in the Swift SDK.
                          If the host toolchain is not included, this makes the Swift SDK compatible with any host, but requires exactly the same version of the
                          swift.org toolchain to be installed for it to work. (default: --host-toolchain)

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) January 7, 2025 14:22
@MaxDesiatov MaxDesiatov merged commit f63f812 into swiftlang:main Jan 7, 2025
2 of 3 checks passed
@xtremekforever xtremekforever deleted the #164-no-host-toolchain-option branch January 7, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants