Stream: wasi

Topic: wit_bindgen: no `take/from_handle` for struct


view this post on Zulip Theodore Brockman (Sep 30 2025 at 20:41):

Forgive me if there's something simple I've missed, but does anything stand out as incorrect with this wit_bindgen::generate! use here?

wit_bindgen::generate!({
    world: "plugin",
    with: {
        "wasi:http/types@0.3.0-rc-2025-09-16": wasmtime_wasi_http::p3::bindings::http::types,
    },
    async: true,
    generate_all
});

Leads to the following compiler error (for [take_handle,from_handle] X [wasmtime_wasi_http::p3::Request,wasmtime_wasi_http::p3::Response]):

error[E0599]: no function or associated item named `from_handle` found for struct `wasmtime_wasi_http::p3::Request` in the current scope
  --> src/apps/mitmproxy-rs/src/plugins/mod.rs:25:1
   |
25 |   wit_bindgen::generate!({
   |  _^
26 | |     world: "plugin",
27 | |     with: {
28 | |         "wasi:http/types@0.3.0-rc-2025-09-16": wasmtime_wasi_http::p3::bindings::http::types,
...  |
31 | |     generate_all
32 | | });
   | |__^ function or associated item not found in `wasmtime_wasi_http::p3::Request`
   |
   = note: this error originates in the macro `wit_bindgen::generate` (in Nightly builds, run with -Z macro-backtrace for more info)

Enabled features + wit_bindgen version (in case it matters)

// ...
wasmtime = { path = "../wasmtime/crates/wasmtime", features = ["component-model-async"] }
wasmtime-wasi = { path = "../wasmtime/crates/wasi", features = ["p3"] }
wasmtime-wasi-http = { path = "../wasmtime/crates/wasi-http", features = ["p3"] }
wit-bindgen = { version = "0.46.0" }

WIT snippet (in case it matters):

world plugin {
    use wasi:http/types@0.3.0-rc-2025-09-16.{request, response};
    // ...

    variant event-data {
        request(request),
        response(response),
    }
}

view this post on Zulip Theodore Brockman (Sep 30 2025 at 21:09):

Using wasmtime::component::bindgen instead seems to compile:

wasmtime::component::bindgen!({
    world: "plugin",
    with: {
        "wasi:http/types@0.3.0-rc-2025-09-16": wasmtime_wasi_http::p3::bindings::http::types,
    },
});

Whatever the distinction between the two that I'd missed ends up being :sweat_smile:

view this post on Zulip Ramon Klass (Sep 30 2025 at 21:42):

wit-bindgen is for generating the guest part, so what is inside the .wasm file, while wasmtime::component::bindgen generates the host part, the thing you run on your machine to load and run these comonent wasm files

view this post on Zulip Ramon Klass (Sep 30 2025 at 21:43):

so wit-bindgen code needs some wasm32-* target to compile

view this post on Zulip Alex Crichton (Oct 01 2025 at 14:14):

Yeah this is a mismatch where you're pointing wit-bindgen-the-crate at wasmtime::component::bindgen!-generated bindings which is a host/guest mismatch

view this post on Zulip Theodore Brockman (Oct 01 2025 at 18:50):

:man_facepalming: think my brain completely glossed over the difference in https://component-model.bytecodealliance.org/language-support/rust.html#implementing-and-exporting-a-resource-implementation-in-a-host

thanks for the explanation


Last updated: Dec 06 2025 at 06:05 UTC