I found this interesting blog post by the author of the Cosmopolitan libc:
I wonder if this idea could be implemented into Roc, to create cross-platform binaries.
I think so! I haven't looked deeply into it but I'm pretty sure we could do it. Seems like a cool idea
@Richard Feldman, should I open an issue for tracking?
I'd rather wait until someone tries actually building something with it :smile:
I don't think we need an issue for it
if anyone wants to try and gets blocked by Roc compiler blockers, lmk!
So, it would not need anything from Roc, just create a C platform and use Cosmopolitan libc?
it's been years since I looked into it, but my vague memory was that you needed to make the output binary in a specific way so that each of the OSes look at the same bytes and think "this is in the right format for me"
if that's correct, I suspect we might need a --target=x64ape or similar, but I'm not sure if llvm supports that output format. I seem to recall they have a reference c compiler, which might use llvm but I'm not sure haha
there's also a question of whether lld knows how to link that format
part of what I think needs a proof-of-concept is building an APE host and then linking it together with a fake "Roc program compiled to APE" and making sure it all comes together
using the same linking settings we always use
getting all the crti.o and similar stuff figured out would likely be tricky there
I prompted an LLM agent to do some research, and it said the task is even more complex than what you described here.
So it would not worth the time and effort with the current state of the compiler. Maybe after 1.0 or later?
@notramo
I like APE, but I found out that it has a few warts- for example, you cannot build for x86_64 from macOS aarch64, you need to cross-compile to aarch64 from x86_64 Linux.
And there's an issue with a fundamental thing that makes it work, IIRC (which might actually be related to the above)- Justine literally rewrote libc (cosmopolitan-libc) to make it all work. And... That may cause OTHER issues.
It's quite an attractive idea, though- a true universal binary!
Ah, another thing I remembered- last I checked, the Mac builds it made were x86_64 only and not aarch64, and that won't be possible to run on macOS soon
uh, I got it to work. Across roc, zig and rust. :laughing:
A single executable artifact for everything. Basically... Better than APE, @notramo :sweat_smile:
Catch: On some platforms, it writes a new executable to a cache location and that's what it actually runs, since only Linux can basically run a binary from a subsection of another binary.
I'm testing it out on my "pinterm" roc terminal game thing from the "show and tell" forum
So, you compile normal Roc targets, then bundle them into an archive-like file with an external tool, which simply unpacks them when it's started?
oh boy. you'll see in a few. it's... good. ;) Doesn't require APE anymore, either, but uses a technique inspired by it (but better... this one works on all the BSD's as well)
Last updated: Oct 15 2026 at 17:56 UTC