Question

I wanted to integrate Elixir into our project, and the good old codes don't use rebar, so I think writing the rules for building .ex files into Emakefile may be a good idea, yet the man page here didn't mention anything relevant.

Edit:

Our team works mainly in Windows environment, but the deployment will be done on Linux servers, so I need a cross-platform solution. Since Erlang itself is cross-platform, I wanted to do it with erl -make command.

Of course I can write a Makefile, but then I'll need a build.bat or something alike to build the code in our developing environments, since we don't have make command on our dev' machines.

Anyone have a better idea?

Update:

In case anyone wants to know, I'm doing it this way:

  1. Copy the lib/elixir directory in the Elixir source tree to our source dir, say some_project/src/tools/elixir.
  2. Add some_project/src/tools/elixir/src/elixir_transform.erl and some_project/src/tools/elixir/src/* to the Emakefile, in that order. Set the output dir to some_project/ebin (All the other .beam files are located there).
  3. Copy src/elixir.app.src in the Elixir source tree to some_project/ebin/elixir.app, and edit it to fix the version code.
  4. Build the Erlang code by running erl -pa ebin -make, in some_project dir.
  5. Build the Elixir compiler by running erl -pa ebin -s elixir_compiler core -s erlang halt
  6. Now we have a working Elixir environment in our code, and I use the following escript to build our custom .ex files:
%%! -pa ./ebin
main(_) ->
    ExList = [ 
        <<"source_1.ex">>,
        <<"source_2.ex">>,
        <<"source_3.ex">>],
    application:start(elixir),
    gen_server:call(elixir_code_server, {compiler_options, [{docs, true}, {debug_info, true}]}),
    [elixir_compiler:file_to_path(F, <<"./ebin">>) || F <- ExList],
    erlang:halt(0).
Was it helpful?

Solution

If you want to explicitly compile Elixir, I would go with the Makefile approach since it will always be supported by Elixir. However, I would recommend the precompiled binaries or even assume Elixir is installed in each developer machine. You can even add a task to your Emakefile to guarantee everyone is using the proper Elixir version.

Finally, about compiling your own Elixir code, I would recommend simply using mix. mix is a binary that ships with Elixir and you can simply do ./src/tools/elixir/bin/mix compile from your Emakefile.

In case using mix is not possible, you should use the parallel compiler, since it will compile files using all cores available in your machine and it will automatically detect and solve dependency in between files. Here is an example of calling the parallel compiler from erlang:

https://github.com/basho/rebar/pull/347/files#L1R62

The API is very simple. It expects a list of file names to compile as binary and the directory to output files to as another binary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top