Swift for Android: Call for the Community

As a first step towards running the Swift toolchain natively on Android by using the Termux app I linked above, I've put together a Termux build script to automate building the Swift 5.1.4 compiler up through the package manager on an Android AArch64 device. If anyone wants to try building the Swift compiler on their Android device and using it, some directions follow for those unfamiliar with Termux. You will want a relatively recent and powerful CPU, ie a Snapdragon 835 or later, and need 5 GBs of free storage.

First, install the Termux app on your Android phone or tablet, available at the official Play Store or other open-source app stores like F-Droid or APKPure. Once installed, open the app and type and run the following commands to get the Swift toolchain built and installed:

cd ~
uname -m     # should say aarch64, otherwise this won't work
pkg install git
git clone -b swift https://github.com/buttaface/termux-packages.git
cd termux-packages/
pkg install clang binutils-gold file patch python cmake ninja python2 perl rsync libandroid-spawn libcurl libicu libsqlite libuuid libxml2 llbuild pkg-config
TERMUX_MAKE_PROCESSES=5 ./build-package.sh swift
dpkg -i debs/swift_5.1.4_aarch64.deb

TERMUX_MAKE_PROCESSES determines how many cores to use, use more if you don't mind the device becoming unresponsive or the build potentially getting killed, as Android is more aggressive about killing such background processes than a desktop OS.

Usually, the Termux app will also show up in the notification tray, where if you press the down arrow next to the Termux name, more options like 'Acquire Wakelock' will show up. It's a good idea to press that option, so that if the device screen turns off, the build can continue in the background.

The build takes three hours on a Snapdragon 835, so be prepared to wait, but once it's done, SPM commands like swift build or swift test should be available and you can try writing and building Swift packages on your Android device. See the Termux pull linked first above for more info.