-
Notifications
You must be signed in to change notification settings - Fork 225
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
Generate Typed Erlang/Elixir/Gleam Definitions from Rust #628
Comments
These are really separate subjects. Check out #614, that's the avenue I'm currently exploring. The best option to make the signatures survive is probably to add another separate exported C function at compile time. |
I was literally just now searching for a solution to this problem 😄 I found this project, which might be interesting: https://github.com/zefchain/serde-reflection/tree/main/serde-generate |
One problem that we have that Generating suitable signatures is a bit more tricky. We can extend the @bjorng Would specifying such a function via an EEP be interesting? I guess extending |
@filmor, thanks a lot for the quick response!
Sorry, I must admit that I am unfamiliar with this. So, you are saying you want to generate the BEAM-side definitions via inspecting the NIF dylibs, after compiling to them?
My understanding is Rustler has that signature information during macro expansion, correct?
These ideas seem simpler to implement except for the problems I mentioned earlier, though I am not sure what larger problems there are with these approaches. |
I'm sorry, but you can't simultaneously say that you aren't familiar with the details of NIF libraries and then claim you found a "simpler way". Of course I thought about just injecting data into the library file. But you can not access this data without a PE/ELF/MachO binary reader (yes, Windows, Linux and macOS use different file formats) which I deem complete overkill for this exercise. /edit: I also considered writing a file during build, but apart from Also, no, Rustler doesn't (necessarily) have the full type information during macro expansion. The macro expansion (like in Elixir) runs on a "token stream", so just a little bit better than on bare text. We might be able to extract information at runtime(!) from this by extending |
Okay, I was wrong. I apologize. We don't have And… yes, proc macro side effects are unintended and build scripts are the ones for them instead. Then, it indeed seems to be fewer troubles to inject the data into the dylib, and then loading it back out with your helper CLI. Footnotes
|
Just writing down some notes:
|
What if we can, @filmor? If we feature gate Also, would there be any advantages manipulating the types on the BEAM instead of in Rust? |
So, what is preventing this?
It seems that we do have the source of truth from the Rust side.
nif
,NifStruct
, and other Rustler macros have access to the typed raw arguments/fields; they just do not store that information in theNif
struct, yet. If we modify the macros to store those information, we would have them all inrustler::codegen_runtime::inventory::iter::<rustler::Nif>()
when callinginit!
, right?Code generation on the BEAM side would be more complicated, though. A few problems I can think of:
In #85, there seemed to be interest from @tsloughter and @lpil, but the
rebar3_run
andrebar3_cargo
mentioned there seem to have staled. I guess it would be much better to just integrate most of the code generation into Rustler itself.The text was updated successfully, but these errors were encountered: