Stream: wasmtime

Topic: component example


view this post on Zulip Ludea (Apr 16 2025 at 13:11):

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

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip bjorn3 (Apr 16 2025 at 13:14):

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

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Ludea (Apr 16 2025 at 13:18):

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?

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Ramon Klass (Apr 16 2025 at 13:20):

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

view this post on Zulip Ramon Klass (Apr 16 2025 at 13:21):

you can expand those rust macros with vscode or cargo-expand to see what code was generated

view this post on Zulip Ludea (Apr 16 2025 at 13:27):

And I want to generate only guest bindings?
And Instantiate it?

view this post on Zulip Ramon Klass (Apr 16 2025 at 13:35):

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

view this post on Zulip Ramon Klass (Apr 16 2025 at 13:36):

also this host is only specific for the wit world, but it can run any component that implements this world

view this post on Zulip Ludea (Apr 16 2025 at 13:49):

So importing a component during runtime, without generating host binding is not supported?

view this post on Zulip Ramon Klass (Apr 16 2025 at 13:51):

I think it is possible but I never did or needed that personally so I don't know how

view this post on Zulip Joel Dice (Apr 16 2025 at 14:15):

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.

view this post on Zulip Ludea (Apr 16 2025 at 14:27):

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?

view this post on Zulip Joel Dice (Apr 16 2025 at 14:37):

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.

view this post on Zulip Ludea (Apr 16 2025 at 14:59):

Exactly I would like to run my component into a wasmtime environment, I don't want to use wasmtime cli.

view this post on Zulip Ludea (Apr 16 2025 at 15:09):

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.

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

Last updated: Dec 06 2025 at 06:05 UTC