Running Swift on "Unsupported" Distributions

Hey Swifties,

In the past weeks I've played around quite a bit with Swift on different distributions (ones that are not "officially" supported, such as OpenSUSE, Fedora, Debian, Arch) and found that Swift actually works really great on all these as long as you pick the correct compatible flavor and install the needed dependencies. Maybe this can help others in the community when trying to figure out how to run Swift on their favorite Linux distribution.

In order to run the Swift SDK you need the correct packages. I also found the needed packages on the distributions that I tested since the naming wasn't quite the same and didn't match the install list from the Swift website, which is to be expected. For convenience I recorded them and they are available in the compatibility matrix below:

Linux Distro Compatible Swift Build Packages / Commands Additional Steps
OpenSUSE Leap, OpenSUSE Tumbleweed Amazon Linux 2 sudo zypper install binutils binutils-gold gcc git gzip glibc-static libbsd-devel libedit libedit-devel libicu-devel libstdc++-devel pkg-config python2 sqlite
CentOS Stream 8, AlmaLinux 8, RockyLinux 8 Amazon Linux 2 sudo dnf install binutils gcc git glibc-static gzip libbsd libcurl libedit libicu libstdc++-static libuuid libxml2 tar tzdata sqlite sudo dnf config-manager --set-enabled powertools
CentOS Stream 9, AlmaLinux 9, RockyLinux 9 RHEL 9 sudo dnf install binutils gcc git glibc-static gzip libbsd libcurl libedit libicu libstdc++-static libuuid libxml2 tar tzdata sqlite sudo dnf config-manager --set-enabled crb
Fedora 38-40 RHEL 9 sudo dnf install binutils gcc git glibc-static gzip libbsd libcurl libedit libicu libstdc++-static libuuid libxml2 tar tzdata sqlite Enable RPM Fusion
Ubuntu 23.04, 23.10, 24.04 Ubuntu 22.04 Swift.org - Linux Installation Options Install packages for Ubuntu 22.04
Linux Mint 21 Ubuntu 22.04 Swift.org - Linux Installation Options Install packages for Ubuntu 22.04
Debian 12 Ubuntu 22.04 sudo apt install binutils git gnupg2 libc6-dev libcurl4-openssl-dev libedit2 libgcc-12-dev libpython3.11 libsqlite3-0 libstdc++-12-dev libxml2-dev libz3-dev pkg-config tzdata unzip zlib1g-dev Install packages for Ubuntu 22.04
Arch Linux (Majaro, Garuda Linux, etc) RHEL 9 sudo pacman -Sy --needed git base-devel, git clone https://aur.archlinux.org/swift-bin.git, cd swift-bin && makepkg -si swift-bin swift-bin from AUR used since libcurses.so needs to be patched for Arch

In all this, I also found that the Swiftly tool works great for installing Swift versions and works on all the distributions above (minus Arch Linux, since the installation method uses the AUR instead).

curl -L https://swift-server.github.io/swiftly/swiftly-install.sh | bash

I am sure that it will work on even more distributions (like Debian 10/11, older Linux Mint versions, and so forth) but I did not test those. I only listed here what I tried and had great success in building and running Swift applications. If anyone else has experience using those, let me know!

Thanks all, and have fun in your Swift adventures!

13 Likes

Well, this is really nice to know. I was about to install the flatpak on Tumbleweed, but being able to use the latest release from Swift.org is much nicer.

1 Like

I haven't tried the flatpak yet, but maybe that's also a good option. In fact I didn't know there was a flatpak available.

I'm curious if you had a chance to test any of the Raspberry Pi distributions?

1 Like

It seems to be new, it wasn't available when I looked a few months ago, but I found it on a search of Flathub last week.

Also, if you want to compile with --static-swift-stdlib, you'll need to make sure libstdc++ is installed. On Tumbleweed that means sudo zypper in libstdc++-devel .

1 Like

I haven't tried yet but I can give it a shot. I only expect it to work on 64-bit distro's such as Raspberry Pi OS or Ubuntu. But, I have tried swiftly on Fedora arm64 running inside of a VM on a MacBook M1. It works fine :)

Thanks for the tip. I added it to the install command in my original post and will also give it a shot on OpenSUSE Leap!

I can't seem to get C++ interop to work, I keep getting an error saying that it can't build Glibc (or Foundation if I import that). Everything else is working great though.

Okay, I find that strange. I was able to use C++ interop with Swift 5.10 on OpenSUSE Leap 15.5 with a private C++ library with Glibc and Foundation included and it builds and runs. I was also able to setup a test project with CXX interop enabled on OpenSUSE Tumbleweed and it compiles and runs as well...

Could this be related to your static linking of swift-stdlib, or a library you are using? I have had issues compiling swift-proto and another library when having CXX interop enabled.

So I sat down and tested a few Raspberry Pi distributions with Swiftly and Swift 5.10 and both Raspberry Pi OS 12 (Bookworm) and 11 (Bullseye) work just fine. For Bookworm I selected the Ubuntu 22.04 Swift version, and for Bullseye I selected the Ubuntu 20.04 version. I also tried the 32-bit (armhf) versions of these distributions, and as expected they do NOT work since both Swiftly and Swift are only built for arm64/aarch64. It would be NICE to have armhf support but we don't have that yet...one thing I've been trying to work towards with the community :)

1 Like

There were two separate problems, the one that was causing Glibc to fail to build was using -Xcc -march=x86-64-v3 with C++ interop enabled.

When I removed that flag, trying to use C++ interop with --static-swift-stdlib I get:

error: link command failed with exit code 1 (use -v to see invocation)
/usr/bin/ld.gold: error: cannot find -lswiftCxx
/usr/bin/ld.gold: error: cannot find -lswiftCxxStdlib
/usr/bin/ld.gold: error: cannot find -lswiftCxx
/usr/bin/ld.gold: error: cannot find -lswiftCxxStdlib

So, C++ interop does work, I just can't specify my target architecture or statically link the standard library when I use it.

1 Like

Okay yeah seems like C++ interop is still pretty buggy in 5.10. For the second issue with --static-swift-stdlib, yesterday I found that the libswiftCxx.a and libswiftCxxStdlib.a static libraries were in the wrong location to be used for static linking. If you move them from usr/lib/swift/linux to usr/lib/swift_static/linux then static linking works:

mv ~/.local/share/swiftly/toolchains/5.10.0/usr/lib/swift/linux/libswiftCxx*.a \
   ~/.local/share/swiftly/toolchains/5.10.0/usr/lib/swift_static/linux

Not sure if it's worth filing some bugs to get these things fixed for Swift 6.0 or if they're even already fixed. But, ideally it would be nice for all this to be worked out once C++ interop is no longer "experimental".

1 Like