ericsink / wasm2cil

A "compiler" that can take a WebAssembly/WASI module and convert it to a .NET assembly
Apache License 2.0
280 stars 23 forks source link

Support for imported functions that aren't provided by wasi #4

Open paulbatum opened 5 years ago

paulbatum commented 5 years ago

I might be missing something but I can't figure out how to load a module that has a set of imports that look like this:

  (import "env" "myfunc" (func $myfunc (type $t1)))
  (import "wasi_unstable" "fd_close" (func $__wasi_fd_close (type $t2)))
  (import "wasi_unstable" "fd_seek" (func $__wasi_fd_seek (type $t3)))
  (import "wasi_unstable" "fd_fdstat_get" (func $__wasi_fd_fdstat_get (type $t4)))
  (import "wasi_unstable" "fd_write" (func $__wasi_fd_write (type $t5)))

The idea is that myfunc would be provided by a separate .NET assembly. I assume that gen_assembly would need to be modified to accept multiple assemblies for this to be possible?

ericsink commented 5 years ago

Yep, that is currently a limitation of gen_assembly. :-(

NicolasDorier commented 5 years ago

@paulbatum I think I solved it long ago with wabt (can take a look to https://github.com/NicolasDorier/NBitcoin.Secp256k1/blob/master/Dockerfile)

I have vague memory about what I did, but I think in my solution, there is a proper implementation of wasi functions provided by the sdk I use.

NicolasDorier commented 5 years ago

I need to try again with new wasn2cil version.

NicolasDorier commented 5 years ago

Either that, or I ended up removing trace of printf in my code so those get never called. I think they were the source of the dependencies.