Support for dynamic linking
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
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.
We shouldn’t reinvent the wheel by reimplementing Javy. I’ll give brining dynamic linking to this library a shot.
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 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
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.
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.