Rebar_mix how to use in erlang rebar projects

Hello! I need to use elixir lib in my erlang project. I add plugin {plugins, [rebar_mix]}. in rebar.config file and add my elixir library in deps. After that I run rebar3 install_deps && rebar3 compile. It fetched and compiled dependencies without problems. Then I ran application and got error ** exception error: undefined function 'Elixir.GenServer':start_link/3. Elixir and erlang installed in system with asdf. elixir 1.7.4, erlang 21.2.7, rebar3 3.9.1

What is wrong with my configurations? Can I find somewhere examples of using rebar_mix?

Thanks! :slight_smile:

Have you added Elixir as a dependency to your Rebar project? I do not think that rebar_mix does that for you.

No, I thought it should use system elixir

It uses the system elixir to compile but depending on how you run the application it might not be able to find elixir.

How are you running your project? rebar3 shell? A release? something else?

According to the projects README, you also need to specify some hooks:

{provider_hooks, [
  {pre,  [{compile, {mix, find_elixir_libs}}]},
  {post, [{compile, {mix, consolidate_protocols}}]}
]}.
1 Like

Oh, and these PRs I forgot about that are probably exactly what OP is looking for :slight_smile:

https://github.com/tsloughter/rebar_mix/pulls

1 Like

I merged the PR that should help with release creation.

2 Likes