-
Notifications
You must be signed in to change notification settings - Fork 39
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
Wasm module annotation (low level/C-like bindings) #690
Conversation
cdb8f42
to
accfe61
Compare
I like the overall direction here. I have some hesitation about the always-generated This will be the public API for a WASM module, so it seems better if this could be hand-written, or maybe generated once and hand-maintained. This would allow better method names (if needed), parameter names, Javadoc, etc. The generator can then create the implementation of the interface. The default methods that call |
Thanks @electrum for the feedback!
I thought about this, in my experience, the user would simply provide more convenient overload over the generated methods, or, alternatively, wrap the lower level API with an additional class.
Agree, I just went for the most straightforward solution at first, I think that this can be a fix in a follow up PR, wdyt? |
accfe61
to
986c11a
Compare
Finally found the time to finalize this effort. The updated diff of opa is available at the link: StyraInc/opa-java-wasm@main...andreaTP:try-wasm-module and there are tests for most code paths. @electrum to answer this:
Here we are only generating interfaces, the user can use them or not, start from the generated code to roll his own implementation etc. |
I'd say that this fixes #482 |
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.
considering this is still experimental, I'd say it's good to go, we can iterate further as we go :)
Opening to hear feedback before I stabilize the implementation with proper tests etc. etc.
Here, as discussed a few times, I'm generating low level(C-like) bindings to give type safe interfaces to the user.
The diff itself is not very interesting, but I encourage to test out the behavior locally, this is what I got running it on OPA (make sure to open the
OpaWasm
file, and, locally, the files generated by the annotations):StyraInc/opa-java-wasm@main...andreaTP:try-wasm-module
This implementation is not very opinionated, and there is space for a more seamless integration(leaving to the user less wiring), but is a good "toolbox" approach to the problem imho.
The
WasmModuleInterface
annotation generates 3 things (examples from OPA):_ModuleExports
an interface that holdsdefault
implementation of the Wasm module export section, i.e.:_ModuleImports
maps the low level module imports and group them by module name, e.g.:ModuleImports
interfaces, i.e.:I'm not sure the interaction with
HostModule
is ideal (but I might be overlooking it).I'm pretty happy with the
ModuleExports
encoding and it saves a lot of upfront work when dealing with a new wasm file.The
ModuleImports
section acts more as an implementation guideline and might benefit from being more opinionated.Happy to hear feedback to finalize the PR!