-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support Host Functions #20
Comments
Since we have a If I am a plugin developer, and I want to to call some For exports I see that your code reference looks for a module.exports by eval some JS which seems fairly reasonable to me. |
Yes, that's a good point. I think putting the imports on the Host object or having another global makes sense to continue with. So I'd be open to any of those options. The tricky issue will still be getting the imports defined into the wasm file. So we'll still need to parse something ahead of time and do a similar trick we do with exports. We could also have some conventional structure you're expected to define as a global in the top of your module. Kind of like how rust works with #[host_fn]
extern "ExtismHost" {
fn hello_world(input: String) -> Json<Output>;
}
// ^ that gets expanded to this:
extern "C" {
fn hello_world(input: i64) -> i64;
} The compiler will need to know what all the imports are that the plugin needs and what the wasm type signature of each host function is. So it will need to parse the JS (or wherever you want to put these declarations), look for these imports and signatures, then compile in the imports into the wasm binary. |
Started work on this and we have a new proposal extism/proposals#16 |
I believe we can call this done |
We want the JS-PDK to support host functions. They should appear as imports in the JS world. We could come up with some kind of convention like:
But the host won't be able to provide them unless they make it into the wasm binary in the imports table. We could try a similar trick to exports. What it does is at compile time, it parses the javascript and looks for the exports, then it generates some "shim" wasm instructions that eval the function by name: https://github.com/extism/js-pdk/blob/main/crates/cli/src/main.rs#L115
Then it adds the exports to the exports table pointing at the shims: https://github.com/extism/js-pdk/blob/main/crates/cli/src/main.rs#L115
We could try something similar with imports. What might make it tricky is, i think, the function indices in the module start with imports, so you can't really append to them without re-writing every function index.
At this point, we're basically writing and maintaining our own linker. So perhaps we should look into a way we can use a tool to statically link the wasm modules at compile time and handle all this merging and re-indexing of functions.
This work may collide with #19 if we decide to go down that path.
The text was updated successfully, but these errors were encountered: