-
-
Notifications
You must be signed in to change notification settings - Fork 761
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
Permit FFI modules in subdirectories #1562
Comments
Adding some extra context at @erikareads (on discord)'s request: You can only write ffi code directly inside src/, but we'd find it a lot more useful if i could co-locate ffi files along with the modules that need it:
It'd mean inside wobble.gleam we could write @external(javascript, "./wobble_ffi.mjs", "thing") instead of @external(javascript, "../wobble_ffi.mjs", "thing") and so on. For a concrete use-case lustre has a As lustre gains more CLI commands more of these one-off FFI modules are likely to be necessary so it'd be really great if they could be organised away in a way that makes more sense than how it is currently. |
For Javascript this seems to be the path creation function: gleam/compiler-core/src/javascript.rs Lines 324 to 341 in 4396f9a
It currently assumes that it will be in the top of the project. |
There seems to be a similar function in the typescript.rs file: gleam/compiler-core/src/javascript/typescript.rs Lines 279 to 297 in 4396f9a
|
Has anyone tried to take a stab at implementing this yet? If not, I'd like to give it a shot, I just don't want to step on anyone's toes. |
It's all yours @winterqt !! |
For the Erlang name clashing, is there a reason you couldn't use an absolute name, like the compiled Gleam does anyway? e.g.
And the compiled output is:
That would avoid that problem, and then you'd only have to worry about naming a Gleam module the same as an Erlang one (which would be an issue either way, and would be an issue on the JS target too) |
No, we will not modify the Erlang source code in any way. We do not want to create our own slightly modified version of Erlang, the language should be unchanged whether or not the Gleam build tool is used. |
Question (as someone not too experienced with the Erlang target's inner workings): is this still a problem if the two files declare modules with different names (and thus parsing the files would be needed to avoid clashes)? Or does Gleam force the modules to have the same names as the files they're in? It's also worth mentioning that I've observed that, on the JS target, you can have two files like |
You don't need to parse the module to work out the name, the name is always the same as the file name. The directory name is not used in any way for Erlang modules.
If we don't prevent this from happening in the PR let's open an issue to make sure we prevent this in future. |
Okay thank you, I might be able to add this to my PR then. Though, is this also true for
Good idea. I'll see if the PR would be able to fix this, if not I'll open an issue. |
Elixir has no relationship at all between file names and module names so we can't predict that modules a file will produce. |
Ah bummer. I guess we can't really give a helpful error in that case and just let it error on the Erlang build step instead, right? Though I guess that isn't that bad, as the user would be intentionally doing so. If Elixir automatically joins the modules, that might be even less of a problem. |
I think we'll just have to leave it up to the programmer to manage that for now. |
I was going to add the duplicate With that said, since that's not the case for |
i.e.
src/one/two/three.js
andsrc/one/two/three.erl
.We will need to track Erlang module names to ensure there are no clashes. For example
src/one/themodule.erl
andsrc/two/themodule.erl
in one project is an error.The text was updated successfully, but these errors were encountered: