2
votes

I'm going over the official Elixir website and learning about Mix at the moment. I'm following their example.

In the document, they mention:

When you compile your source code, Elixir compiles artifacts to the _build directory. However, in many occasions to avoid unnecessary copying, Elixir will create filesystem links from _build to actual source files. When true, :build_embedded disables this behaviour as it aims to provide everything you need to run your application inside _build.

I have few questions about this excerpt:

  1. What is filesystems links? Is it just referring to something like "bin/elixir"?
  2. Can you rephrase "Elixir will create filesystem links from _build to actual source files."? I'm not sure what it means by creating the links to actual source files. Does it mean, it is not building artifats in _build folder but in other place?
  3. Why is it better to put all artifats in _build folder than other places? Is it plainly because it's better to put all artifats in one folder?

    One last question about :start_permanent:

    • In the document, it says :start_permanent option starts your application in permanent mode, which means the Erlang VM will crash if your application’s supervision tree shuts down.. Is it always better to crash the VM when the supervision tree shuts down? What's the motivation behind this?
1

1 Answers

6
votes

This blog post covers the :build_embedded and :start_permanent options in detail.

:build_embedded

:build_embedded enables protocol consolidation, which makes some function calls faster (such as Enum module functions).

It also creates a complete copy of files in the priv directory, eg static assets you may have in priv/static.

During development, you don't need to make a complete copy of these files on every build, it's faster to just link them.

For a production build, it makes a full copy of those files, so that it doesn't need to follow the symlink and making the _build directory self-contained.

:start_permanent

:start_permanent is desirable for production builds of your application, so that all other OTP apps that you depend on (cowboy, postgrex, etc..) are also shutdown and the operating system process terminated.

Without this, other OTP apps will be left running but your main application code will not be, leaving the system in a half-working state.

Terminating the operating system process gives the host monitoring tools a chance to restart the whole system or raise an alert.