Stream: ideas

Topic: Actually portable executable


view this post on Zulip notramo (Oct 12 2026 at 13:43):

I found this interesting blog post by the author of the Cosmopolitan libc:

https://justine.lol/ape.html

view this post on Zulip notramo (Oct 12 2026 at 13:44):

I wonder if this idea could be implemented into Roc, to create cross-platform binaries.

view this post on Zulip Richard Feldman (Oct 12 2026 at 14:15):

I think so! I haven't looked deeply into it but I'm pretty sure we could do it. Seems like a cool idea

view this post on Zulip notramo (Oct 12 2026 at 17:49):

@Richard Feldman, should I open an issue for tracking?

view this post on Zulip Richard Feldman (Oct 12 2026 at 17:53):

I'd rather wait until someone tries actually building something with it :smile:

view this post on Zulip Richard Feldman (Oct 12 2026 at 17:53):

I don't think we need an issue for it

view this post on Zulip Richard Feldman (Oct 12 2026 at 17:53):

if anyone wants to try and gets blocked by Roc compiler blockers, lmk!

view this post on Zulip notramo (Oct 12 2026 at 17:54):

So, it would not need anything from Roc, just create a C platform and use Cosmopolitan libc?

view this post on Zulip Richard Feldman (Oct 12 2026 at 17:58):

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"

view this post on Zulip Richard Feldman (Oct 12 2026 at 18:00):

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

view this post on Zulip Richard Feldman (Oct 12 2026 at 18:02):

there's also a question of whether lld knows how to link that format

view this post on Zulip Richard Feldman (Oct 12 2026 at 18:03):

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

view this post on Zulip Richard Feldman (Oct 12 2026 at 18:05):

using the same linking settings we always use

view this post on Zulip Richard Feldman (Oct 12 2026 at 18:06):

getting all the crti.o and similar stuff figured out would likely be tricky there

view this post on Zulip notramo (Oct 12 2026 at 19:18):

I prompted an LLM agent to do some research, and it said the task is even more complex than what you described here.

view this post on Zulip notramo (Oct 12 2026 at 19:20):

So it would not worth the time and effort with the current state of the compiler. Maybe after 1.0 or later?

view this post on Zulip Peter Marreck (Oct 13 2026 at 15:01):

@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

view this post on Zulip Peter Marreck (Oct 14 2026 at 00:15):

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.

view this post on Zulip Peter Marreck (Oct 14 2026 at 00:18):

I'm testing it out on my "pinterm" roc terminal game thing from the "show and tell" forum

view this post on Zulip notramo (Oct 14 2026 at 10:57):

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?

view this post on Zulip Peter Marreck (Oct 14 2026 at 12:06):

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