Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components without WASI #10215

Closed
kvcache opened this issue Feb 10, 2025 · 2 comments
Closed

Components without WASI #10215

kvcache opened this issue Feb 10, 2025 · 2 comments

Comments

@kvcache
Copy link

kvcache commented Feb 10, 2025

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.

@pchickey
Copy link
Contributor

pchickey commented Feb 10, 2025

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.

@kvcache
Copy link
Author

kvcache commented Feb 11, 2025

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

@kvcache kvcache closed this as completed Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants