Repository navigation
Rust: Error in bindings when using wasi:http #245
Copy link
Copy link
Closed
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
macovedj commentedon Apr 13, 2025
You are including
wasi:http/proxyin your wit.If you check the definition of that world in your deps folder, you'll see which interfaces are imported and exported by that world. You'll see that it also exports an interface called
incoming-handler, so you can think of that include statement as also creating an export for that interface, and requiring you to do everything you did in your source code that you had to do for theaddinterface being exported.Here are some lines you can add to your code that should get rid of your error .
Where I just added a barebones function that meets the type constraints required by the interface defined in the wit.
But also maybe you could share a bit about what you were intending to be able to do when including
wasi:http/proxy? You might be able to get some of what you're looking for (types or functionality) viaimportand/orusestatements, instead of aninclude, sinceincluderequires you to export all of the interfaces exported by the world you're including.Almaju commentedon Apr 13, 2025
Oooh that makes sense!
My goal was to do an http request inside my add component.
Here is what I ended up doing and this builds fine:
vados-cosmonic commentedon Apr 23, 2025
Hey @Almaju I know it's been a while, but we're trying to improve the docs so that others get that they can
import/userather thaninclude, and making it clear where it makes sense to use which.Do you happen to remember how you ended up using
include? Which piece of documentation suggested that it might be reasonable? Was it a code snippet?Almaju commentedon Apr 24, 2025
I am not sure but I guess here: https://component-model.bytecodealliance.org/design/wit.html#including-other-worlds
and also reading at some
.witfrom the wasi interfaces.