wasmex icon indicating copy to clipboard operation
wasmex copied to clipboard

Support for dynamic linking

Open munjalpatel opened this issue 2 years ago • 4 comments

wasmtime supports dynamic linking using —preload. Is dynamic linking supported by this library?

Example use case: https://github.com/bytecodealliance/javy#creating-and-running-a-dynamically-linked-module-on-the-cli

munjalpatel avatar Jun 03 '23 17:06 munjalpatel

Hey @munjalpatel thanks for your question, it's a good one! :)

Wasmex does currently not support dynamic linking between WASM modules. But if you're up to implement that support, I'd be happy to review a pull request. I'd be happy to give some pointers, if you want to tackle this topic.

A workaround is to implement all functions in the javy_quickjs_provider_v1 namespace in Elixir and pass them in as imported functions to my_code.wasm from your linked example. But I see that it's probably a (fun) challenge to implement javy again in pure elixir when it is already implemented in another WASM file.

tessi avatar Jun 03 '23 22:06 tessi

We shouldn’t reinvent the wheel by reimplementing Javy. I’ll give brining dynamic linking to this library a shot.

munjalpatel avatar Jun 05 '23 03:06 munjalpatel

Curious if this is still the case as it may limit us switching to wasmex. Happy to contribute the feature if it's not done!

bhelx avatar Jun 28 '24 15:06 bhelx

@bhelx I believe this still needs implementation.

If I am reading the code correctly, I think we need to instantiate the module to link with the same linker before the instantiation of the user-provided module here: https://github.com/tessi/wasmex/blob/863cb01aba128420ed7d4ba6b755c2a9c421afef/native/wasmex/src/instance.rs#L65

Reference: https://docs.wasmtime.dev/examples-rust-linking.html

munjalpatel avatar Jun 28 '24 17:06 munjalpatel

Yes, I can look into it a little bit more. Would be curious what @tessi thinks the API should be before we propose any changes. We could expose some more of the bits of linking to the caller, or we could create a datastructure that you pass and the rust code ties everything together. We do something similar in extism but we're trying to abstract away the runtime interface so that may not be appropriate here.

bhelx avatar Jun 28 '24 20:06 bhelx

Would be curious what @tessi thinks the API should be before we propose any changes.

thanks! Actually I already looked into @munjalpatel 's PR on the topic and love the start 💛 . I gave some inputs on API design on my review. So there is a discussion over in #596 - but I believe it shouldn't be too hard to implement either way.

tessi avatar Jul 03 '24 10:07 tessi