I see https://github.com/bytecodealliance/wasmtime/blob/main/examples/component/main.rs#L58 but where come from Convert?
I don't see any import of it
Convert is defined by the bindgen!("convert" in "./examples/component/convert.wit"); macro I think as a result of the world being called convert: https://github.com/bytecodealliance/wasmtime/blob/a2a66a34af5fef0b8d530620318256a5db35a722/examples/component/convert.wit#L3
It's them same thing as https://github.com/bytecodealliance/wasmtime/blob/main/examples/component/wasm/guest.rs#L3?
We need to generate bindings from host and component?
yes you need to generate bindings both for the guest and the host. Host bindings are generated with wasmtime::bindgen and guest bindings are generated with wit_bindgen::generate
you can expand those rust macros with vscode or cargo-expand to see what code was generated
And I want to generate only guest bindings?
And Instantiate it?
these are entirely separate, you only need the guest bindings to make a component
If you have a component and want to run it, you need the wasmtime host bindings so that you can conveniently call the exported functions of the component, but that has nothing to do with the component itself, just how to run it
also this host is only specific for the wit world, but it can run any component that implements this world
So importing a component during runtime, without generating host binding is not supported?
I think it is possible but I never did or needed that personally so I don't know how
If your component targets a WASI world such as wasi:http/proxy or wasi:cli/command, then you can run it using wasmtime-wasi-http or wasmtime-wasi, respectively (or wasmtime serve or wasmtime run, respectively, if using the command line interface).
You only need to write a custom host embedding (either using the Wasmtime component API directly or in concert with wasmtime-wit-bindgen-generated bindings) if you have a custom world.
Yes, my component use WASI world.
I see https://docs.rs/wasmtime-wasi/latest/wasmtime_wasi/bindings/index.html#examples
So I need to import wasi cli onto my component?
I can avoid that and just only call guest fn defined with wit?
If your component targets wasi:cli/command and nothing else, then you can use a simplified version of that example. You can remove the wasmtime::component::bindgen! macro expression and the example:wasi parts.
Exactly I would like to run my component into a wasmtime environment, I don't want to use wasmtime cli.
Doing this https://github.com/bytecodealliance/wasmtime/blob/main/examples/component/main.rs#L58, without bindgen! Into a wasi world, generating bindings only for component would be perfect.
Last updated: Dec 06 2025 at 06:05 UTC