If you've got a Raspberry Pi 3 B+, there are several options for getting Swift to install on your Pi.
Option 1: Raspbian Stretch
buildSwiftOnARM repo on GitHub has a link to a pre-compiled binary.
- Download it from the link on buildSwiftOnARM.
- The file will land in
/home/pi/Downloads/
- Untar the file with the following command:
tar zxvf swift-4.1.3-RPi23-RaspbianStretch.tgz
- Upon completion of Step 3, you should hae a directory called
home/pi/Downloads/usr/ that's got all the Swift files in it.
- Next, copy the files from that directory with the following command:
sudo cp -R /home/pi/Downloads/usr/ /
At that point, typing swift --version should tell you what version you've got installed on your Pi. Unfortunately, I haven't found anything that works for cross compiling Xcode projects created on a Mac to build on an ARM processor, so for now, you're stuck editing on the Pi. I've found the easiest route to go is Visual Studios Code compiled for ARM processors. This build of Visual Studios Code can be called from the command line using code-oss. You can add basic autocompletion, linters, etc. as you normally would within Visual Studios Code.
Another option is Hypriot. While this works OK, you can't cross compile on a Raspberry Pi 3 B+ as of 12/26/2018, so you're left editing in vim.
Option 2: Hypriot
- Download Hypriot & unzip it
- Download & install Balena Etcher
- Insert a microSD card you don't mind nuking into your Mac.
- Open Disk Utility
- format your SD card as MS-DOS (FAT) with the scheme Master Boot Record
- Open up Balena Etcher
- Select the Hypriot image
- Select your newly nuked & formatted microSD card
- Etch it
- Once it's done etching, dismount the drive if it doesn't do so automatically and insert it in your Pi 3 B+
- Boot up your Raspberry Pi 3 B+
- Login to your pi. Username is
pirate, password is hypriot (CHANGE THIS AT SOME POINT)
- Setup your WiFi by typing
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf, which will open nano.
Here's what got WiFi working in my wpa_supplicant.conf file:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOUR NETWORK NAME HERE"
psk="YOUR PASSWORD HERE"
}
Ctrl + X to exit nano
- Your WiFi won't work until you reboot. Shutdown the Raspberry Pi 3 B+ with
sudo halt
- Wait until the lights stop flashing on your Pi to unplug it, then unplug and replug it.
- When you reboot and login, try
sudo ping cnn.com to verify your WiFi works & Ctrl+C to stop the pinging
At this point, you've got a Raspberry Pi 3 B+ setup that runs Hypriot. Next, you'll want to mosey on over to helje5/dockSwiftOnARM. There's a bunch of links there for getting it going.
Install Swift for Docker
- Type
docker pull helje5/rpi-swift, which will pull down the latest version of Swift for ARM onto your Pi. It'll take a few minutes to finish and you'll see updates on progress in terminal.
- Type
docker run --rm helje5/rpi-swift-dev swift --version
At this point, you should see this outputted in your terminal:
Swift version 4.1.2 (swift-4.1.2-RELEASE)
Target: armv7-unknown-linnux-gnueabihf
- Celebrate
Creating a project
Here's a link for cross compiling a Swift project using Docker