Stream: git-wasmtime

Topic: wasmtime / issue #10215 Components without WASI


view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2025 at 23:16):

kvcache opened issue #10215:

I'm attempting to compile guest functions using wasm32-unknown-unknown, but I'd like to use the Component model. Trying to parse a guest function as a Component does not work without wasm32-wasip2.

I don't want to use wasm32-wasip2 because I need to define all of my host interfaces.

Client:

wit_bindgen::generate!({
    world: "function",
});

struct Function;

impl exports::momento::functions::function_invoke_post::Guest for Function {
    fn post(payload: Vec::<u8>,) -> Vec::<u8> {
        todo!()
    }
}

export!(Function);

Host fails when parsing wasm byte array:

let component = wasmtime::component::Component::new(&engine, wasm_bytes).map_err(|e| FunctionError::InvalidWasm(e))?;

When I compile with wasm32-unknown-unknown, it says "attempted to parse a wasm module with a component parser".

When I compile with wasm32-wasip2, it fails on WASI interfaces I'm not adding to the linker.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2025 at 23:23):

pchickey commented on issue #10215:

When compiling with wasm32-unknown-unknown rustc emits a WebAssembly Module. You can convert that to a WebAssembly Component with the wasm-tools component new command line tool, or using https://docs.rs/wit-component/latest/wit_component/struct.ComponentEncoder.html directly.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2025 at 23:24):

pchickey edited a comment on issue #10215:

When compiling with wasm32-unknown-unknown rustc emits a WebAssembly Module. You can convert that to a WebAssembly Component with the wasm-tools component new command line tool, or using https://docs.rs/wit-component/latest/wit_component/struct.ComponentEncoder.html directly.

The wasm32-wasip2 target passes the module emitted by rustc to wasm-component-ld which wraps up the conversion performed above, plus some details to adapt wasip1 interfaces to wasip2, which you don't care about.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2025 at 23:24):

pchickey edited a comment on issue #10215:

When compiling with wasm32-unknown-unknown rustc emits a WebAssembly Module. You can convert that to a WebAssembly Component with the wasm-tools component new command line tool, or using https://docs.rs/wit-component/latest/wit_component/struct.ComponentEncoder.html directly.

The wasm32-wasip2 target passes the Module emitted by rustc to wasm-component-ld which wraps up the Component conversion performed above, plus some details to adapt wasip1 interfaces to wasip2, which you don't care about.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 11 2025 at 00:58):

kvcache closed issue #10215:

I'm attempting to compile guest functions using wasm32-unknown-unknown, but I'd like to use the Component model. Trying to parse a guest function as a Component does not work without wasm32-wasip2.

I don't want to use wasm32-wasip2 because I need to define all of my host interfaces.

Client:

wit_bindgen::generate!({
    world: "function",
});

struct Function;

impl exports::momento::functions::function_invoke_post::Guest for Function {
    fn post(payload: Vec::<u8>,) -> Vec::<u8> {
        todo!()
    }
}

export!(Function);

Host fails when parsing wasm byte array:

let component = wasmtime::component::Component::new(&engine, wasm_bytes).map_err(|e| FunctionError::InvalidWasm(e))?;

When I compile with wasm32-unknown-unknown, it says "attempted to parse a wasm module with a component parser".

When I compile with wasm32-wasip2, it fails on WASI interfaces I'm not adding to the linker.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 11 2025 at 00:58):

kvcache commented on issue #10215:

@pchickey Thank you, this is what I needed! I now see an example does this too.


Last updated: Feb 28 2025 at 01:30 UTC