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.



Mix task ‘compile’, documented at 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. ^.^


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


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.


Here’s part of the answer to your question:
and there’s this too:


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 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.


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.


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


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.



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: