Skip to content

Add support for building Swift SDKs for armv7 with target Swift toolchain or docker container #170

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
merged 10 commits into from
Feb 11, 2025

Conversation

xtremekforever
Copy link
Contributor

This would implement #65. Although there is no official support for armv7 in Swift yet, this opens the door for being able to generate Swift SDKs for cross compilation to armv7 given you have build artifacts to give it. In my case, I can grab some that I built from my swift-armv7 repo, download and extract, then run the generator like this:

$ swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --target armv7-unknown-linux-gnueabihf --target-swift-package-path ~/Downloads/swift-6.0.3-RELEASE-ubuntu-jammy-armv7-install
...
All done! Install the newly generated SDK with this command:
swift experimental-sdk install ~/swift-sdk-generator/Bundles/6.0.3-RELEASE_ubuntu_jammy_armv7.artifactbundle

After that, use the newly installed SDK when building with this command:
swift build --experimental-swift-sdk 6.0.3-RELEASE_ubuntu_jammy_armv7

And, this generates a working Swift SDK that I can use to cross compile anything, like a Hummingbird app:

$ swift build --swift-sdk 6.0.3-RELEASE_ubuntu_jammy_armv7
warning: 'swift-algorithms': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    ~/hummingbird-examples/hello/.build/checkouts/swift-algorithms/Sources/Algorithms/Documentation.docc
Building for debugging...
[948/948] Linking App
Build complete! (35.16s)

So, I think that it could be reasonable to add this support to the generator now. It's something I will use myself, but also when official support for armv7 lands for Swift, it'll be ready ;)

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov requested a review from euanh January 21, 2025 08:09
@xtremekforever
Copy link
Contributor Author

Right now if I do something like this:

$ swift run swift-sdk-generator make-linux-sdk --swift-version 6.0.3-RELEASE --host x86_64-unknown-linux-gnu --target armv7-unknown-linux-gnueabihf --linu
x-distribution-name rhel --with-docker

I just get a Docker error, which of course means there is no container available for rhel-ubi9 for armv7:

Launching a Docker container to copy Swift SDK for the target triple from it...
Error: process exited non-zero: exit(125)

So perhaps this situation can be detected up front, and we can throw an error saying that RHEL UBI9 does not support armv7. What do you think @MaxDesiatov ?

@MaxDesiatov
Copy link
Contributor

So perhaps this situation can be detected up front, and we can throw an error saying that RHEL UBI9 does not support armv7. What do you think @MaxDesiatov ?

Yes, that's what I was referring to in the other thread. If we know that generation for other armv7 distributions can't possibly work and we can detect that early, we should log an error message. Or if it could possibly work, but we don't know for sure, then at least a warning message saying this codepath is not fully supported.

@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Jan 22, 2025
…ting to create a Swift SDK with rhel for armv7
@xtremekforever
Copy link
Contributor Author

xtremekforever commented Jan 24, 2025

@MaxDesiatov RHEL and Fedora do not support armv7 and there don't appear to be any plans to support it any more in the future:

So, I've opted to add a new .distributionDoesNotSupportArchitecture error to GeneratorError that is thrown if you try to create a Swift SDK for a rhel target with armv7 architecture:

Error: Target Linux distribution RHEL UBI9 does not support the target architecture: armv7

There really is no way this configuration would work unless someone in a corner of the galaxy is compiling and running RHEL for armv7 for some reason.

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

@xtremekforever
Copy link
Contributor Author

@euanh @kateinoigakukun do you guys have a minute to check out this PR this week? The changes are pretty minor I think, and work well as long as you've got build artifacts, so it could be good to have in the generator while I continue working on updating swiftlang/swift to be able to cross-compile for armv7.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov merged commit d4aba13 into swiftlang:main Feb 11, 2025
3 checks passed
@xtremekforever xtremekforever deleted the #65-support-armv7 branch February 11, 2025 12:22
euanh added a commit to euanh/swift-sdk-generator that referenced this pull request Feb 13, 2025
…sed SDK

PR swiftlang#177 was intended to skip unnecessary toolchain downloads, making it
possible to build a container-based SDK offline if all its requirements
had already been dowloaded.  The change was too broad and also broke
building package-based SDKs.

PR swiftlang#177 skips calling generator.downloadArtifacts() when building
an SDK without an embedded host toolchain (the default).   In
addition to downloading the host toolchain (and LLVM, if needed),
generator.downloadArtifacts() is also responsible for downloading
the target toolchain.  This is not needed when building a container-based
SDK but is required when building a package-based SDK, which combines
an SDK from swift.org with supporting libraries extracted from
Debian packages.

In fact, generator.downloadArtifacts() already avoids downloading
toolchains when building a container-based SDK without an embedded
toolchain.   The only network call which caused offline builds to
fail was an unconditional check for a suitable LLVM binary from
GitHub.

This PR restores the call to generator.downloadArtifacts() and only
makes the LLVM check if LLVM is in the list of required downloads.
This allows the EndToEnd tests to pass again (with PR swiftlang#170 temporarily
reverted because of issue swiftlang#181).
euanh added a commit that referenced this pull request Feb 14, 2025
…sed SDK (#182)

PR #177 was intended to skip unnecessary toolchain downloads, making it
possible to build a container-based SDK offline if all its requirements
had already been dowloaded.  The change was too broad and also broke
building package-based SDKs.

PR #177 skips calling generator.downloadArtifacts() when building
an SDK without an embedded host toolchain (the default).   In
addition to downloading the host toolchain (and LLVM, if needed),
generator.downloadArtifacts() is also responsible for downloading
the target toolchain.  This is not needed when building a container-based
SDK but is required when building a package-based SDK, which combines
an SDK from swift.org with supporting libraries extracted from
Debian packages.

In fact, generator.downloadArtifacts() already avoids downloading
toolchains when building a container-based SDK without an embedded
toolchain.   The only network call which caused offline builds to
fail was an unconditional check for a suitable LLVM binary from
GitHub.

This PR restores the call to generator.downloadArtifacts() and only
makes the LLVM check if LLVM is in the list of required downloads.
This allows the EndToEnd tests to pass again (with PR #170 temporarily
reverted because of issue #181).
euanh added a commit to euanh/swift-sdk-generator that referenced this pull request Feb 14, 2025
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