gleam-lang/gleam

Elixir external functions don't work when no Elixir modules are present

Open

#1,986 opened on Feb 3, 2023

View on GitHub
 (16 comments) (0 reactions) (0 assignees)Rust (21,417 stars) (960 forks)batch import
discussionhelp wanted

Description

When generating a new Gleam project:

gleam new exffi

And adding an FFI function to Elixir:

import gleam/io

pub fn main() {
  io.println("Hello from " <> cwd())
}

external fn cwd() -> String = 
  "Elixir.File" "cwd!"

Calling the function results in:

exffi:main().
% ** exception error: undefined function 'Elixir.File':'cwd!'/0
%      in function  exffi:main/0 (build/dev/erlang/exffi/_gleam_artefacts/exffi.erl, line 8)

Elixir files are not being generated in the build directory until there's an elixir dependency:

Screenshot 2023-02-02 at 21 00 51

Adding a .ex file to the project generates the files and solves this issue.

Contributor guide