Stream: wit-bindgen

Topic: Loading a Component


view this post on Zulip Yoshi Sono (Nov 08 2022 at 22:53):

Noobie here. I'd like my wasmtime rust host to dynamically instantiate components of a known {import + export + default}. Here is what I tried:

  1. Build guest: cargo build --target wasm32-unknown-unknown --release --> foo.wasm
  2. Convert guest from wasm to component: wit-component foo.wasm --> component.wasm
    (So far, the same steps as in https://github.com/bytecodealliance/wit-bindgen/blob/main/crates/wit-bindgen-demo/build.sh)

  3. On host, use wit_bindgen_host_wasmtime_rust::generate!(...)

  4. The macro-generated interface takes a wasmtime::component::Component. I'm trying to build one via Component::new(), from_binary(), or from_file(); and none of these works.

Question:

I'm using
wit-component = git b0a34f0
wasmtime = git 7b5fd84

A language binding generator for WebAssembly interface types - wit-bindgen/build.sh at main · bytecodealliance/wit-bindgen

view this post on Zulip Alex Crichton (Nov 08 2022 at 22:56):

That's the right workflow, yeah, and steps 1/2 are slated to be combined with the cargo-component subcommand eventually as well.

view this post on Zulip Alex Crichton (Nov 08 2022 at 22:56):

What errro are you getting from Component::new? (any of those ctors should work)

view this post on Zulip Yoshi Sono (Nov 08 2022 at 23:18):

Oops I just needed config.wasm_component_model(true);. Thanks for your super quick response. <3


Last updated: Dec 23 2024 at 12:05 UTC