Porting the Swift Runtime to Android, Part One: The How

In June 2016 something I worked on was featured in Apple's WWDC State of the Union.

Shortly after Swift was open-sourced, Zhuowei Zhang sent an email to the swift-dev mailing list, introducing his fork of Swift, which could produce code that ran on Android devices. I worked on his fork, to adapt the code so that it could be merged into the Apple Swift repository. In February 2016 I sent a pull request, entitled simply "Port to Android". It was merged in April.

What does it mean to "port" the Swift runtime to Android?

The Swift compiler is a program that simply translates Swift source code into an intermediate representation, called LLVM IR. LLVM is a program that translates LLVM IR into assembly code. Assembly code is a slightly more readable version of the 0's and 1's that are used to represent machine instructions. LLVM can generate assembly for many different platforms, including Android, PS4, and Windows.

$3+ patron-only content

What it means to generate code for an Android target, as well as a step-by-step breakdown the code changes to Swift compiler that were necessary for it to do so.

I am a patronBecome a patron

In a future post, I'll write about the current state of using Swift to write Android apps. In the meantime, you can read on for more technical detail on the above changes.


1. Modifications to the compiler itself

$3+ patron-only content

Details on the modifications made to swiftc.

I am a patronBecome a patron

2. Modifications to the Swift runtime

$3+ patron-only content

Details on the modifications made to the Swift runtime such that Swift code can execute (relatively) normally in Android environments.

I am a patronBecome a patron

3. Modifications to the Swift standard library

$3+ patron-only content

Details on the modifications made to Swift's standard library so that it can fulfill its API contracts, even in an environment as different as Android.

I am a patronBecome a patron