rebar_gleam icon indicating copy to clipboard operation
rebar_gleam copied to clipboard

New compiler API

Open lpil opened this issue 3 years ago • 1 comments

I'm looking to write a new rebar3 plugin for the new compiler API

The API

The API is to be called once per Erlang application within the project, starting with the left applications that have no deps, up to the root, so that dependancy modules are compiled before dependant modules.

It looks something like this:

gleam compile-package \
  --name app_name \
  --src directory/containing/gleam/files \
  --out directory/to/write/to \
  --lib path/to/out/dir/of/dep \
  --lib path/to/out/dir/of/another/dep # ...etc

It reads metadata files from the --lib directories for type information from already compiled Gleam applications, then it reads all the Gleam files from --src, then it writes compiled Erlang files and metadata files to the --out directory.

rebar3 integration

I have been looking at the rebar_compiler behaviour, but it seems to be focused on compiling individual files, but the Gleam compiler operates at the application level. https://github.com/erlang/rebar3/blob/dd9b8b1f41520c307f08b6005eb77ce70d54ee42/src/rebar_compiler.erl#L34

I found a project_builder concept here. It is just a build/1 function that returns ok or an error tuple.

https://github.com/erlang/rebar3/blob/dd9b8b1f41520c307f08b6005eb77ce70d54ee42/src/rebar_state.erl#L446

Questions

How does the project_type field get set? https://github.com/erlang/rebar3/blob/73aa64fb342ef76bf6fc4d1734c6df711bebe5ab/src/rebar_prv_compile.erl#L326-L339

How do we invoke the normal rebar3 build process after the Gleam project builder has run?

@tsloughter If have a spare moment I would be very grateful if you could share whether you think I'm going in the right direction. Thank you! 🙏

lpil avatar Mar 23 '21 18:03 lpil