Skip to content

Rust: Error in bindings when using wasi:http #245

@Almaju

Description

@Almaju

Example .wit:

interface add {
    add: func(x: u32, y: u32) -> u32;
}

world planner {
    export add;
    include wasi:http/proxy@0.2.3;
}

With lib.rs:

#[allow(warnings)]
mod bindings;

use bindings::exports::component::planner::add::Guest;

struct Component;

impl Guest for Component {
    fn add(x: u32, y: u32) -> u32 {
        x + y
    }
}

bindings::export!(Component with_types_in bindings);

I ran wkg wit fetch and here is my Cargo.toml:

[package.metadata.component.target.dependencies]
"wasi:cli" = { path = "wit/deps/wasi-cli-0.2.3" }
"wasi:clock" = { path = "wit/deps/wasi-clocks-0.2.3" }
"wasi:http" = { path = "wit/deps/wasi-http-0.2.3" }
"wasi:io" = { path = "wit/deps/wasi-io-0.2.3" }
"wasi:random" = { path = "wit/deps/wasi-random-0.2.3" }

I ran cargo component bindings

Then when I try to build, I get:

error[E0277]: the trait bound `Component: incoming_handler::Guest` is not satisfied
    --> components/planner/src/bindings.rs:8488:68
     |
8488 |                         $($path_to_types)*:: _export_handle_cabi::<$ty > (arg0, arg1) } }
     |                                                                    ^^^ the trait `incoming_handler::Guest` is not implemented for `Component`
     |
    ::: components/planner/src/lib.rs:16:1
     |
16   | bindings::export!(Component with_types_in bindings);
     | --------------------------------------------------- in this macro invocation
     |
help: this trait has no implementations, consider adding one
    --> components/planner/src/bindings.rs:8466:17
     |
8466 |                 pub trait Guest {
     |                 ^^^^^^^^^^^^^^^
note: required by a bound in `_export_handle_cabi`
    --> components/planner/src/bindings.rs:8451:54
     |
8451 |                 pub unsafe fn _export_handle_cabi<T: Guest>(arg0: i32, arg1: i32) {
     |                                                      ^^^^^ required by this bound in `_export_handle_cabi`
     = note: this error originates in the macro `bindings::exports::wasi::http::incoming_handler::__export_wasi_http_incoming_handler_0_2_3_cabi` which comes from the expansion of the macro `bindings::export` (in Nightly builds, run with -Z macro-backtrace for more info)

This is the related line in bindings:

                #[doc(hidden)]
                macro_rules! __export_wasi_http_incoming_handler_0_2_3_cabi {
                    ($ty:ident with_types_in $($path_to_types:tt)*) => {
                        const _ : () = { #[unsafe (export_name =
                        "wasi:http/incoming-handler@0.2.3#handle")] unsafe extern "C" fn
                        export_handle(arg0 : i32, arg1 : i32,) { unsafe {
                        $($path_to_types)*:: _export_handle_cabi::<$ty > (arg0, arg1) } }
                        };
                    };
                }

Any idea what I am doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions