# Cosmopolitan Erlang: build once run anywhere - possible?

**URL:** <https://erlangforums.com/t/cosmopolitan-erlang-build-once-run-anywhere-possible/2004>\
**Category:** Chat / Discussions\
**Tags:** build-tool\
**Created:** [November 2, 2022, 5:55pm UTC](https://erlangforums.com/t/cosmopolitan-erlang-build-once-run-anywhere-possible/2004 "2022-11-02T17:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![100phlecs](https://erlangforums.com/user_avatar/erlangforums.com/100phlecs/32/2758_2.png) [@100phlecs](https://erlangforums.com/u/100phlecs)\
**Post date:** [November 2, 2022, 5:55pm UTC](https://erlangforums.com/t/cosmopolitan-erlang-build-once-run-anywhere-possible/2004/1 "2022-11-02T17:55:26Z")

</div>

By knitting together boot sequences in a magical way, one is able to run c executables on any platform.

> **[GitHub - jart/cosmopolitan: build-once run-anywhere c library](https://github.com/jart/cosmopolitan)**
>
> build-once run-anywhere c library. Contribute to jart/cosmopolitan development by creating an account on GitHub.

[https://justine.lol/ape.html](https://justine.lol/ape.html)

I was wondering if this could be used to make portable scripts for any beam language.  
One can already see this concept in the wild: [GitHub - burrito-elixir/burrito: Wrap your application in a BEAM Burrito!](https://github.com/burrito-elixir/burrito)

But instead of having to target the system you want to run the script on, you could instead just configure it to be cosmopolitan and let it run everywhere.

Reading through the build system of `erlang/otp` I tried altering the CFLAGS and LIBS environment variables to possibly link all that is required of cosmopolitan, but then felt out of my depth in terms of compiling large C projects. Also I had doubts on whether or not it was even a possibility.

It was possible with Python: [Python is Actually Portable](https://ahgamut.github.io/2021/07/13/ape-python/) so I would be curious if it would be possible for Erlang.

---

<div class="post-metadata">

**Author:** ![nzok](https://erlangforums.com/letter_avatar_proxy/v4/letter/n/4af34b/32.png) [@nzok](https://erlangforums.com/u/nzok)\
**Post date:** [November 3, 2022, 12:56am UTC](https://erlangforums.com/t/cosmopolitan-erlang-build-once-run-anywhere-possible/2004/2 "2022-11-03T00:56:28Z")

</div>

I think the “run anywhere” claim for  
the jart/cosmopolitan C thing is a bit overblown.  
For hardware, it lists only “Intel” and “AMD”,  
no mention of SPARC, MIPS, ARM v7, ARM v8, or  
RISC-V (to mention hardware I have), or z/Series  
or POWER (or even PowerPC).  
For operating systems, there is no mention of  
Solaris (or its sibling Illumos) or Raspbian.

If I wanted to compile C (or Rust or Go or D)  
once and run it “anywhere”, I’d look at emscripten  
plus something like wasmer.  
[https://v8.dev/blog/emscripten-standalone-wasm#running-in-wasm-runtimes](https://v8.dev/blog/emscripten-standalone-wasm#running-in-wasm-runtimes)  
(This still seems insane, even perverse, to me,  
something a hacker on acid might have dreamed up,  
but it’s real. Sober ANDF lost to a head trip.)

Erlang is intrinsically portable and so is most of  
OTP; you’re just not going to get the benefit of the  
JIT everywhere.

My own experience of porting things between POSIX  
implementations is that it’s the things you don’t  
expect to be porting problems that actually are.  
The whereabouts of various files, for example.  
Floating-point code failing mysteriously because  
‘long double’ is bigger than ‘double’ but some of  
the C library functions that are supposed to work  
with long doubles are mapped by the compiler to  
the double versions. (I am sick and tired of having  
to roll my own \<math.h\> functions.) libuuid missing  
or incomplete. [If anyone can tell me a portable way  
to find my machine’s MAC address, that would be a  
kindness.] Files that are missing, in the wrong  
place, or empty. Packages or commands that have been  
dropped with no obvious replacement. Things that  
are where they are supposed to be but just don’t  
_work_ for inexplicable reasons.

All of this is why containers are so popular.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [November 6, 2022, 8:45am UTC](https://erlangforums.com/t/cosmopolitan-erlang-build-once-run-anywhere-possible/2004/3 "2022-11-06T08:45:27Z")

</div>

Looks rather cryptic =)

We just put several architectures to our erlang build and have single distributive compiled for 4 architectures.
