Swift 6 in Linux containers

This Linux + static binaries + containers stuff seems aimed at the development segment served by Go, but on trying to get started with it, it looks like things aren't ready. I came here expecting to find a community positively exploding with excited activity. All this static Linux building stuff is an obvious win with containers. I cannot possibly be the first to realize this truth.

What I found instead was a forum category so sleepy it has 2020-era topics on the front page, ones speaking of "CentOS 7", a topic that would be dead of natural causes by now even if Red Hat hadn't gone and actively killed it outright.

I came here after failing to find an official Swift 6 container. There's only 5.x stuff there, lacking the static build support I expect from a Go-killer.

I was briefly encouraged to find the much more up-to-date Red Hat UBI9 build of Swift 6 release, but I was then scared off when I found that it isn't a container but instead a tarball I'm meant to unpack at /usr level over the top of my development system. Seriously?

At the same time, the mere availability of this hints that someone has created a ubi9 based container for this. Where do I get that, rather than this docker export …stuff… tarball? Am I meant to repack this tarball as a container myself, or wait for someone on a releng team to get around to pushing the UBI9 + Swift 6 image to Docker Hub, or…

Swift 6 is under development but there are already nightly Docker images for some platforms, for example for RHEL / AL2 / Ubuntu: https://hub.docker.com/r/swiftlang/swift/tags

Yes, that's my mistake: going to the official Docker "library" ("_") images instead of finding the upstream project ("swiftlang") images. This is much better. Thank you.

1 Like

Sigh…

$ podman run --cap-add sys_ptrace -it --rm swift:nightly-rhel-ubi9 sh
sh-5.1# swift sdk install https://download.swift.org/development/static-sdk/swift-DEVELOPMENT-SNAPSHOT-2024-06-06-a/swift-DEVELOPMENT-SNAPSHOT-2024-06-06-a_static-linux-0.0.1.artifactbundle.tar.gz
…
Swift SDK bundle at `https://download.swift.org/development/static-sdk/swift-DEVELOPMENT-SNAPSHOT-2024-06-06-a/swift-DEVELOPMENT-SNAPSHOT-2024-06-06-a_static-linux-0.0.1.artifactbundle.tar.gz` is assumed to be an archive, unpacking...
Error: 
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
sh-5.1# find ~/.swiftpm
/root/.swiftpm
/root/.swiftpm/swift-sdks

Not ready… :pensive:

Any reason you tried to use an older SDK swift-DEVELOPMENT-SNAPSHOT-2024-06-06-a instead of the latest SDK build shown at the bottom of this page? The instructions clearly say you should use the "corresponding" tag.

Yep, this new standalone linux SDK was just released as part of the 6.0 development snapshot toolchains to get it ready for the 6.0 release in a couple months, by people like you trying it out and reporting issues. Once you install and use it, it works great in my testing so far.

The instructions clearly say you should use the "corresponding" tag.

Okay, yes, you caught me not reading every single word on the page. :roll_eyes:

What I did instead is copy the command given a few lines below what you point out. Given that the 2024-06-06 tarball doesn't work [any more?] but later ones do, someone should update that page to give a working URL in the command example.

EDIT: The current -22 version installs but then doesn't work:

sh-5.1# swift sdk install https://download.swift.org/swift-6.0-branch/static-sdk/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a_static-linux-0.0.1.artifactbundle.tar.gz
Downloading a Swift SDK bundle…
…successfully installed as…
sh-5.1# mkdir hello
sh-5.1# cd hello
sh-5.1# swift package init --type executable
sh-5.1# swift build --swift-sdk x86_64-swift-linux-musl
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: compiled module was created by an older version of the compiler; rebuild 'Swift' and try again: /root/.swiftpm/swift-sdks/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a_static-linux-0.0.1.artifactbundle/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/Swift.swiftmodule/x86_64-swift-linux-musl.swiftmodule

I speculatively tried hand-hacking the date to -29 (today's date) and -28 (yesterday's, presumably what was current when the CI bot produced the UBI9 container I'm testing with) and both gave errors.

Since these appear to be full-fat (~2GB) development containers and not stripped-down production base layer containers, I propose that the matching static build SDK be preinstalled.

The issue is you're trying to use the swift:nightly-rhel-ubi9 Docker you mentioned above, which packages the next 6.1 trunk toolchain builds, with the latest 6.0 linux SDK, which it notes it cannot handle, error: compiled module was created by an older version of the compiler.

We could probably do a better job of explaining the Swift versioning scheme to newcomers like you. You'll want to use the latest main/trunk SDK snapshot instead.

That won't work, as the CI doesn't produce 6.0/6.1 snapshot tags every day.

That's a good idea. You're right that the initial install process is not so great here, but a lot of work has gone into developing this new linux SDK, so hopefully we can add the finishing UX touches before the Swift 6 release.

Keep reporting any problems you see, I'm sure people would like to fix them.

3 Likes