A Small Update on Swift For Raspberry Pi Zero/1/2/3
Posted on September 6, 2017
Update 04/2019: Swift 5.0 now available, see post.
Update 2/2018: Fixed a libDispatch issue on ARMv6, archive updated.
Since some time has passed since the last update, here is a recap of the current status of Swift on ARM/Linux. You’ll find the previous episodes of the Swift On ARM saga here, check them out if you need additional pointers on how to run or compile Swift.
With the release of Raspbian Stretch a few weeks ago, Swift now builds correctly with support for SPM. You can grab the full build here for ARMv7 Raspberry Pi 2 and 3 or here for ARMv6 Pis like the original Raspberry or the new Zero/W.
You’ll need to install a few dependecies and fix clang’s links:
sudo apt-get install git cmake ninja-build clang-3.8 python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
Then 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).
Or you can always build Swift on your own with the buildSwiftOnARM scripts.
You’ll notice that compiling 3.1.1 on Raspbian Stretch will require an additional libdispatch patch that will need to be applied manually.
It’s available under swift-corelibs-libdispatch.diff/raspbian/
, and to apply it just run patch -p1 < ../swift-corelibs-libdispatch.diffs/raspbian/c01599944879e58556a6e34585ac6539f5e83000_no_membarrier.diff
from the libdispatch directory.
As usual, 3.1.1 have been tested on Raspbian with SwiftyGPIO and everything, finally including SPM, appears to work.
Swift 3.2 and 4.0 Status
While building 3.2 for Linux/ARM shouldn’t be a problem once it’s finalized with the release of Xcode 9.0, there are still some issues with Swift 4.0 that need to be adressed.
Even if the compiler seem to build correctly on Ubuntu Mate or Raspbian/Stretch without SPM, you’ll likely won’t be able to produce working binaries most of the times, since as shown by some failing tests, there are a few major issues related to error handling and weak references among others.
You can follow the developments on the 4.0 front subscribing to SR-5845 and SR-5846, or as usual, waiting for further updates from this blog or on twitter.
Did you like this article? Let me know on Twitter!