Announcing Swift for armv7 Distributions

Since officially supporting armv7 in Swift has been slow and spotty at best, I've launched a personal project to make it more accessible to use Swift on armv7 SBCs which are still around and used by many, although the industry has been steadily moving towards things like aarch64 and RISC-V.


Source: Swift on Raspberry Pi (in 2019) – Wade Tregaskis

To make this easier, I've built 3 versions of Swift for Debian Bullseye/Bookworm and Ubuntu Focal/Jammy/Noble. See the releases on my GitHub page:

I based these builds of off @ColemanCDA's excellent swift-armv7 build scripts, but further refined them and added CIs for building any version of Swift after 5.9. Also, these scripts can be taken by anyone and used to build Swift for custom sysroots, or generate SDKs with custom dependencies as well.

I hope this can be helpful to others wanting to use Swift on armv7 but avoiding it since there is no official support. The way I see it, if the community supports this armv7 effort, it should be good enough until the architecture is no longer produced anymore.

Some eventual goals of this project are:

  • Using the artifacts built above, generate cross compilation SDKs that can be installed using swift experimental-sdk install or swift sdk install.
  • Generate deb packages for the Swift runtime for armhf that can be easily installed on the target. Hosting an apt repository would be a bonus if it is not too expensive.
  • Creating some documentation somewhere (on a website or GitHub wiki) on how to get started with Swift on armv7, with more advanced topics like how to generate custom SDKs.

I am doing this for myself (and my Raspberry Pi projects) but also for others. Please hit me up if you are interested in this or file an issue on the repo if you need help with something related to the build artifacts.

20 Likes

Nice work! Congrats on the results you’ve made.

I don’t think the Swift community is not interested in getting more platforms supported, especially with the continuous development of Embedded Swift. However, we do need a more complete support matrix with multiple tiers that allows developers and users to track the support status of each platforms.

2 Likes

I did try to get cross-compilation support for armv7 into swiftlang/swift previously, but ran into a host of issues and was not even able to get a working runtime when using the buildbot. So unless someone working for Apple or swiftlang or the community could figure it out somehow, it seems like armv7 will never be officially supported.

Regardless, there are versions of Swift that are released that can be minimally patched to build the runtime for armv7, and this is what I'm trying to provide now, today.

I'm not against getting cross-compilation support for armv7 in swiftlang/swift, but I just can't be the one to do it since I don't have the bandwidth for it, and smarter people then me would have to tackle this.

1 Like

Unless you have some other patches that aren't public, your repo only shows a single tiny patch to Swift 6 to build these armv7 SDKs, so it looks like pretty much everything works. That's because there are internal CI at Apple that still test 32-bit watchOS or whatever, and Swift devs occasionally merge 32-bit fixes that show up there.

As for adding a public 32-bit CI again, I will look into adding Android armv7 to the official CI at some point, just as I make available an untested Android armv7 toolchain for the Termux app on Android, which I believe is the only 32-bit Swift toolchain available for the last couple years. :blush:

3 Likes

Yeah, it’s really just the buildbot and build scripts that need to be patched to get cross compilation for Linux armv7 to work. Unfortunately I wasn’t able to get it working, but maybe there’s still a chance to get this working in the future.

But yeah, at least being able to compile the runtime and main libraries with minimal patching is good. The only stdlib feature that is not working is backtracing…looks like it’ll need to be patched for armv7. Say, is backtracing enabled on the Android armv7 build?

To answer this, there are no other patches to build Swift for armv7. This particular one is just for CXX interop to build properly when using an external sysroot, and not specific to Swift 6.0! It is pretty shocking how easy it can be when you’re just using cmake to build.

No, that is not enabled for Android at all, as it appears to launch a toolchain executable to dump the backtrace output to the command-line when the main Swift binary crashes, so it seems aimed at Swift on Server and other command-line executable use, whereas Android apps invoke native code like Swift as part of native shared libraries and don't expose a CLI for that output.

I would like to use it in the Termux app for Swift command-line executables though, so I've started porting that backtracing code, but haven't spent much time on it.

1 Like

Over the Christmas break I did some more work on the repo to make it even better. Here's what I did:

So now, there are armv6 + armv7 artifacts for Swift 6.0, 6.0.1, 6.0.2, and 6.0.3 releases. These can be easily downloaded, used, and deployed to the board to run Swift on every Raspberry Pi ever made.

Happy New Year to all!

11 Likes