Stream: wasmtime

Topic: wasm-tools component features


view this post on Zulip Daniel Macovei (Feb 10 2023 at 19:36):

I'm trying to execute a component I compiled using wasmtime like so

pub fn main() -> Result<()> {
  let mut config = Config::new();
  config.wasm_component_model(true);
  let engine = Engine::new(&config)?;
  // let path = path::Path::new("/Users/interpretations/projects/witty/my-component.wasm");
  let contents = fs::read("./my-component.wasm")
         .expect("Something went wrong reading the file");
  println!("PRINTING OUT SOME THIGNS");
  println!("THE ACTUAL CONTENTS {:?}", contents);
  let comp = Component::from_binary(&engine, &contents).unwrap();
  // println!("Output: {}", wasmprinter::print_bytes(&comp).unwrap());
  let linker = Linker::new(&engine);
  let mut store = Store::new(&engine, ());
  let instance = linker.instantiate(&mut store, &comp)?;

  Ok(())
}

and I'm getting

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: failed to parse WebAssembly module

Caused by:
    unknown binary version (at offset 0x4)', src/main.rs:17:57

Seems like maybe wasmparser isn't recognizing const KIND_COMPONENT: u16 = 0x01; when reading the binary?
Does this need to be enabled with a feature flag?
I've specified wasmtime = { version = "5.0.0", features = ["component-model"]} in my Cargo.toml

view this post on Zulip Daniel Macovei (Feb 10 2023 at 19:37):

It's failing on the call to Component::from_binary

view this post on Zulip Lann Martin (Feb 10 2023 at 19:39):

Is your .wasm file binary wasm? (or is it perhaps the text form?)

view this post on Zulip Daniel Macovei (Feb 10 2023 at 19:40):

It's binary. I'm creating it by running

wasm-tools component new ./target/wasm32-wasi/debug/my-project.wasm \
    -o my-component.wasm --adapt ./wasi_snapshot_preview1.wasm

view this post on Zulip Lann Martin (Feb 10 2023 at 20:00):

This is just a guess as I'm not tracking changes closely, but the component model spec is under heavy development and its possible that your tools are out of sync with each other; are you using recent versions of both wasm-tools and wasmtime?

view this post on Zulip Daniel Macovei (Feb 10 2023 at 20:04):

Fairly sure I'm using latest for both, 1.0.23 and 5.0.0. Can try and tinker with some version changes though

view this post on Zulip bjorn3 (Feb 11 2023 at 09:08):

You might want to try the main branch of wasmtime.

view this post on Zulip bjorn3 (Feb 11 2023 at 09:09):

Wasm-tools may have had a release with breaking changes after Wasmtime 5.0.0 got released.

view this post on Zulip Peter Huene (Feb 11 2023 at 17:18):

It did, unfortunately. Latest published wasm-tools only works with main of wasmtime. wit-bindgen hasn't been updated yet either.

view this post on Zulip Peter Huene (Feb 11 2023 at 17:21):

If you do want to use 5.0.0 of wasmtime, you may need to rollback wasm-tools a version or two (another format change happened nine days ago too). We're getting close to some stability in the component binary format, but not quite there yet.

view this post on Zulip Peter Huene (Feb 11 2023 at 19:24):

Oh I take that back, it looks like wit-bindgen updated its deps yesterday (Alex was supposed to have the day off :eyes:)

view this post on Zulip Daniel Macovei (Feb 11 2023 at 20:51):

Thanks for the updates!


Last updated: Oct 23 2024 at 20:03 UTC