This year, I started an effort to look at generating Swift SDKs for various platforms for the purpose of cross-compiling from a macOS or Linux host to a different distribution or even architecture.
The idea is to use the swift-sdk-generator to generate Swift SDKs for each Linux distribution for a given Swift version from a CI. I started a repo for this effort here:
However, the more I think about it, the more it seems obvious. What if we could just automatically generate Swift SDKs for each version of Linux that is supported and host them on the swift.org download page? We already have the Static Linux SDK available:
Not everyone can use or wants to use the Static Linux SDK due to library incompatibility or binary size. So, if an official CI could be setup to generate Swift SDKs for each Linux distribution and architecture supported, imagine if those could be just as easy to install from swift.org. For example, to install a Swift SDK to cross-compile to a Ubuntu 22.04 Jammy target on aarch64:
swift sdk install https://download.swift.org/swift-6.0.3-release/swift-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_ubuntu_jammy_aarch64.artifactbundle.tar.gz
Ideally this would work on any macOS or Linux host as long as the exact same version of Swift is installed. A developer could grab this and immediately start cross-compiling their app:
swift build --swift-sdk 6.0.3-RELEASE_ubuntu_jammy_aarch64
So my proposal is to:
- Setup an official swiftlang CI to use the swift-sdk-generator to create Swift SDKs for each version of Linux supported, for each version of Swift. This could even generate Swift SDKs for development and 6.1 snapshots as well.
- Host the Swift SDK artifacts on swift.org somewhere. I am not sure where they could be placed since they are SDKs for the target rather than the host, but I'm sure it could be figured out.
- Generate & host .deb and .rpm artifacts that can be used to install just the Swift runtime to the target. So, for a Ubuntu or Debian host, you'd download a .deb file and install it:
sudo dpkg -i ./swift-runtime-6.0.3-ubuntu-jammy.deb
. Or, for a RHEL/Fedora/Amazon Linux 2 target, you install the .rpm:sudo rpm --install ./swift-runtime-6.0.3-rhel-ubi9.rpm
.
What do we think about this idea? I plan on continuing to work on my repo to help find things that can be improved in the swift-sdk-generator. However, I would love to see this become official and I would also not mind helping to create this CI, if we think it's a good idea to pursue for Swift!