Static Erlang

Dave Cottlehuber dch@REDACTED
Wed Aug 5 21:36:26 CEST 2020

On Tue, 4 Aug 2020, at 19:33, Grzegorz Junka wrote:
> On 04/08/2020 16:32, Łukasz Niemier wrote:
> >> Is it possible to compile Erlang Beam statically
> > Yes

Hi Grzegorz

As Max said, you'll find it almost impossible to not have
a dependency on libc and similar system libraries.

If your intent is (for example) to run your erlang app
inside a vanilla FreeBSD jail or system, Erlang releases
already do this - we ship several elixir and erlang apps
this way already, each into their own jails. Nothing other
than the base FreeBSD OS (and therefore libc) is required
 - not even security/openssl.

These are built during CI to output a standard FreeBSD
package, in our custom repo, and then `pkg install`. The
manifest tells FreeBSD to pull in any custom NIF dependencies
and everything Just Works. NB we're not building these
using the ports tree, but it's a handful of lines of
shell or Makefile to achieve this.

I can share more details of that offline if needed.

> Would you know the configure options that should work?

OTP does support static embedding of some libraries, I've
only done this for Windows, and not recently.


IIRC sometime around R14A this became the default. And
obviously with some work, you could add any additional
library using whatever tricks ERTS does already. But
I am not sure this is worth the effort? GRISP is the
ultimate expression of this, I suppose.

> >> so that when I am doing a release it doesn't require any dynamically loaded libraries on the host to which the release is being deployed?

Yes, so long as you accept your libc dependencies.

> I am not using NIFs. I am just interested in the Erlang runtime. And I 
> need to be able to run it directly on the host, so any containerization 
> won't help - I am assuming a bare host with no packages installed. 
> systemd maybe could be an option but this system doesn't use systemd, it 
> isn't even Linux but this detail shouldn't matter.

Here's a list of runtime dependencies for our app, they're all either
directly required by OTP release itself (ASN1, crypto) and if you're
not using those modules, wouldn't be needed either.

/usr/local/lib/eden/lib/asn1-5.0.12/priv/lib/ => /lib/ (0x800247000)
/usr/local/lib/eden/lib/crypto-4.6.5/priv/lib/ => /lib/ (0x801000000) => /lib/ (0x800247000) => /lib/ (0x800690000)
/usr/local/lib/eden/lib/crypto-4.6.5/priv/lib/ => /lib/ (0x800247000)
/usr/local/lib/eden/lib/crypto-4.6.5/priv/lib/ => /lib/ (0x801000000) => /lib/ (0x800247000) => /lib/ (0x800675000)

If you *choose* to include runtime_tools, you have a few more:

/usr/local/lib/eden/lib/runtime_tools-1.14/priv/lib/ => /lib/ (0x800673000) => /usr/lib/ (0x80068b000) => /lib/ (0x80068f000) => /lib/ (0x8006c1000) => /lib/ (0x800247000)
/usr/local/lib/eden/lib/runtime_tools-1.14/priv/lib/ => /lib/ (0x800675000) => /usr/lib/ (0x80068d000) => /lib/ (0x800691000) => /lib/ (0x8006c3000) => /lib/ (0x800247000)
/usr/local/lib/eden/lib/runtime_tools-1.14/priv/lib/ => /lib/ (0x800675000) => /usr/lib/ (0x80068d000) => /lib/ (0x800691000) => /lib/ (0x8006c3000) => /lib/ (0x800247000)

This package is deployable on FreeBSD as a single archive, with no
additional dependencies, so long as you keep the ABI/architecture.

I can share more details of that offline if this is of interest.

If you're trying to do something more complicated, you're going
to need to share some more details on why this is absolutely
necessary. Perhaps the GRiSP team have more experience to share.


More information about the erlang-questions mailing list