zarkone opened issue #5743:
wasmtime::component::bindgen!({ world: "http", async: true, }); impl HttpImports for HttpState { async fn request(&mut self, url: String) -> anyhow::Result<String> { println!("url is: {}", url); Ok(url.clone()) } } async fn eval_with_imported() -> anyhow::Result<String> { let mut config = Config::new(); config.async_support(true); config.wasm_component_model(true); let engine = Engine::new(&config)?; let component = wasmtime::component::Component::from_file(&engine, "../pasm-wit/pasm-wit-component.wasm")?; let mut linker = wasmtime::component::Linker::new(&engine); Http::add_to_linker(&mut linker, |state: &mut HttpState| state)?; let mut store = Store::new(&engine, HttpState {}); let (bindings, _) = Http::instantiate_async(&mut store, &component, &linker).await?; let res = bindings.call_mainfn(&mut store).await?; Ok(res) }
fails with error:
error[E0706]: functions in traits cannot be declared `async` --> src/main.rs:9:1 | 9 | / wasmtime::component::bindgen!({ 10 | | world: "http", 11 | | async: true, 12 | | }); | |__^ `async` because of this | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
according to doc,
HttpImports
is supposed to haveasync_trait
but I don't see it incargo expand
:use wasmtime::*; pub struct Http { mainfn: wasmtime::component::Func, } pub trait HttpImports { async fn request(&mut self, url: String) -> anyhow::Result<String>; }
also posted on zulip
zarkone labeled issue #5743:
wasmtime::component::bindgen!({ world: "http", async: true, }); impl HttpImports for HttpState { async fn request(&mut self, url: String) -> anyhow::Result<String> { println!("url is: {}", url); Ok(url.clone()) } } async fn eval_with_imported() -> anyhow::Result<String> { let mut config = Config::new(); config.async_support(true); config.wasm_component_model(true); let engine = Engine::new(&config)?; let component = wasmtime::component::Component::from_file(&engine, "../pasm-wit/pasm-wit-component.wasm")?; let mut linker = wasmtime::component::Linker::new(&engine); Http::add_to_linker(&mut linker, |state: &mut HttpState| state)?; let mut store = Store::new(&engine, HttpState {}); let (bindings, _) = Http::instantiate_async(&mut store, &component, &linker).await?; let res = bindings.call_mainfn(&mut store).await?; Ok(res) }
fails with error:
error[E0706]: functions in traits cannot be declared `async` --> src/main.rs:9:1 | 9 | / wasmtime::component::bindgen!({ 10 | | world: "http", 11 | | async: true, 12 | | }); | |__^ `async` because of this | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
according to doc,
HttpImports
is supposed to haveasync_trait
but I don't see it incargo expand
:use wasmtime::*; pub struct Http { mainfn: wasmtime::component::Func, } pub trait HttpImports { async fn request(&mut self, url: String) -> anyhow::Result<String>; }
also posted on zulip
alexcrichton closed issue #5743:
wasmtime::component::bindgen!({ world: "http", async: true, }); impl HttpImports for HttpState { async fn request(&mut self, url: String) -> anyhow::Result<String> { println!("url is: {}", url); Ok(url.clone()) } } async fn eval_with_imported() -> anyhow::Result<String> { let mut config = Config::new(); config.async_support(true); config.wasm_component_model(true); let engine = Engine::new(&config)?; let component = wasmtime::component::Component::from_file(&engine, "../pasm-wit/pasm-wit-component.wasm")?; let mut linker = wasmtime::component::Linker::new(&engine); Http::add_to_linker(&mut linker, |state: &mut HttpState| state)?; let mut store = Store::new(&engine, HttpState {}); let (bindings, _) = Http::instantiate_async(&mut store, &component, &linker).await?; let res = bindings.call_mainfn(&mut store).await?; Ok(res) }
fails with error:
error[E0706]: functions in traits cannot be declared `async` --> src/main.rs:9:1 | 9 | / wasmtime::component::bindgen!({ 10 | | world: "http", 11 | | async: true, 12 | | }); | |__^ `async` because of this | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
according to doc,
HttpImports
is supposed to haveasync_trait
but I don't see it incargo expand
:use wasmtime::*; pub struct Http { mainfn: wasmtime::component::Func, } pub trait HttpImports { async fn request(&mut self, url: String) -> anyhow::Result<String>; }
also posted on zulip
Giom-fm commented on issue #5743:
Unfortunately, I have the same error. i am using
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", features = ["component-model"], branch = 'release-6.0.0' }
in my cargo.toml.When I run cargo expand I don't see anything that looks like the async_trait annotation is set correctly.
pub struct HelloWorld { greet: wasmtime::component::Func, } pub trait HelloWorldImports { async fn name(&mut self) -> anyhow::Result<String>; }
My code looks like that:
wasmtime::component::bindgen!({ path: "guest/wit", world: "host", async: true }); struct HelloWorldState { name: String, } #[async_trait] impl HelloWorldImports for HelloWorldState { async fn name(&mut self) -> Result<String> { Ok(self.name.clone()) } }
Error is:
error[E0706]: functions in traits cannot be declared `async` --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ `async` because of this | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error: method `name` should be async because the method from the trait is async --> src/main.rs:28:5 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__- required because the trait method is async ... 28 | async fn name(&mut self) -> Result<String> { | ^^^^^ error: future cannot be sent between threads safely --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ future created by async block is not `Send` | = help: within `[async block@src/main.rs:11:1: 15:3]`, the trait `Send` is not implemented for `impl Future<Output = std::result::Result<std::string::String, anyhow::Error>>` note: future is not `Send` as it awaits another future which is not `Send` --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ await occurs here on type `impl Future<Output = std::result::Result<std::string::String, anyhow::Error>>`, which is not `Send` = note: required for the cast from `[async block@src/main.rs:11:1: 15:3]` to the object type `dyn Future<Output = std::result::Result<(std::string::String,), anyhow::Error>> + Send` = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0706`.
Giom-fm edited a comment on issue #5743:
Unfortunately, I have the same error. i am using
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", features = ["component-model"], branch = 'release-6.0.0' }
in my cargo.toml.When I run cargo expand I don't see anything that looks like the async_trait annotation is set correctly.
pub struct HelloWorld { greet: wasmtime::component::Func, } pub trait HelloWorldImports { async fn name(&mut self) -> anyhow::Result<String>; }
My code looks like that:
wasmtime::component::bindgen!({ path: "guest/wit", world: "host", async: true }); struct HelloWorldState { name: String, } #[async_trait] impl HelloWorldImports for HelloWorldState { async fn name(&mut self) -> Result<String> { Ok(self.name.clone()) } }
Error is:
error[E0706]: functions in traits cannot be declared `async` --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ `async` because of this | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error: method `name` should be async because the method from the trait is async --> src/main.rs:28:5 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__- required because the trait method is async ... 28 | async fn name(&mut self) -> Result<String> { | ^^^^^ error: future cannot be sent between threads safely --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ future created by async block is not `Send` | = help: within `[async block@src/main.rs:11:1: 15:3]`, the trait `Send` is not implemented for `impl Future<Output = std::result::Result<std::string::String, anyhow::Error>>` note: future is not `Send` as it awaits another future which is not `Send` --> src/main.rs:11:1 | 11 | / wasmtime::component::bindgen!({ 12 | | path: "guest/wit", 13 | | world: "host", 14 | | async: true 15 | | }); | |__^ await occurs here on type `impl Future<Output = std::result::Result<std::string::String, anyhow::Error>>`, which is not `Send` = note: required for the cast from `[async block@src/main.rs:11:1: 15:3]` to the object type `dyn Future<Output = std::result::Result<(std::string::String,), anyhow::Error>> + Send` = note: this error originates in the macro `wasmtime::component::bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0706`.
bjorn3 commented on issue #5743:
The fix will be part of wasmtime 7.0.0 I think.
Giom-fm commented on issue #5743:
Ah yes you are right. A quick lookup shows that the fix is currently only on the main branch.
Thanks!
Last updated: Nov 22 2024 at 17:03 UTC