motoko icon indicating copy to clipboard operation
motoko copied to clipboard

fails to run compiled wasm with `wasmtime` v15

Open ZenVoich opened this issue 2 years ago • 6 comments

  • moc 0.10.2
  • compiled with -wasi-system-api flag
  • wasmtime command wasmtime --max-wasm-stack=2000000 --enable-cranelift-nan-canonicalization --wasm-features multi-memory,bulk-memory <file>

Error:

unknown import: `wasi_unstable::fd_write` has not been defined

ZenVoich avatar Nov 21 '23 08:11 ZenVoich

Thanks for reporting!

Which wasmtime? We use 10.0.2.

crusso avatar Nov 21 '23 15:11 crusso

wasmtime 15.0.0, released 2023-11-20

ZenVoich avatar Nov 21 '23 15:11 ZenVoich

(oh, sorry, just noticed the title ;->)

crusso avatar Nov 21 '23 16:11 crusso

Are you blocked by this or is it an FYI?

crusso avatar Nov 21 '23 19:11 crusso

Not a blocker, but it would be nice to fix) I just found my CI is failing because it installs the latest wasmtime.

ZenVoich avatar Nov 21 '23 20:11 ZenVoich

I've investigated a bit. We only actually use 1 function from Wasi (I believe) but the module name has change from "wasi_unstable" to something else "wasi_snapshot_preview1" (I think).

I'm not sure how easy it is to upgrade the version of wasmtime we use in CI (it might be dictated by the was we use nix somehow @ggreif), but I found a wasmtime flag that lets you use the legacy version of the wasi api that we seem to still target (-S preview2=n).

For wasmtime 15.0.0, these options seem to work, without modifying the compiler. wasmtime -S preview2=n -C cache=n -W bulk-memory -W multi-memory foo.wasm

Unfortunately, I don't see how to emulate the old 10.0.2 --enable-cranelift-nan-canonicalization flag using a command-line flag.

diff:

-WASMTIME_OPTIONS="--disable-cache --enable-cranelift-nan-canonicalization --wasm-features multi-memory,bulk-memory"
+WASMTIME_OPTIONS="-S preview2=n -C cache=n -W bulk-memory -W multi-memory"

Perhaps we could add a moc flag for the different wasi api versions... or just target the latest one if we can update our CI.

crusso avatar Nov 22 '23 00:11 crusso