Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang compilation - Erlang as stand alone executeable

Tags:

is there a way to compile Erlang to be a stand-alone executable? this means, to run it as an exe without the Erlang runtime.

like image 432
qwerty Avatar asked Nov 25 '09 09:11

qwerty


People also ask

Does Erlang compile?

The Erlang compiler is written in Erlang and always available and can compile to either a file or a binary which can be immediately loaded into the system.

Does elixir compile to binary?

You can use Elixir's built-in releases as of Elixir 1.9. It is a lightweight alternative to Distillery. Caveats: It will not create anything remotely like Go does with a single binary executable that you can run almost anywhere. Also your target will have to match the CPU architecture and OS.


2 Answers

While it's possible to wrap everything up in a single EXE, you're not going to get away from having an Erlang runtime. Dynamic languages like Erlang can't really be compiled to native x86 code, for instance, due to their nature. There has to be an interpreter in there somewhere.

It's possible to come up with a scheme that bundles the interpreter and all the BEAM files into a single EXE you can double-click and run directly, but that's probably more work than you were wanting to go to. I've seen it done before, but there's rarely a good reason to do it, so I won't bother going into detail on the techniques here.

Instead, I suggest you use the same technique they use for Python's py2exe and py2app programs for creating Windows and Mac OS X executables, respectively. These programs load the program's main module up into a Python interpreter, figure out which other modules it needs using the language's built-in reflection mechanisms, then write out all those compiled modules along with a copy of the language interpreter and a small wrapper program that launches the program's main module with the interpreter. The directory containing those files is then a stand-alone environment, having everything needed to run the program. The only difference in the Erlang case is that python.exe becomes erl.exe, and *.pyc becomes *.beam. The basic idea is still the same.

You can simplify this if you don't need it to work with any arbitrary Erlang program, but only yours. In that case, you just copy the Erlang interpreter and all the .beam files that make up your program into a single directory. You can make this part of your program's Makefile, for instance.

You can then use your favorite setup.exe or MSI creation method for creating a distributable package that installs this collection of files into c:\Program Files\MyProgram on the end user's system and creates a shortcut for "erl mainmodule.beam" in their Start menu. The end user doesn't care that as part of the program they also get a copy of Erlang. That's an implementation detail.

like image 122
Warren Young Avatar answered Sep 20 '22 15:09

Warren Young


you can use Warp. I've added examples for wrapping an Erlang release.

like image 33
Pouriya Avatar answered Sep 19 '22 15:09

Pouriya