I suspect that is a wasm-tools issue, but I thought I'd ask anyway. I was following the README example in the wit-bindgen repo and (apart from some minor fixups) I ended up with a valid wasm file for the component. I downloaded the WASI preview adapter wasm as well (also valid wasm). But once I linked them using wasm-tools
, I get a Wasm file with an invalid magic number that is also not accepted by wasmtime.
$ wasm-tools component new ./target/wasm32-wasi/debug/wit.wasm -o comp.wasm --adapt ./wasi_snapshot_preview1.wasm
$ file comp.wasm
comp.wasm: WebAssembly (wasm) binary module version 0x1000c
$ wasmtime run comp.wasm
Error: failed to run main module `comp.wasm`
Caused by:
0: failed to parse WebAssembly module
1: Invalid input WebAssembly code at offset 4: unknown binary version
Am I holding it wrong or is this a bug?
You likely need to build wasmtime from source to get an updated decoder
So 0x1000c
is intentional, yea?
... In retrospect, I probably should have tried wasm-tools parse
, which works just fine
yeah that's the expected current version
So I built wasm-tools
with -F component
and built wasmtime
with -F component-model
, which has slightly altered the error message, but it is still failing to run the module:
wasmtime run --wasm-features component-model ./comp.wasm
Error: if you're trying to run a precompiled module, pass --allow-precompiled
Caused by:
0: failed to parse WebAssembly module
1: Unsupported feature: component model
juust to make sure since I made that error a few days ago and somebody helped me: are you certain you use the latest git versions of everything? Cargo.lock remembers which revision it used and won't let cargo fetch newer code unless you delete the lockfile
I’m specifying full paths to my local build artifacts, so I don’t think that’s the issue here. But let me triple-check
I think this only applies if you depend directly on git in Cargo.toml, right
that error message indicates you're not passing --wasm-features component-model
to the runtime of wasmtime, but you clearly are, so I'm not entirely sure
it may be that enabling the component-model
feature of the CLI didn't work or the wasmtime
executable you're using isn't the one that you built?
Yeah that’s why I’m so confused. I am specifying the full path to the wasm binary:
~/src/github.com/bytecodealliance/wasmtime/target/release/wasmtime run --wasm-features component-model ./comp.wasm
The CLI even lists the component model in the help
$ ~/src/github.com/bytecodealliance/wasmtime/target/release/wasmtime run --help 130 ↵
wasmtime-run
Runs a WebAssembly module
USAGE:
wasmtime run [OPTIONS] <MODULE> [--] [ARGS]...
... bla bla bla ...
Supported values for `--wasm-features`:
all enables all supported WebAssembly features
bulk-memory enables support for bulk memory instructions
multi-memory enables support for the multi-memory proposal
multi-value enables support for multi-value functions
reference-types enables support for reference types
simd enables support for proposed SIMD instructions
threads enables support for WebAssembly threads
memory64 enables support for 64-bit memories
component-model enables support for the component model <--- !!
... bla bla bla
hm that may be a bug somewhere else then, can you share the component you have?
Literally the stuff created by following the README. Here’s the files that I am using:
wasm-tools component new...
)cargo build --target=wasm32-wasi
)oh sorry I remember now, wasmtime run
doens't have support for components
and that's a bad error message I think of compiling a component with a Module
Oh, I am just now grasping that wasmtime-the-crate can run components, but wasmtime-the-cli can not (yet). So I guess I have to build my own thing for now
yeah this is largely blocked on more WASI support and stabilization
the work in the preview2-prototyping repository will eventually move into the wasmtime repository and there'll be a similar set up to wasi-common
and once there's support for WIT-defined WASI APIs then we'll add CLI support
@Alex Crichton - Is this still the case "wasmtime run doens't have support for components"
I don't see the feature in wasmtime run --help
Yes, that is still the case. The preview2 implementation still ongoing - I'm guessing CLI support wouldn't come until that is (more) complete.
Yes wasmtime doesn't currently support components in the CLI, and that'll get enabled when preview2 support is ready
Last updated: Nov 22 2024 at 16:03 UTC