Support Build Time Config / Application Environment Config #4732
Replies: 2 comments 4 replies
-
This would mean 2 step compilation once for config and then another time with the result of whatever config produced? What about one of those ways to go about it:
|
Beta Was this translation helpful? Give feedback.
-
Elixir's config DSL is a way to write to OTP application configuration before code is compiled, so we want a way to do the same rather than anything specific to Elixir. How do Erlang projects do this? How would different environments work here? In Elixir's Mix there is the concept of dev, test, and prod. Would this have implications for OTP releases built with Gleam? Or |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Gleam supports compiling Elixir dependencies and Elixir files.
In Mix projects, configuration can be applied at build time, through
config/config.exs
, which Mix reads into the application environment before compiling the project, see: https://hexdocs.pm/mix/Mix.html#module-build-time-configuration.Obviously this is not 'the Gleam way', in a Gleam project configuration should be applied explicitly by passing it to functions at runtime, however some Elixir packages that one may want to use from a Gleam project must be configured this way.
For example, I am using the elixir package
oban
in my project, which usespostgrex
(through ecto) to communicate with a Postgres DB.postgrex
by default wants to use the Elixir modulejason
for it's JSON encoding functions, but it can be configured to use the built-in JSON module of OTP27, this configuration however must be applied at build time, probably because it's used in macros, see: https://github.com/elixir-ecto/postgrex?tab=readme-ov-file#json-supportIt would be great if the Gleam compiler allowed configuring Elixir packages this way, so that they can be used more easily from Gleam.
One potential way to do this would be by supporting the same configuration convention as Mix, reading a config file at
config/config.exs
before building elixir modules.Beta Was this translation helpful? Give feedback.
All reactions