A Long Overdue Update on Swift 5.0 For Raspberry Pi Zero/1/2/3
Posted on April 11, 2019
Update 3/2020: 5.1.5 binaries are now available.
It has been nearly a year since the last update on the state of Swift on the Raspberry Pi and other ARM boards so let’s start with a short recap of what happened since the release of Swift 4.1.2.
TLDR: After a bloodbath with 4.2, for the first time we got Swift 5.0 running with relatively minimal effort and you can already download it now, see below.
If you have kept an eye on updates to buildSwiftOnARM you already know that by the end of October we had a working, albeit with a lingering small bug, Swift 4.2.
This was the result of the work (a huge amount of it, really) done by Kaiede (you can buy him a cup of coffee here to show your appreciation), that lead to multiple PRs opened for Swift and related libraries and took a few months to get something that could be considered stable.
And it goes without saying that the community built around the swift-arm Slack channel was responsible for ironing out a plethora of other additional issues and testing on various SBCs.
A few additional small issues were found and fixed in the monthly 4.2.x Linux-only releases and 4.2.4 now compiles without patches even on 32-bit ARM.
Considering what we are used to when a new major release comes out, getting 5.0 to compile was a breeze (in part thanks to some preemptive work done by Kaiede before the final release).
Current Status
Right now a few patches are required to compile Swift 5.0 but all the issues identified have a fix or a workaround.
A new temporary patch that limits the number of parallel jobs launched by SPM has been added by hpux735 since from this release SPM spawns a number of compiler threads equal to the number of the cpu’s cores every time you build something. This behaviour, not really optimal for platforms with a small amount of RAM, cannot be changed yet, and so for now we are limiting the number of jobs used by SPM to 1. A proper fix should come in one of the future monthly limux releases.
The Swift binaries provided below contain this hotfix if needed.
Feel free to open new issues on buildSwiftOnARM if you spot additional problems and crashes.
Prebuilt binaries
OS | Architecture | Boards | Download |
---|---|---|---|
Raspbian Stretch | ARMv6 | RaspberryPi Classic, All versions of Pi Zero | 4.2.3 - 5.0 |
Raspbian Stretch | ARMv7 | All versions of RaspberryPi 2/3 | 4.2.3 - 5.0-hotfix1 |
Ubuntu 16.04 | ARMv7 | All versions of RaspberryPi 2/3 | 4.2.3 - 5.0-hotfix1 |
Ubuntu 18.04 | ARMv7 | All versions of RaspberryPi 2/3 | 4.2.3 - 5.0-hotfix1 |
Ubuntu 18.10 | ARMv7 | All versions of RaspberryPi 2/3 | 4.2.3 - 5.0-hotfix1 |
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).
If you have patience and a few hours to spare, check out the updated buildSwiftOnARM scripts to build your own 5.0 binaries.
And for those interested in IoT projects, SwiftyGPIO has been verified with Swift 5.0, that is now the recommended Swift release.
Swift and AArch64
AArch64 should not require additional patches now (other than small patches to select the proper linker on some releases of Ubuntu), Neil Jones provides downloadable prebuilt binaries here or the same binaries via more practical apt packages.
Did you like this article? Let me know on Twitter!