How to run swift and libDispatch on ARM (Raspberry Pi)

421 Views Asked by At

The aim is to run swift and libDispatch on a Raspberry Pi 3. I’m using Ubuntu Core 16.04

Where I’m at: I’ve tried to get SR-397 (https://bugs.swift.org/browse/SR-397) to compile - it is a minimal Swift libDispatch example. The projects for this SR are here: https://github.com/sheffler/gcd4 and here: https://github.com/sheffler/CDispatch

When I try to compile the gcd4 project, I get this error: “error: Empty manifest file is not supported anymore. Use swift package init to autogenerate.” I assumed the error message was due to the empty Package.swift file, so then I copied the Sheffler CDispatch project to https://github.com/tree700/CDispatch and added a Package.swift file. I still get the same error and haven't been able to get past it.

By way of background, I’m using a precompiled download of Swift 3.1.1 from https://github.com/uraimo/buildSwiftOnARM, and have installed Ubuntu libdispatch0 and libdispatch-dev packages and dependencies on my system. The swift compiler and Swift Package Manager are working fine,

I’d love to get this going, I use Dispatch on OS X, and it makes concurrency a breeze. Thanks

1

There are 1 best solutions below

0
On

The answer was simple... the extra information required is in the associated blog. To obtain and install Swift 3.1.1 go to https://www.uraimo.com/2017/09/06/A-small-update-on-Swift-for-raspberry-pi-zero-1-2-3/ Which says to do this...

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

After that, there is the the usual process of decompressing the compressed project file and adding the usr/bin directory into one's path (or run swift, swift etc from inside usr/bin)

Note: I also had to install the package libpthread-workqueue-dev. If running on Raspbian, requires an upgrade to Stretch .

——— By the way, I posted the SO question when using a Raspberry 3. In fact, I was on an early Pi model B when I got this working. The Pi 3 will soon have Swift also. Here is a simple Swift program to test libdispatch:-

import Foundation
import Dispatch

let queue = DispatchQueue(label: "queueName")
let workItem = DispatchWorkItem(qos: .userInitiated, flags: .assignCurrentContext) {
   print("Hello")
}
queue.async(execute: workItem)

DispatchQueue.main.async {
   print("Hello2")
}

dispatchMain()