Search code examples
rustwebassemblywasm-bindgen

Is it possible to do dynamic linking in WebAssembly with Rust?


I'm making a Turing-complete DSL in Rust for the web using wasm-bindgen. I want the ability to download arbitrary WASM code from the web and then use functions from that file in my DSL. Some sort of dynamic linking with an equivalent of dlopen is what I have in mind.

I have no idea how to actually achieve this though.

From reading the WebAssembly docs I get the impression that it should indeed be possible but I'm not knowledgeable enough to understand the details of the process from this document.

There is a chapter in the wasm-bindgen reference detailing how to instantiate WebAssembly modules from inside WebAssembly modules!, but this seems to do it via JavaScript which seems suboptimal and not what the WebAssembly doc describes.

In js-sys it is possible to create JavaScript functions from arbitrary strings, but this essentially calls Function(/* some arbitrary string */) from the JavaScript side which again seems suboptimal and not what the WebAssembly doc describes.

Is it possible or is there some other more suitable way to achieve my goal?


Solution

  • Dynamic linking support in llvm/lld for WebAssembly is still a work in progress. I imagine that dynamic linking in Rust is currently blocked on dynamic linking support in in llvm/lld more generally.