Hacker News new | ask | show | jobs
by toast0 902 days ago
> Elixir does not have cross-compiling.

Elixir compiles to beam files, like Erlang, right?

I was pretty sure beam files are bytecode and not platform specific?

1 comments

You're right that Elixir source code compiles to BEAM bytecode, however, if you run `mix release`, you need to ensure that the release runs on the same target OS and OpenSSL version. My aim was to build a `mix release` on my M1 Mac to run it on an x86-64 server.

From the docs [0]:

> Once a release is assembled, it can be packaged and deployed to a target, as long as the target runs on the same operating system (OS) distribution and version as the machine running the mix release command.

The `mix release` command outputs a directory containing your compiled Elixir bytecode files, along with the ERTS (Erlang Runtime System). The ERTS it bundles is only for your host machine's architecture. Another point to remember is that some dependencies use native NIFs, which means they need to be cross-compiled too. Hence it's not as easy as replacing the ERTS folder with one for another architecture in most circumstances.

There's a project that aims to alleviate these issues called Burrito [1], but when I tried it, I had mixed success with it, and decided not to use it for my deployment approach. It looks like Burrito has matured since then, so it would be worth taking a look into if you need to cross-compile.

The gist is, while possible, its significantly harder to get an Elixir release running on another architecture than say is the case for Go.

[0] https://hexdocs.pm/mix/1.16.0/Mix.Tasks.Release.html [1] https://github.com/burrito-elixir/burrito