-
-
Notifications
You must be signed in to change notification settings - Fork 753
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 files in subdirectories #3601
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
You'll see there's integration tests in the test directory which can be updated with nested FFI files
29b67b1
to
0880a75
Compare
a7903ba
to
cb3980e
Compare
Problem: My handmade recursive directory walker is too naive and can enter infinite symlink loops. I'll probably add a new method to |
5da6877
to
df8cbd8
Compare
Alright, I've made the implementation more robust (it also now supports copying nested Erlang modules), added detection of conflicting |
Hello, thanks for taking this on, this is lovely <3 for FFI interop! In case this is desired and-or not yet considered: Can we enforce some namespacing on Erlang, Elixir and JavaScript modules that maps to the directory structure and else throw a compiler error? Edit: ... if possible, this might also make this check obsolete?
|
I'm not sure that would be desirable since the main point of FFI is to have full control over what the final transpiled code does. Besides, we would have to parse all Erlang files, though I guess we could do with some regex in this case. But I think it's more a matter of flexibility, and the error just tells you if you ever mess it up somehow. The error is also not perfect since I guess it's theoretically possible for you to shadow some module from some other package. But it's an attempt. |
maybe it could warn. |
I think this is fine to be honest... Forcing people to name their modules like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you.
It seems now that there's a concept of directories in the in memory file system and also the OS file system, and each is responsible for implementing traversal. I think it would make sense to remove this duplication and instead to have the trait know nothing about directory walking and then the walking logic depends on the trait and is shared between all implementations.
If I understood correctly, you are proposing making a dir walking function which uses only the trait's Although I guess a re-implementation will be needed if we add symlinks to the in-memory FS down the road, so we could alternatively consider searching for existing platform agnostic implementations and using that, or even just re-implement while attempting to avoid reinventing the wheel as much as possible, e.g. by using special data structure crates if needed. Still, I'm not fully aware of all edge cases to know whether we would be able to match existing OS-specific implementations in terms of not only performance but also correctness. |
Yes, that's right. We should not have two implementations of the same thing, and removing a dependency is beneficial for maintenance. Having one less dependency to verify for the EU Cyber Resilience Act is nice too! I'm not worried about correctness seeing as this is a trivial algorithm, will be fine. |
By the way, I believe this is very close to completion (the dir walker algorithm was already pushed, but I haven't tested it well yet) - I'll be picking this up again very soon, once I have a bit more time :) |
ea4fbd3
to
7410d22
Compare
3808565
to
977041b
Compare
Ready for another look 😄 The dir walker has been implemented with symlink loop detection. I've switched other places using recursive search to use the dir walker. Try it out :) I've also made a few fixes and explicit design decisions in the implementation of directories in IMFS. Of note, I now ensure the root path always exists, for consistency. (We don't really check for this anywhere at the moment though, so I can remove that, but I felt like not leaving a time bomb for the future here 😄.) |
Ideally, `src/abc.gleam` and `src/abc.erl` would cause an error. However, this can actually occur legitimately when downloading a Hex package with precompiled `.erl` source files, which would trigger false positives. Wonder what would be the best way to detect this situation, but doesn't seem trivial to solve.
- Test header file in separate subdir - Test parent folder ffi in Erlang
- Prevent problems with infinite symlink loops
add mjs bug fix to changelog update changelog to include erl ffi files update changelog with js ffi change
We were previously including all paths in the filesystem, which included, in particular, the root. Therefore, the "initial files" included the root directory, causing everything to be deleted, not only the initial files.
Closes #1562
Still WIP (finishing the details regarding the duplicate module check)Changes:
@external(javascript, "./file.mjs", "function")
. For Erlang, you'd use the module's name as usual..erl
files with the same name exist within the project, as Erlang cannot have duplicate modules.is_directory
function would returntrue
for files andread_dir
would also list the directory itself, causing tests to enter infinite recursion and crash.)Potential improvements:
@external
with relative paths in JS (I tested locally with.mjs
with node.js, Deno and Bun and it worked, but could be worth it to test other potential edge cases). Let me know where would be the best spot in the codebase to do so..gleam
file's generated code (.mjs
or.erl
).