Swift for Debian Armv7

I have been working previously on Buildroot support for Swift on Armv5 since Swift 5.4, and I'm excited to share that work has culminated into a set of scripts and distributable binaries to cross compile the Swift runtime (and SwiftPM packages) for Debian 11 Armhf. This binary distribution can be used with existing toolchains from Swift.org and @futurejones swiftlang.xyz.

I have also provided Docker images to quickly cross compile for Debian 11 Armhf

  • latest: this is the bare minimum environment needed to cross compile the Swift runtime for Armv7. Includes Swift 5.6.1 compiler, Cmake 3.22 and LLVM headers. The build.sh script can be used to cross compile the runtime. Takes about 5 minutes to compile Swift, Dispatch, Foundation and XCTest.
  • 5.6.1-prebuilt: This image builds on latest as a base, but also includes the Debian 11 sysroot needed to cross compile Swift packages and the Swift runtime already compiled for Armv7. The generate-swiftpm-toolchain.sh and build-swift-package.sh scripts can be used to cross compile packages.

Example of Docker image usage:

In this example, the colemancda/swift-armv7:5.6.1-prebuilt Docker image is used to cross compile the package in a x86 CI environment. The -prebuilt suffix means the image contains the Debian 11 Armhf sysroot with the Swift runtime librares. The next GitHub Action takes the compiled .xctest executable and runs it in a self hosted Armv7 environment (Orange Pi Zero 2 development board).

v0.3.0 binaries

5 Likes

Great work!

I am not super familiar with similarities between Debian and OpenWRT, but I see you have mentioned OpenWRT before. Have you been to compile any Swift application for OpenWRT and if so, can you give some direction on how I can achieve this, possibly using your prebuilt docker images.

Ok, after a lot of trial and error, I seem to have got it working by creating a new buildroot package for the target platform I am building for and updating a lot of library and include paths. Some more info can be found on the fork I created here: GitHub - sroebert/swift-armv7: Swift runtime for Linux Armv7

I also have a Buildroot fork that integrates Swift as proper Buildroot packages.

@sroebert I updated the repo for Swift 5.7.1. Also I have Buildroot external for proper Swift support

Updated for Swift 5.7.1

Debian 11 Armhf

Buildroot

Yocto