Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Add gleam support to Mix #14262

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Papipo
Copy link

@Papipo Papipo commented Feb 13, 2025

This PR adds support for the gleam language.

  • Support for gleam.toml in path deps
  • Support gleam in deps loader.
  • Support for gleam in deps.compile
  • Require specific gleam binary version (hardcoded to 1.9.0 for now, see below)
  • Handle absent gleam binary
  • Support git deps (support for them in gleam is in main already but not yet released)
  • Setup gleam on CI (Otherwise gleam tests will be skipped).

Notes:

  • Packages having a gleam binary version requirements are handled automatically when executing gleam compile-package.
  • The gleam binary version requirement is hardcoded because I could just try to run gleam export package-info but I can't know the reason for a bad exit status (maybe the dep path was wrong and the command was run in a dir without a gleam.toml).
  • The required command to export information about gleam packages and their deps is not yet released.

@Papipo
Copy link
Author

Papipo commented Feb 17, 2025

@josevalim when working on this I was always thinking of erlang target packages, but it would be nice to be able to use javascript ones as well (ie. to use them in Phoenix frontend). Not sure how we can handle that, any hints?

@josevalim
Copy link
Member

It should be possible because we use heroicons, a regular JS package, as a dependency on Phoenix applications. So we could probably support a :gleam_targets or similar option that is used by by deps.compile? You will probably need to set app: false true, similar to how heroicons are added.

@lpil
Copy link
Contributor

lpil commented Feb 17, 2025

Hello! You shouldn't need to do anything special target-wise as Gleam performs dead code elimination for code that is for other targets.

@josevalim when working on this I was always thinking of erlang target packages, but it would be nice to be able to use javascript ones as well (ie. to use them in Phoenix frontend). Not sure how we can handle that, any hints?

I would not expect Mix to become a front-end build tool by adding Gleam support. I think the workflow should be the same as it is today etc, with the desired build tool (esbuild, webpack, gleam etc) being run as a Phoenix watcher.

Adding frontend dependencies to the BEAM application dependency tree would either be wasted work compiling and managing them, or the programmer would need to go through every dependency in the lock file and add configuration to their mix.exs for each one they don't want to use on the backend.

We are going to #14262 (comment), so I also need the target config, if any. I think that just exporting everything is the best bet.

There is no such config. A Gleam package doesn't have an explicit target, each function in the public API is available on Erlang, JavaScript, or both, and they get either compiled or eliminated as needed. Whether a package is for Erlang or JavaScript is typically a matter of how the dependant is using them, not a matter of the configuration of the dependency.

There is a target flag in gleam.toml, but that is "if I run code from this page (almost always the tests) what target should be used by default, unless otherwise specified".

@Papipo Papipo force-pushed the add-gleam-compiler branch 2 times, most recently from 8c06e6e to b91ae71 Compare February 20, 2025 11:32
- Add Mix.Gleam module
- Add specific gleam binary version requirement
- Rely on `gleam export package-info`
@Papipo Papipo force-pushed the add-gleam-compiler branch from b91ae71 to c181ecd Compare February 20, 2025 11:34
@@ -269,6 +269,15 @@ Enum.each(fixtures, fn fixture ->
File.cp_r!(source, dest)
end)

## Set up Gleam fixtures

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should probably skip gleam tests if gleam is not installed, right?

Copy link
Author

@Papipo Papipo Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I guess I need to add gleam to CI (although I need to wait until my gleam PR is merged and released).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants