Update 6th Sept: Swift 3.1.1 with SPM now compiles correctly on the latest Raspbian, check out the post here.

Update 12th May: Added section on cross compilation.

I think it’s time for another update on the status of Swift on Raspberry Pi and other ARM boards.

If you are using a Raspberry Pi 2 or 3 with Ubuntu Mate 16.04, that has been for some time the distribution I recommend, you can just download release 3.1.1 from here(install the dependecies with: sudo apt install clang-3.8 libicu-dev libcurl4-nss-dev) or use the updated buildSwiftOnARM scripts to build your own binaries.

Just decompress the tgz archive and both swiftc and swift will be available under ./usr/bin. Use the former to compile Swift files directly or the swift binary to access additional tools like SPM (as usual the REPL will not be available).

Thanks to Florian Friedrich most of the patches required to compile on ARM have been integrated into the Swift master and 3.1 branches.

If you have an ARMv6 board like the original Raspberry Pis or the new Zero boards or you are just running Raspbian, at the moment it’s not possible to compile successfully releases of Swift newer than 3.0.2.

That release could be enough for what you want to do and if it is, you can find it here (and yes, there is still no SPM on Raspbian/Debian, but read the section on cross compilation).

The community built around the swift-arm Slack channel have been working on trying to get Swift to compile on Raspbian (or other Debians) since the 3.1 release and some progress has been made.

There are already some patches (that are needed on some Ubuntus too) and a couple of issues have been opened to track the current blocking issues: SR-4613, SR-4147.

As usual, 3.1.1 have been tested with SwiftyGPIO and everything appears to work.

Building on Docker and Cross-Compilation

Another recent development is the new dockSwiftOnARM project by Helge Heß that allows to run or even build Swift in an ARM docker container running on Linux or macOS, quite convinient and well documented.

A few weeks ago the Swift Package Manager finally gained support for cross compilation.

This means that now you can finally cross-compile ARM binaries from a Mac (or from Ubuntu), follow these detailed instructions from Helge Heß to build your own SPM-capable cross-compiling toolchain that produces Swift 3.1.1 ARM binaries for Ubuntu 16.04 on macOS.

Cross-compiling Toolchain for Swift 3.0.2 on Raspbian

The instructions above can be slightly modified to produce a toolchain that builds binaries that work with Swift 3.0.2 on Raspbian, but more important, has a working SPM!

A few things need to be changed from what is described in the original guide.

The toolchain will be built correctly but SPM will not work because the swiftc from Swift 3.0.2 does not support the new -swift-version option that the package manager appends when calling the compiler.