diff --git a/lib/mix/tasks/gleam_compile.ex b/lib/mix/tasks/gleam_compile.ex index 4dcc0a2..46dc255 100644 --- a/lib/mix/tasks/gleam_compile.ex +++ b/lib/mix/tasks/gleam_compile.ex @@ -78,6 +78,23 @@ defmodule Mix.Tasks.GleamCompile do else Mix.shell().info("Gleam output directory #{gleam_output} does not exist") end + + # Also copy Gleam stdlib files + gleam_stdlib_dir = "build/dev/erlang/gleam_stdlib/ebin" + if File.exists?(gleam_stdlib_dir) do + Mix.shell().info("Copying Gleam stdlib files...") + + gleam_stdlib_dir + |> File.ls!() + |> Enum.filter(&String.ends_with?(&1, ".beam")) + |> Enum.each(fn beam_file -> + src = Path.join(gleam_stdlib_dir, beam_file) + dest = Path.join(ebin_dir, beam_file) + File.copy!(src, dest) + end) + + Mix.shell().info("Copied Gleam stdlib files") + end else # Last resort: Check for pre-compiled BEAM files in priv/gleam Mix.shell().info("No Gleam compiler available, checking for pre-compiled BEAM files...") @@ -88,16 +105,23 @@ defmodule Mix.Tasks.GleamCompile do if File.exists?(priv_gleam) do File.mkdir_p!(ebin_dir) - # Look specifically for our Gleam module - beam_file = "aprsme@encoding.beam" - src = Path.join(priv_gleam, beam_file) - - if File.exists?(src) do + # Copy all Gleam-related BEAM files + priv_gleam + |> File.ls!() + |> Enum.filter(fn file -> + String.ends_with?(file, ".beam") and + (String.starts_with?(file, "gleam") or String.starts_with?(file, "aprsme@")) + end) + |> Enum.each(fn beam_file -> + src = Path.join(priv_gleam, beam_file) dest = Path.join(ebin_dir, beam_file) File.copy!(src, dest) Mix.shell().info("Copied pre-compiled #{beam_file} from priv/gleam") - else - Mix.shell().error("Pre-compiled #{beam_file} not found in priv/gleam") + end) + + # Check if we got the main module + if not File.exists?(Path.join(ebin_dir, "aprsme@encoding.beam")) do + Mix.shell().error("Pre-compiled aprsme@encoding.beam not found in priv/gleam") end else # Try to copy from dev build if available diff --git a/mix.exs b/mix.exs index 397b28e..55b778d 100644 --- a/mix.exs +++ b/mix.exs @@ -20,6 +20,11 @@ defmodule Aprsme.MixProject do plt_file: {:no_warn, "_build/dev/dialyxir_erlang-#{:erlang.system_info(:otp_release)}_elixir-#{System.version()}_deps-dev.plt"} + ], + releases: [ + aprsme: [ + steps: [:assemble, ©_gleam_files/1] + ] ] ] end @@ -142,4 +147,25 @@ defmodule Aprsme.MixProject do # {:aprs, github: "aprsme/aprs", branch: "main"} # end end + + # Copy Gleam BEAM files to the release + defp copy_gleam_files(release) do + app_dir = Path.join([release.path, "lib", "aprsme-#{release.version}", "ebin"]) + File.mkdir_p!(app_dir) + + # Copy from priv/gleam if available + priv_gleam = "priv/gleam" + if File.exists?(priv_gleam) do + priv_gleam + |> File.ls!() + |> Enum.filter(&String.ends_with?(&1, ".beam")) + |> Enum.each(fn beam_file -> + src = Path.join(priv_gleam, beam_file) + dest = Path.join(app_dir, beam_file) + File.copy!(src, dest) + end) + end + + release + end end