bytecodealliance / wasmtime-dotnet

.NET embedding of Wasmtime https://bytecodealliance.github.io/wasmtime-dotnet/
Apache License 2.0
409 stars 52 forks source link

Loading a wasm file built with emscripten results in unknown import: `wasi_snapshot_preview1::fd_close` has not been defined' #250

Closed marc-mueller closed 1 year ago

marc-mueller commented 1 year ago

Hi,

I'm trying to figure out how to load a wasm file built with emscripten. When I call linker.Instantiate it results in the following error: unknown import: 'wasi_snapshot_preview1::fd_close' has not been defined'

I also figured out based on other issues, that I need to run emcc with the --no-entry flag. If I'm using emcc with the --bind flag and generating a javascript file and wasm file, this results in other errors.

I'm pretty new to wasm and wasmtime-dotnet. Is there any information available on how to achieve this? The goal would be to compile a wasm module from C++ which runs in the browser and the backend. Thanks for your help!

--Marc

martindevans commented 1 year ago

wasi_snapshot_preview1::fd_close is part of the WebAssembly System Interface (WASI). I guess you probably need to enable WASI when loading the module.

That should look something like this:

linker.DefineWasi();
store.SetWasiConfiguration(new WasiConfiguration());

var instance = linker.Instantiate(store, your_module);
peterhuene commented 1 year ago

Hi @marc-mueller. Thanks for opening the issue!

I believe @martindevans's suggestion will fix your issue for missing definitions of WASI at runtime.

Please reopen if you run into further issues.