Building Swift 3.0 on an ARMv7 System
Editor’s Note: This post supersedes our other posts on building Swift 3.0 for the BeagleBone Black or Raspberry Pi 3 as it utilizes the repository’s hosted by the Swift ARM organization.
To get started with building Swift 3.0 natively on an ARMv7 you’re going to need:
- a suitably powerful ARMv7 system; we have used the BeagleBoard X15 with build times of about 4 hours and Raspberry Pi 3 for initial build times of 6 hours
- high-speed IO on either a USB3 flash drive or a UHS-I/class 10 microSD card with a capacity of 16GB or greater (I like the Patriot EP Series for the price combined with relatively high write speeds)
- one of the supported Ubuntu releases such as Ubuntu Xenial 16.04
Install Build Prerequisites
Compiling Swift requires a number of prerequisites. Get them in one fell swoop with:
# sudo apt-get install -y git cmake ninja-build clang uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config autoconf libtool systemtap-sdt-dev libcurl4-openssl-dev
Add Some Swap
You will need at a minimum 2G of RAM on an ARMv7 system to build Swift. If you are working with the Pi3 you will want to add some swap to double up from the base 1G.
# cd /var/cache # sudo mkdir swap # cd swap # sudo fallocate -l 1G 1G.swap # sudo mkswap 1G.swap Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=184d002a-2f15-4b23-8360-8e792badc6a2 # sudo chmod 600 1G.swap # sudo swapon 1G.swap
build-swift is our Github repository that has several helper scripts to make life a little easier building Swift on ARM.
# git clone https://github.com/swift-arm/build-swift # cd build-swift
build-swift will check out to the
The contained scripts (located in the
scripts directory) are pretty simple:
get.sh– Downloads all of the required repositories for building Swift; these repositories are from the Swift ARM organization and have been patched specifically for building ARMv7
update.sh– Updates all of your local repositories with the latest on Github
package.sh– Runs the Swift
clean.sh– Deletes the build artifacts
distclean.sh– Deletes both the build artifacts and the deletes the repositories
I suggest you look at each shell script and walk through the logic before executing. They are straightforward but it’s worth the time understanding what they are doing.
Let’s Do This
Remember to make sure you have:
- installed all of the prerequisite packages
- have plenty of RAM available on your system (2G minimum)
Now, clone all of the required repositories:
# cd build-swift # ./scripts/get.sh
On a high-speed SD card this step took about 15 minutes to download and write everything.
Now, compile. The Swift on ARM team uses Jenkins to run this in a headless build job, but if you use
nohup to ensure your compile continues even if the terminal detaches you should be fine:
# nohup ./scripts/package.sh > swiftbuild.log&
To watch the output of the build use
tail -F swiftbuild.log.
Now, be prepared to wait! A clean build of Swift on a Raspberry Pi 3 can take upwards of 6 hours. The reward is well worth it, however, and that is a
swift.tar.gz bundle that can be installed on either a Raspberry Pi 2 or Pi 3 running Ubuntu Xenial (do not try to install this on a Raspbian machine, you will be sorry). I like to install Swift in
/opt/swift/ like so:
# cd /opt # mkdir -p swift/swift-3.0 # cd swift/swift-3.0 # tar -xzvf /path/to/swift.tar.gz
You can then set your
export PATH=/opt/swift/swift-3.0/usr/bin:$PATH. To properly use
swift build you will also need to run the following commands:
sudo apt-get install -y libicu-dev sudo apt-get install -y clang-3.6 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
If you are having trouble compiling feel free to join our swift-arm Slack.