1

Can I import .wasm files from my AssemblyScript code? I know I can use the AssemblyScript loader to load .wasm files from TypeScript, but I get errors if I try to build my AssemblyScript example if I follow the instructions found on https://www.assemblyscript.org/loader.html

Long story short, I have a Rust library that I've compiled to WASM. I'd like to use that code in my AssemblyScript example. Is that possible or no?

Texagonian
  • 11
  • 3

1 Answers1

0

To the best of my knowledge, currently there is no tooling to statically link two wasm binaries from different languages.

This is difficult for several reasons: AS modules aren't designed with relocation in mind (that is you can't reference an import indirectly), and another is that currently without allocation being provided by Wasm each binary typically packages its own allocator internally. This means without coordination the two allocators don't know about the state of available memory and could overwrite each other.

It sounds like your use case is in the browser, but if you aren't wasmtime now has dynamic linking, which could be useful to do what you want. See here for an example, all be it a simple one that doesn't have the allocator issue mentioned above

sirwillem
  • 722
  • 4
  • 9
  • I actually am using Wasmtime in this case. However, what I'm trying to do is basically the reverse of your example (which was helpful BTW thanks). Basically I have a Rust library I've compiled to WASM and I'd like to import and use it in my AssemblyScript example. If I manage to come up with a working example I'll be sure to come back and share it. – Texagonian Jul 01 '21 at 01:42
  • Cool! Good luck and feel free to share even if you haven't finished! – sirwillem Jul 01 '21 at 20:54