While progress with Swift on ARM has been very encouraging, there have been a few reports of people having trouble with it. This post is intended to be a step-by-step, starting with a brand-new Raspberry Pi version 2 and a freshly-made Raspian image (note that other distributions might work, I’ve only verified raspian).
Setup the raspberry pi
I expect that you can ssh to your raspberry pi (hereto referred to as raspi), and that you’ve run the raspi-config utility.
First, you need to expand the range of debian repositories in order to access the required prerequisites. To do that, edit /etc/apt/sources.list:
sudo nano /etc/apt/sources.list
and uncomment the last line in the file, which should look like this:
deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi
Then, you’ll need to update your repositories.
sudo apt-get update
Install prerequisite software
Once that’s complete, install clang
sudo apt-get install clang
Option 1: install from tarball
A tar of the swift installation (usually more up to date) is available from my website. You can install this in either your system root, or from another directory. I do all of my testing with it installed in the system root, and therefore things are more likely to work. However, you’re putting your system at more risk by doing that. Keep in mind, though, that you’re playing around with alpha-level software on your <$100 computer… YOLO.
cd / sudo wget http://housedillon.com/other/swift-armv7.tar.gz sudo tar -xzpf swift-armv7.tar.gz rm swift-armv7.tar.gz
Option 2: install with Joe Bell’s repo
Joe @iachievedit did a fantastic job creating a debian repository for the swift compiler and tools, and he’s hosting it in an amazon aws instance. Taking this route has some huge advantages. First among them is that they’re only updated when things are stable-ish. The version hosted at my website can change frequently, and it might even be completely broken!
Now, assuming that everything went according to plan, you should be able to compile programs written in swift. Also, you should be able to use glibc and Foundation.
pi@raspberrypi:~ $ cat hello.swift import Glibc import Foundation let now = NSDate() print("Hello world at \(now)") pi@raspberrypi:~ $ swiftc hello.swift pi@raspberrypi:~ $ ./hello Hello world at 2016-01-09 05:36:31 +0000 pi@raspberrypi:~ $ uname -a Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
Not so fast
Ok, so there are some caveats. For one, it seems like the REPL is kinda broken on the Raspi v.2. Joe noticed this, too. I’m not sure what the root cause is for this one. It works on the original raspberry pi (armv6), and it works on the Beaglebone Black and Nvidia Tegra (armv7).
Also, things are very alpha-level, so expect the unexpected.