Hello! First off, thanks for the work you've been putting into Gleam. Having a statically typed language on the beam is super exciting.
I've been wanting to play around with Gleam for a while, but when I sat down to give it a try I noticed that the compiler is explicitly set up to work with rebar/Erlang projects. Since I come from more of an Elixir background, I was thinking it would be cool to have a mix task that can compile Gleam code as part of an Elixir project. I took a stab at writing a library that works with the compiler as is. It works, but is a bit hacky as the current gleam compiler is set up to use the src, test, and gen folders.
I was thinking of submitting a PR that checked gleam.toml for src_dirs and dest_dir before defaulting back to src, test, and gen. Before I do so, I wanted to make sure this is something that wouldn't disrupt what you're trying to build with this project. If this goes against how Gleam is intended to be used, is stepping on some other plans you already have, or you just plain don't like the idea; please let me know. I'm excited by what I've seen from Gleam so far, and I'm interested to see where it goes.
Hello! Thank you for the words of support. :)
I'm reluctant to make the compiler more complex until we have a good idea of how we want tooling to work in future. The current tooling is to be considered highly unstable and will undergo breaking changes in future.
There's no specific rebar3 support, instead we hackily instruct rebar3 to look in gen/src (and also gen/test if in the test env), and then tell rebar3 to call out to the compiler before attempting compilation itself.
We could do the same for Erlang using the erlc_paths mix project option, but we'd also need a way to get mix to run the Gleam compiler- likely a plugin as mix doesn't have a hook system like rebar3.
Today the quickest route to using Gleam in an Elixir project is probably by creating an umbrella application and creating a rebar3 application within that for the Gleam code.
likely a plugin as mix doesn't have a hook system like rebar3.
Mix/Elixir actually has support for custom compilers that can be added to a project via the :compile key a project's mix config.
I've gotten mix set up, compiling Gleam files, and compiling the resulting erlang files in a test project. The pain point comes from the Gleam compiler looking for files in the src dir, rather than lib.
I totally understand the reluctance to make compiler changes this early for someone's random, hacky project :). I think the solution is probably for me to use a custom build of the compiler that looks at lib instead of src while I play around with things.
mix uses the src directory for erl, yecc and leec files out the box, among others, so I think it makes sense to keep the Gleam in there too. I believe that only Elixir files live in lib currently.
Ahh I wasn't aware mix looks at src for erl files by default. Sounds like it does make sense to keep Gleam files there as well. Thanks for the heads up!
Most helpful comment
Ahh I wasn't aware
mixlooks atsrcforerlfiles by default. Sounds like it does make sense to keep Gleam files there as well. Thanks for the heads up!