[GSoC 2025] Swift for Embedded Linux

To myself:
I am a huge Apple fan and embedded software engineer. Enough said, let's get to the details of this proposal!

Proposal Summary
Apple's Swift programming language is growing. With the static Linux SDK (Swift.org - Getting Started with the Static Linux SDK) and Swift cross compilation concept(swift-evolution/proposals/0387-cross-compilation-destinations.md at main · swiftlang/swift-evolution · GitHub) efforts have been made to port Swift to more platforms.
I would like to join these efforts and bring Swift to Embedded Linux using Yocto.

Project size: I have no idea
Estimated difficulty: Intermediate

Project Technologies
C++, Swift, Python, CMake, Bitbake

Project Topics
Embedded Linux, Builds

Expected Outcomes / Deliverables:

  • Swift built using Yocto for arch: aarch32, aarch64 and x86_64
  • CI on swiftlang/swift for Embedded Linux

:person_raising_hand: What I’m Looking For:

  • a mentor

Thank you very much for anyone who took the time to read this. I am always open for feedback and happy for interactions.

1 Like

@lukeh? Seems up your alley :wink:

Ha, indeed. I believe OP and I are already in touch on the PR.

What's remaining from my end is:

  • reoccurrence of C++ interop issue when building with Swift 6.1
  • moving to self-hosted build (which will involve building Swift 5.9 first, then Swift 6.x with utils/build-script)

I am working slowly on both of these but could definitely use some help. Xaver, do you want to reach out offline, either DM me or email me at padl.com (username same as on here).

1 Like

Hey @lukeh,

It is great to see you here as well!

I would like to get Swift for Embedded Linux in a state so it may be officially supported by Swift‘s ecosystem.

Ultimately I want to have a CI on swiftlang/swift running the Yocto build and have the meta-swift layer moved to swiftlang.

I bring it up here for GSoC as it seems to be a great opportunity for me and matches the efforts from Swift that I have seen.

In order for this to happen:

I will write you an email, Howard!

Any help to write a proposal is greatly appreciated!

2 Likes

I'm still learning about both Yocto and the Swift build system so, forgive any inaccuracies in the text below.

Here's my understanding of where we're at.

  • The current meta-swift layers (both the original and my 6.0.2 PR) download the host toolchain from download.swift.org, which is capable of cross-compiling, and then explicitly build the standard library and Foundation for the target
  • Irrespective of how the cross-compiler is built, it's important that the target libraries are built in the specific Yocto target environment to ensure that the glibc version matches, any sub-arch optimisations are made, etc.
  • Because this doesn't use build-script it's not particularly resilient to new Swift releases (it is easy, for example, to miss new CMake defines for experimental features that should be enabled by default)
  • We also do have some issues with cross-compiling which may or may not be related to not using build-script, in particular to do with the heuristic used by the Swift clang driver to find the location of libstdc++ which is required for the C++ interop modules to build
  • To be consistent with the way other languages are built on Yocto, we would ideally prefer to build the Swift cross-compiler from scratch
  • Because Swift 5.10 and above require Swift to build the compiler, this also means we will need to build Swift 5.9
  • Ideally we should support both static and dynamic linking of the Swift standard libraries for the target, either way they do have to be built. Likely we also want to support musl as well as glibc. But these (to me) are stretch goals.
  • Care needs to be taken integrating SwiftPM vendored dependencies with Yocto. We need to decide whether we are OK with SwiftPM managing the dependency versions or these should be lifted into the Bitbake recipe.
  • Orthogonal to this (but also important) is that the dependencies are only fetched near the do_fetch build task as Yocto by default does not provide network access during the do_compile task. My current PR does this by adding a do_swift_package_resolve task between do_unpack and do_compile, which runs swift package resolve as well as git submodule update --init --recursive --depth 1.

Anyway, that's my brain dump of where I think we're at. More to follow.

2 Likes