Code Monkey home page Code Monkey logo

buildswiftonarm's Introduction

Scripts to clone, configure, patch and build Swift 5.0 on Linux ARM devices.

Summary

Supported Architectures

  • ✅ ARMv6 32bit: Original RaspberryPi, Pi Zero, etc...
  • ✅ ARMv7/8 32bit: All versions of RaspberryPi 2/3, OrangePi, ODroid, CHIP, etc...
  • ✅ aarch64: RaspberryPis or other ARMv8 boards with a 64 bit OS, Pine64, etc...

Prebuilt binaries

OS Architecture Boards Download
Raspbian Stretch ARMv6 RaspberryPi Classic, All versions of Pi Zero 4.2.3 - 5.0
Raspbian Stretch ARMv7 All versions of RaspberryPi 2/3 4.2.3 - 5.0-hotfix1
Ubuntu 16.04 ARMv7 All versions of RaspberryPi 2/3 4.2.3 - 5.0-hotfix1
Ubuntu 18.04 ARMv7 All versions of RaspberryPi 2/3 4.2.3 - 5.0-hotfix1
Ubuntu 18.10 ARMv7 All versions of RaspberryPi 2/3 4.2.3 - 5.0-hotfix1
Ubuntu 18.04/aarch64 aarch64 All versions of RaspberryPi 2/3 4.2.3

Dependencies

In order to use the provided prebuilt binaries you'll need to install the following dependencies:

Ubuntu 16.04 and Raspbian

sudo apt install clang-3.8 libicu-dev libcurl4-nss-dev

Ubuntu 18.04 and newer

sudo apt install clang libicu-dev libcurl4-nss-dev curl

Decompress the archive on the RaspberryPi, you'll find the Swift binaries in usr/bin/ relative to where you decompressed the archive.

tar -xzf <archivename.tgz>

Ensure that the path you decompressed to is in your PATH environment variable: echo $PATH. If it's not then add it to your path for your shell.

PATH='$HOME/usr/bin:$PATH'

Verify the swift version is setup:

$ swift --version

Swift version 5.0 (swift-5.0-RELEASE)
Target: armv7-unknown-linux-gnueabihf

Building on ARM

For the latest updates on Swift on ARM, check out my blog here.

Check out Helge Heß's project dockSwiftOnARM to build Swift in a Docker container or to build a cross-compiling toolchain that will allow you to build arm binaries directly from your Mac using a precompiled swiftc for ARM.

The scripts that buildSwiftOnARM provides:

  • clone.sh - Install dependencies and clones the main Swift repository and all the related projects

  • checkoutRelease.sh - Resets all repos, updates them, checks out a specific tag (5.0 at the moment) and apply the patches.

  • build.sh - Builds Swift producing a tgz archive with the Swift distributions.

  • clean.sh - Cleans all build artifacts, only needed when you want to start again from scratch.

Step by step instructions

First of all, use a suitably sized sd-card, at least 32Gb in size, but I recommend to use an external USB drive to clone the project and build Swift.

Configure a swap file of at least 2Gb, on Ubuntu:

sudo fallocate -l 2G swapfile
sudo chmod 600 swapfile
sudo mkswap swapfile
sudo swapon swapfile

You'll need to manually enable the swap file with swapon each time you reboot the RaspberryPi (or the system will just run without swap).

On Raspbian, since the swapfile is already configured, open /etc/dphys-swapfile and edit CONF_SWAPSIZE to increase the size:

CONF_SWAPSIZE=2048

Save the file and:

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

Now, call the included scripts as follows:

  1. Launch clone.sh that will install the required dependencies (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 libcurl4-openssl-dev libz-dev), fix clang links and clone apple/swift with all its dependecies.

  2. Run checkoutRelease.sh that will select the current release (5.0) and apply the needed patches. These patches cover the basic Raspi2/3 with Xenial case, but I've had many reports of successful build on different setups, but beware, additional patches could be needed on different boards/OSs.

  3. Once done, start the build with build.sh.

  4. Once the build completes a few hours later, you'll have a swift-5.0.tgz archive containing the whole Swift compiler distribution. Once decompressed you'll find the Swift binaries under usr/bin.

I recommend to perform all these operations in a permanent background tmux or screen session (CTRL+B d to detach from the session and tmux a to reattach to it when you ssh again into the RaspberryPi).

Additional steps could be required in some cases (on a RaspberryPi 1 or for Raspbian) check the latest ARM posts on my blog for additional info.

To build a different release than the one currently configured in the script, open checkoutRelease.sh and build.sh and modify the variables on top, with the branch name for the release and the release name for the tgz respectively.

REPL Issues

Since the first releases of Swift on ARM32, the REPL has never been available on this platform, but that doesn't impact the compiler itself. Considering this, as you would expect, launching swift without parameters will result in an error instead of the REPL prompt.

Acknowledgments

We wouldn't have Swift on ARM and most of the patches included on buildSwiftOnARM without the work done by these developers:

The community can be reached at the swift-arm Slack channel.

Previous Releases

You can compile old releases checking out the specific tag:

buildswiftonarm's People

Contributors

hpux735 avatar kaiede avatar kyleleneau avatar uraimo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.