简体   繁体   中英

Can Elixir or Erlang programs be compiled to a standalone binary?

It says that Elixir has a tool called elixirc and Erlang has a tool called erlc to compile modules for use. It says immediately after this that you can then run code with the elixir command line tool.

Is there a way to compile a binary executable with Elixir or Erlang? (one which I can chmod +x binary_name and then run from the same directory with ./binary_name )

Escripts support that to some extent but you still need Erlang installed in your machine. See this answer for more information: Elixir or Hex portable package format?

Make sure you checkout Distillery . It does what you need, without having to deal with Rebar.

Add this to your mix.exs file's dependencies then run mix release .

defp deps do
  [{:distillery, "~> 0.9"}]
end

Their documentation is great:

You can use tools like rebar to generate a release that also contains the erts, which makes it possible to run said release on a machine where erlang is not installed. But the erts included corresponds to the operating system on which the release was built, ie windows binaries if built on windows.

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.

To build a release run:

mix release

Read more here: https://hexdocs.pm/mix/Mix.Tasks.Release.html

There are a few tools now that allow you to create a self contained executable binary that doesn't require any dependencies on the target machine. They support multiple platforms.

Bakeware: https://github.com/bake-bake-bake/bakeware

Burrito: https://github.com/burrito-elixir/burrito

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM