gleam
gleam copied to clipboard
Dev dependencies are written into the app list in .app.src
See the gleam.toml
in https://preview.hex.pm/preview/bigi/3.0.0/show/gleam.toml, gleeunit
is only a development dependency. But in the created .app.src
, gleeunit
is included as a dependency application: https://preview.hex.pm/preview/bigi/3.0.0/show/src/bigi.app.src.
Context: I managed to get bigi
compiling in Elixir by putting {:bigi, "~> 3.0", manager: :rebar3}
in mix.exs
, but trying to run fails due to not having gleeunit
. If I edit _build/dev/lib/bigi/ebin/bigi.app
and remove gleeunit
manually, I can open IEx and run bigi
code successfully! :)
zsh/2 486 % iex -S mix
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]
Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :bigi.zero()
0
iex(2)> :bigi.add(1, 2)
3
The compiler (or rebar3?) also warns
===> "/home/nicd/test/gleam_test/_build/dev/lib/gleam_json/ebin/gleam_json.app" is missing kernel from applications list
===> "/home/nicd/test/gleam_test/_build/dev/lib/gleam_json/ebin/gleam_json.app" is missing stdlib from applications list
and indeed kernel
and stdlib
are not in the app files. I'm not sure if that's an issue or not.
I guess this is the place responsible (suitable TODO here :grin:): https://github.com/gleam-lang/gleam/blob/55a4e5881923e5679dde57cf950de389d6e04be4/compiler-core/src/codegen.rs#L114-L138
Whether dev deps are included is controlled by this line: https://github.com/gleam-lang/gleam/blob/55a4e5881923e5679dde57cf950de389d6e04be4/compiler-core/src/build/project_compiler.rs#L520
We could turn it to false
there, but I suppose that would break functionality if the user wants some app to exist in development but not in production (like phoenix_live_reload
type things)? So do we need a dev/prod distinction to proceed with this issue?
Would it ever make sense to include dev deps in prod? Cause the project compiler already has the mode for dev vs prod so unless there is a reason we would want to keep dev deps in prod we could always update that line to check mode != Mode::Prod
instead since dependencies are all compiled in prod mode already
But, do we ever use the prod mode? I was under the impression that we don't have prod builds. That's what I meant by having a dev/prod distinction, i.e. do we need to start using prod builds?
A lighter alternative could be to detect when building for Hex upload and not including dev deps then?
Yeah there are a couple places where the compiler looks at the mode to determine what to do though i know for javascript generation specifically it ignores the mode. For example https://github.com/gleam-lang/gleam/blob/main/compiler-core/src/build/package_loader.rs#L214 the package loader doesn't load test modules in prod. This seems like it would fall under the same category?
Hmm, I guess I'll try it out and see. 👍
I made this change:
diff --git a/compiler-core/src/build/project_compiler.rs b/compiler-core/src/build/project_compiler.rs
index de2f2006..79eea3d6 100644
--- a/compiler-core/src/build/project_compiler.rs
+++ b/compiler-core/src/build/project_compiler.rs
@@ -517,7 +517,7 @@ where
.collect();
super::TargetCodegenConfiguration::Erlang {
app_file: Some(ErlangAppCodegenConfiguration {
- include_dev_deps: is_root,
+ include_dev_deps: self.mode() != Mode::Prod,
package_name_overrides,
}),
}
After running gleam publish
and canceling it, this file is created in build/prod/erlang/bigi/ebin/bigi.app
:
{application, bigi, [
{vsn, "3.0.0"},
{applications, [gleam_stdlib]},
{description, "Arbitrary precision integer arithmetic for Gleam"},
{modules, [bigi]},
{registered, []}
]}.
After running just gleam build
, this file is created in build/dev/erlang/bigi/ebin/bigi.app
:
{application, bigi, [
{vsn, "3.0.0"},
{applications, [gleam_stdlib,
gleeunit]},
{description, "Arbitrary precision integer arithmetic for Gleam"},
{modules, [bigi,
bigi_test]},
{registered, []}
]}.
So it seems to work. Is there something specific I should test? This does not seem to be tested directly as the only mention of include_dev_deps
has it hardcoded in the tests and all the tests pass with the change.
It'd be good to have a test for the contents of the Hex tarball if that's something we don't already have.
There is a test-package-compiler
, but it forces include_dev_deps: true
.