rebar3 集成elixir 模块

发布时间 2023-12-27 09:16:48作者: 荣锋亮

社区包含了一个rebar3 的elixir mix 插件,可以方便rebar 使用elixir 模块

参考使用

  • rebar.config 配置
{erl_opts, [debug_info]}.
{deps, [
 % 添加引用
  {decimal, "2.0.0"}
]}.
 
{shell, [
    {apps, [basic]}
]}.
 
% 添加插件
 
{plugins, [rebar_mix]}.
 
{provider_hooks, [{post, [{compile, {mix, consolidate_protocols}}]}]}.
  • 代码使用elixir 模块
    basic_demo.erl
 
-module(basic_demo).
 
-export([demo/0]).
 
demo() ->
    % 注意是Elixir.  开头的
    Result = 'Elixir.Decimal':new(1, 42, -20),
    io:format("Result: ~w - ~n", [Result]).
  • 调用
rebar3 shell 
basic_demo:demo().

效果

 

参考资料

https://rebar3.org/docs/configuration/plugins/#elixir-dependencies
https://github.com/tsloughter/rebar_mix
https://github.com/barrel-db/rebar3_elixir_compile
https://rebar3.org/docs/configuration/configuration/#hooks