Debian Packages for Swift on ARM

Rpi3

Disclaimer! Swift on ARM systems is very much at an alpha stage at the moment! The package below does not contain a working

12/27/15 Update: The REPL is now somewhat functional on BeagleBone and BeagleBoard. Occasionally you may see Execution interrupted. Enter code to recover and continue.
1/4/16 Update: Foundation is now working!

You can track the progress of the port of Swift to ARM platforms at bugs.swift.org, and follow @iachievedit on Twitter for updates when new packages are released. To help out, create an account at bugs.swift.org and when you find broken stuff, file bugs and tag them with ‘arm’. This tagging process helps those working on ARM support track all of the open issues in JIRA.

Background

A number of folks have been working hard to get a port of Open Source Swift working on ARM-based platforms such as the RaspberryPi, BeagleBone, etc. A port request, SR-40 was opened in JIRA and from there several forks of the main Swift repository were created to start the work. William Dillon succeeded in getting a basic port to work, which was no small feat. This work has been a collaboration among a number of users on Github including hpux735, tienex, and others.

Prerequisites

The clang-3.6 and libicu-dev packages need to be installed. In addition, you should use update-alternatives to provide /usr/bin links for clang and clang++.

sudo apt-get install libicu-dev
sudo apt-get install 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

Editor’s Note: Jump down to the bottom if for whatever reason you absolutely cannot find clang-3.6 for your system.

Installation

At the moment there are packages for Ubuntu 14.04 (Trusty) and Debian 8.2 (Jessie). These have been tested on the BeagleBoard X15, BeagleBone Black, and Wandboard.

1. Add the repository key

wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -

2. Add the appropriate repository to sources.list

Ubuntu 14.04 (Trusty)

echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list

Debian 8.2 (Jessie)

echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ jessie main" | sudo tee --append /etc/apt/sources.list

3. Run apt-get update

sudo apt-get update

4. Install swift-2.2!

apt-get install swift-2.2

Trying it Out

Again, a warning! There is no Swift package manager in this build yet. You can however compile basic applications, including those requiring Glibc and Foundation.

root@beaglebone:~# more helloWorld.swift 
print("Hello, world!")

for i in 1...10 {
  print(i)
}
root@beaglebone:~# swiftc helloWorld.swift 
root@beaglebone:~# ./helloWorld 
Hello, world!
1
2
3
4
5
6
7
8
9
10

or, try out swiftcat.swift which uses Glibc.

With the latest 0ubuntu11 release, Foundation is supported too!
countdown.swift

Stay Tuned!

Folks are working hard to bring Swift to our favorite ARM platforms. Updates will be posted to this article as well as to our @iachievedit Twitter account.

For those using Raspbian

Editor’s Note: This has been tested on at least one Raspberry Pi 3. YMMV.

For some reason clang-3.6 isn’t readily available on Raspbian systems. If you find yourself in the situation of having clang-3.7 or later and want to use the swift-2.2 package, you can use these steps. Yes, this is a bit of trickery.

Before starting, go ahead and install clang-3.7 (or whichever clang version you are using), as well as libicu-dev: sudo apt-get install clang-3.7 libicu-dev.

Then,

  1. Add the iAchieved.it LLC repository key (step #1 above)
  2. Add the Jessie repository.
echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ jessie main" | sudo tee --append /etc/apt/sources.list
  1. Download the .deb file with aptitude download swift-2.2. The downloaded file will include something like 1%3a2.2-0ubuntu11_armhf in it.
  2. Perform the following steps (from Serverfault):
$ ar x swift-2.2_1%3a2.2-0ubuntu11_armhf.deb
$ tar xzf control.tar.gz
# Edit control in a text editor and replace clang-3.6 with clang-3.7
$ tar c control | gzip -c > control.tar.gz
$ ar rcs swift-2.2-new.deb debian-binary control.tar.gz data.tar.xz # Note the order is important

Then, install the new package file: sudo dpkg -i swift-2.2-new.deb. Good luck!

3 comments

  1. John CutlerReply

    Thanks for your great work! Do you know if the Package Manager has been implemented for debian Arm7 yet ? (as of 3/26/16)

  2. John CutlerReply

    Hello again. I have had good success on my Debian amd64 bit Jessie install with your swift-2.2 and the swift-3.0 packages. On this 64 bit Debian – lldb works fine.

    On the BBB 32-bit Swift-2.2, lldb works, but has problems:

    For example I can use the lldb command fr v -a, and it prints out all the variables just fine. However, if I instead use the “p” command for a variable, it complains….

    lldb: /mnt/usbms/package-swift/swift/lib/AST/Module.cpp:1477: void performAutoImport(swift::SourceFile &, SourceFile::ImplicitModuleImportKind): Assertion `M && “unable to auto-import module”‘ failed.
    Aborted

    Any ideas as to why? As I said, the fr v command works fine.

    Thanks

    John

  3. BobReply

    Hello

    I have a Beagle Bone Black running Ubuntu 140.04.

    After following the directions I get this error:

    :0: error: opening import file for module ‘SwiftShims’: No such file or directory

    I have successfully installed the Debian version on the same BBB. And it worked fine.

    Any suggestions ?

Leave a Reply

Your email address will not be published. Required fields are marked *