Using a local Gleam library inside an Erlang + Rebar3 project

I’m looking for ways to add Gleam code into a project that already uses Erlang/Rebar3, I’ve noticed that rebar_gleam kind does what I want but it is archived, also Gleam compiles to Erlang so it seems feasible.

My idea is creating another lib that gets imported by the main application, to rewrite a couple sections that would benefit from the ML-like type system that Gleam boasts. This is my current project structure:

$ tree -I '_build|maps|*.dump' server
server
├── apps
│   └── server
│       └── src
│           ├── character.erl
│           ├── dispatcher.erl
│           ├── dispatcher_sup.erl
│           ├── map.erl
│           ├── map_generator.erl
│           ├── player.erl
│           ├── player_sup.erl
│           ├── registry.erl
│           ├── server.app.src
│           ├── server.erl
│           ├── server_sup.erl
│           ├── types.hrl
│           ├── world.erl
│           └── world_sup.erl
├── config
│   ├── sys.config
│   └── vm.args
├── database
│   ├── main.down.sql
│   ├── main.input.sql
│   ├── migrate_down.sh
│   ├── migrate_input.sh
│   ├── migrate_up.sh
│   └── migrations
│       ├── 000001_schema.sql
│       ├── 000002_player.sql
│       ├── 000003_map.sql
│       ├── 000004_character.sql
│       └── 000005_equipment.sql
├── lib
│   └── database
│       ├── rebar.config
│       └── src
│           ├── database.app.src
│           ├── database.erl
│           ├── database_utils.erl
│           └── postgres_m.erl
├── rebar.config
├── rebar-deps.nix
└── rebar.lock

Is this somehow supported? Or is there a better a way to pull this that wasn’t mentioned?

1 Like

Hello! I don’t think anyone has added support for Gleam via a plugin or such, so there’s no good way to add Gleam code to a rebar3 project. You could possibly use the Gleam build tool instead (it can compile Gleam, Erlang, and Elixir), but that would be quite a large workflow change.

1 Like

Thanks for the reply @lpil. I’ll check if I can leverage the Gleam build somehow and post some report here later.

@schonfinkel what was wrong with the rebar_gleam plugin that didn’t work for you?

Ah, it looks like you might could also configure your Erlang project to build with Mix and use mix_gleam… would that work for you?

Well, for starters its archived and from 4 years ago (as of now).

Might work, but I want to avoid moving from rebar3 as I’m also mixing rebar3 + Nix for pure builds.