phtrivier

phtrivier

Mixing elixir / erlang / alpaca in an umbrella application

I’m trying to integrate an alpaca module with an Elixir umbrella application.

I have no idea how to tackle this, but I think I have the various pieces of the puzzle:

  • a rebar3 project can contain a mix of erlang (.erl) and alpaca (.alp) files
  • the alpaca files can export functions in modules:

E.g, with this module in a my_module.alp file:

module my_module

-- one function that takes a single argument will be publicly accessible:
export double/1

let double x =
  let add a b = a + b in
  add x x

It should export an erlang module named alpaca_my_module, with the double/1 function

  • the rebar3 project will compile the .alp file if it has a rebar.config file like this:
{erl_opts, [debug_info]}.
{deps, []}.

{shell, [
  % {config, "config/sys.config"},
    {apps, [alpatest]}
]}.

{plugins, [
    {rebar_prv_alpaca, ".*", {git, "https://github.com/alpaca-lang/rebar_prv_alpaca.git", {branch, "master"}}}
]}.

{provider_hooks, [{post, [{compile, {alpaca, compile}}]}]}.

When running rebar3 compile in an alpaca project, I manage to produce a file like ./_build/default/lib/alpatest/ebin/alpaca_my_module.beam

  • mix seems to have built-in support for building elixir projects. I’m in an umbrella project, so I tried doing something like this:
project/
  apps/
         my_alpaca_app/
             src/
                 .... . erl
                 my_module.alp
             rebar.config
             mix.exs
          an_elixir_app
             lib/
                foo.ex
  • The mix.exs file for the my_alpaca application is a default one (I have not even changed the list of compilers.)

  • I want to call the double function in my elixir application. So the mix.exs file for my_elixir_app mentions it as an “in_umbrella” dependency:

defp deps() do 
  [ { :my_alpaca_app, in_umbrella: true} ....
  • When I run mix compile in my elixir app, it seems like the erlang part of my_alpaca project is build ; but the alp one is not build (the alpaca_my_module.beam file is not created.)

So my understanding is that mix ignores the rebar.config file entirely.
Does it looks like a good lead ? How would I tell mix to use it ?

  • The next step would be to call the erlang / alp function in my elixir code:
def foo() do
  x = :alpaca_my_module.double(42)
  ... 
end

Should this be the right syntax ?

Most Liked

wojtekmach

wojtekmach

Hex Core Team

I have a toy project that has Elixir, Erlang, LFE, and Gleam child apps all in the same umbrella: https://github.com/wojtekmach/hello_beam and so by that token Alpaca should work too if it’s built by rebar3. If you get it working a PR to hello_beam would be very appreciated! :slight_smile:

wojtekmach

wojtekmach

Hex Core Team
phtrivier

phtrivier

I should have make it clear, but what I’m trying to do is to have only mix projects in my umbrella.

What I really want is to be able to run “mix compile” as usual, and have both the alpaca and elixir code be compiled properly.

OvermindDL1

    October 3

If it’s not a mix project then it shouldn’t be in am umbrella, use a path dependency or so instead and see if that works?

phtrivier:
Should this be the right syntax ?

Yep yep. :slight_smile:

Where Next?

Popular in Questions Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement