Swift 5.7 Release for Debian Bullseye 32-bit ARM (armhf)

I've updated my Swift for ARM scripts to Swift 5.7

This new version requires the LLVM headers from Swift to be locally compiled, and using the built in Debian / Ubuntu ones is deprecated.
I've added scripts to build LLVM and uploaded a prebuilt Docker image so Swift packages on GitHub can cross compile to ARM without building everything.

https://hub.docker.com/repository/docker/colemancda/swift-armv7

  • colemancda/swift-armv7:latest and colemancda/swift-armv7:5.7 contains Debian 11 armhf sysroot to build everything (including LLVM from scratch)
  • colemancda/swift-armv7:5.7-prebuilt has the Debian 11 armhf sys root with Swift installed to /usr/lib/swift
linux-swift-5_7-armv7-debian-build:
        name: Build Debian Armv7 (Swift 5.7)
        runs-on: ubuntu-20.04
        container: colemancda/swift-armv7:5.7-prebuilt
        steps:
        - name: Checkout
          uses: actions/checkout@v3
        - name: Swift Version
          run: swift --version
        - name: Build
          run: |
            cd /usr/src/swift-armv7
            export SWIFT_PACKAGE_SRCDIR=$GITHUB_WORKSPACE
            export SWIFT_PACKAGE_BUILDDIR=$SWIFT_PACKAGE_SRCDIR/.build
            mkdir -p $SWIFT_PACKAGE_BUILDDIR
            mkdir -p /usr/src/swift-armv7/build/
            ./generate-swiftpm-toolchain.sh
            ./build-swift-package.sh
        - name: Archive Build artifacts
          uses: actions/upload-artifact@v3
          with:
            name: swiftpm-5_7-build-debian-armv7
            path: .build/*/*.xctest

This is an example of a GitHub Action for cross compiling the unit tests of a SwiftPM library with the provided docker image that can later be run on Debian 11 armhf on real hardware. You don't have to worry about building Swift, the compiler, or LLVM.

This is the compiled Swift 5.7 runtime you can install into /usr/lib, only 35 MB download

https://github.com/colemancda/swift-armv7/releases/download/0.4.0/swift-armv7.tar.gz

If you want the Swift compiler for Arm64, check out The Swift Arm Community CI Server

8 Likes

Thank you so much for putting this together. I am not sure if I am missing something or miss understanding what this is, but I downloaded the tar.gz from the link and when I expanded it, there isn't any "swift" or "swiftc" executables.
I do apologize if I am missing understanding, I am really not that familiar with cross compiling or building Swift.

I also wanted to share scripts I've updated for Buildroot and Yocto Linux, for embedded systems. I want to thank @William_Dillon2 for spearheading these efforts years ago and sponsoring the maintenance of various Swift for Armv7 toolchains over the years, as well as @uraimo @futurejones and @Buttaface . I'd also like to invite developers interested in Swift on 32-bit ARM development to join our Slack .

Just released newly cross compiled runtime with compiler and SwiftPM. This means you can build on device with swift build in addition to cross compiling from Linux and macOS. It's recommended you cross compile for release builds and build on-device for debug builds and testing. SourceKit-LSP is also built and working with VS Code on Armv7. This is the first release of Swift compiler for Armv7 since Swift 5.1.5. Previous releases after Swift 5.2 were cross compiled runtime only.

3 Likes

This is the first release of Swift compiler for Armv7 since Swift 5.1.5.

Amazing work! I'm looking forward to trying this out again :clap:

Out of curiosity, why is it recommended to cross compile for release builds with this toolchain? My typical workflow involves doing containerized docker builds on arm hardware for releases.

While the Swift runtime on Armv7 itself has no issues, several new Swift compiler optimization passes introduced since 5.2 are in the process of being fixed for 32-bit and some even rewritten in Swift on the latest development builds. Until those fixes and rewrites for swiftc are complete, you can reliably build debug builds, but some projects will cause swiftc to crash on Armv7 when building for release depending on which optimizations passes are run by the compiler. I am working with Apple to get swiftc crash free on Armv7 and i386. Hence why I am cross compiling everything in the first place.

1 Like

I have docker images readily available both for the Armv7 runtime and development, as well as x86 image to cross compile. See this GitHub action for an example of building natively and cross compiling:

  • colemancda/swift-armv7:latest-runtime Debian 11 armhf with Swift runtime and compiler
  • colemancda/swift-armv7:latest-prebuilt Ubuntu Jammy x86_64 with Swift compiler and cross compilation environment

You can also cross compile from macOS.

1 Like