Set compilation target explicitly #1172
Replies: 2 comments 7 replies
-
This could be useful, I am curious about how it might impact tooling and general DX. What do you see as being the main experience for the user that is provided by this additional information? I think we would want to be able to specify multiple supported target. For example the stdlib will support both Erlang and JavaScript. What would the Gleam build tool do if it encounters a package marked as not for the current target? If it errors this may cause problem as packages that support both targets may have deps that are only used for one or the other. Alternatively they may need to provide wrapper 2 packages and a core package to work around this. Would this be limiting? Would we record this on Hex in some way? They do have some amount of unstructured metadata. |
Beta Was this translation helpful? Give feedback.
-
This is done! |
Beta Was this translation helpful? Give feedback.
-
Now that
js
compilation support has been added to the gleam compiler, it might be useful to have some mechanism to optionally specify the intended compilation target of a gleam library/application, this would be useful to remove ambiguity when using/writing code that containsexternal
function calls.There is probably a lot of nuance to this topic with regards to the benefits of being explicit v.s. just letting the compiler figure it out (as well as allowing for conditional compilation?), though I personally tend to favour explicitness when possible.
My suggestion would be to add a
target
field togleam.toml
with current options beingerlang
(orerl
, ...), as well asjs
. The way I see it, this field would only be required when there are anyexternal
functions present in the gleam code.In the case of any dependencies that would have to specify a target, like in wrapper modules for erlang/elixir functionality, the target specified by all dependencies of a library would have to match, and would therefore force a given compilation target for the caller.
I'm sure plenty of other people have opinions/idea on this topic (especially those with more compiler knowledge than myself), and I look forward to seeing where this discussion goes.
Feel free to poke as many holes in my idea as possible 😸
Beta Was this translation helpful? Give feedback.
All reactions