Hello everyone, i'm not sure if i'm in the right channel for this. I wanted to share some experiments I made recently on Kotlin Native, hoping to reach the kotlin team too as I'm sure there are interesting things in there.
For a bit of background, there is this not-so-known project called
cosmopolitan. It's a fantastic project that manages black magic of the highest order: compiling C code to a single executable file that can run on all major OSs (windows, macOS, linux, BSDs..) and architectures (x86/ARM). It's a bit hard to grasp but the end result of using cosmopolitan is truly a single file that can run everywhere with no runtime dependency.
The black magic involved in cosmopolitan is quite complex, and i won't pretend that I could explain it myself, but the thing i know about it is that it requires compiling to native linux programs, then linking with cosmopolitan's libc abstraction that ensure the compatibility of the program.
I realised that Kotlin Native could be compiled to native linux, obviously, and asked myself if it was possible to use the cosmopolitan project to compile kotlin to cross platform/architecture programs. With the help AI tooling to do the heavy lifting, I experimented on the subject and reached the conclusion that it is indeed possible.
The following proof of concept is available here:
github.com/Arwalk/kotlin-ape-poc
The
writeup explains how everything fits together and how is it possible. To make it short,
a non trivial kotlin program was successfully compiled to a single file that will run, at least, on linux ARM, mac ARM, windows X86 (which are the platforms that I manually tested).
Once again, i find it very cool myself, especially how the solution to this was patching the IR before recompiling / linking, but it's just an experiment. The value is in the
how, not on the
what.
I'd be happy to hear your opinion about this, if you have any feedback to provide. And once again, i'd like to be sure that it reaches the kotlin team at some point.