Using mix to compile other languages

How good is mix in compiling other languages when building an application? I am, of course, thinking of LFE, but Erlang or C are also interesting. Can someone point towards where this is documented?

:grinning: And wouldn’t it be wonderful if I could write the mix spec file in another language, say why not LFE. :grinning: Just teasing.

Robert

3 Likes

Mix task ‘compile’, documented at http://elixir-lang.org/docs/stable/mix/Mix.Tasks.Compile.html takes a list of compilers to compile with, defaulting internally with Elixir as far as I recall. But I have an extra compiler in my program, here is the relevant part of my Mix.exs file :slight_smile: :

      compilers: [:phoenix, :gettext] ++ Mix.compilers,

So that adds in some phoenix and gettext special compiler things. I have another project that made its own compiler to compile ASN1 files (using Erlang’s stock ASN1 compiler). It is pretty easy to make new compilers, just define the module and define it in the compiler list (such as a Mix.Tasks.Compiler.LFE or so). :slight_smile:

But yes, LFE would be quite easy to add as a supported compiler in Mix, just depend on the dependency, have the compilers list add it in (:lfe!), and done for the user. :slight_smile:

No clue about a Mix.lfe file though. ^.^

Hmm, actually you could probably make a call from a Mix file that includes a Mix.lfe file if you really wanted. ^.^

2 Likes

Serious question–what about rebar? Would rebar handle your use case as well?

2 Likes

I’ve been curious about something, is there any way to use/compile elixir apps and/or hex dependencies in rebar and if so how? It would be nice to start integrating some elixir into some of my old servers.

2 Likes

Here’s part of the answer to your question: https://hex.pm/docs/rebar3_usage
and there’s this too: http://www.rebar3.org/docs/hex-package-management

3 Likes

Awesome, will have to upgrade rebar in those projects (still using the very first rebar as I recall, and Makefiles…, they are old…). Perhaps I should just make the jump and overhaul it all to Mix as it handles erlang fine too…

I just ran across GitHub - yrashk/rebar_elixir_plugin: Elixir Plugin for Rebar for compiling elixir in rebar, but it seems very old and likely stale I am guessing… Probably better to just port to Mix when I work on them again.

2 Likes

Yeah for whatever it’s worth, there is a Chocolatey Nuget package for
Rebar3 because at one point I needed R3 on my windows box. I try to keep it
up to date too.

3 Likes

Yes, I saw that you can add compilers but I couldn’t find how such a compiler interface should work.

2 Likes

A compiler is a task that implements the mix task behaviour [1] and returns :ok | :noop from the run/1 function depending on if the compiler compiled anything. You can take a look at other compilers, for example the erlang compiler [2].

It would be tricky to allow other languages for the mix.exs file because mix would have to know how to compile it out of the box. The project module registers itself with meta programming, so it would not be possible to write in Erlang, although LFE might be able to do it.

[1] http://elixir-lang.org/docs/master/mix/Mix.Task.html
[2] https://github.com/elixir-lang/elixir/blob/master/lib/mix/lib/mix/tasks/compile.erlang.ex

5 Likes

Thanks, I will check out the compiler modules.

I hadn’t expected to write the mix spec in other languages, there are limits to how far you can go. :slight_smile:

2 Likes