-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugIncorrect behavior in the current implementation that needs fixingIncorrect behavior in the current implementation that needs fixing
Description
Test Case
The wit file:
package sasync:guest;
interface string-if {
resource string-rs {
/// Returns the name of the SaaS provider
string-fn: func() -> string;
}
}
world string-guest {
export string-if;
}
main.rs:
use bindings::exports::sasync::guest::string_if::{Guest, GuestStringRs};
use wit_bindgen::generate;
mod bindings {
wit_bindgen::generate!({
path: "./wit/async-string.wit",
world: "string-guest",
async: true,
});
use super::AsyncString;
export!(AsyncString);
}
pub struct AsyncString;
// ✅ Implement `GuestStringRs` for `AsyncString`
impl GuestStringRs for AsyncString {
async fn string_fn(&self) -> String {
"success".to_string()
}
}
impl Guest for AsyncString {
type StringRs = AsyncString;
}
fn main() {
println!("WASM executed successfully!");
}
Steps to Reproduce
- cargo build --target wasm32-wasip2
- wasmtime run target/wasm32-wasip2/debug/async-string.wasm
Expected Results
WASM executed successfully! [This is what happens when async: false and async removed from fn string_fn]
Actual Results
Error: failed to parse WebAssembly module
Caused by:
invalid leading byte (0x9) for canonical function (at offset 0x3a8a7e)
Versions and Environment
Wasmtime version or commit:
wit-bindgen = { version= "0.38.0", features = ["async"] }
wit-bindgen-rt = { version = "0.38.0", features = ["async"] }
Operating system: MacOS
Architecture: Arm
Extra Info
Here is a github with all the code:
https://github.com/profitgrowinginnovator/async-string
Similar module error is launched when an async wasm is read:
Error: failed to parse WebAssembly module
Caused by:
invalid leading byte (0x9) for canonical function (at offset 0x3a8a7e)
#[tokio::main] // Requires the "macros" feature
async fn main() -> anyhow::Result<()> {
let mut config = Config::new();
config.wasm_component_model(true);
config.async_support(true); // Enable async support
let engine = Engine::new(&config)?;
//let mut linker = Linker::<MyState>::new(&engine);
let state = MyString::default();
let mut store = Store::new(&engine, state);
let linker = Linker::new(&engine);
let component = Component::from_file(&engine, "../async-string/target/wasm32-wasip2/debug/async-string.wasm")?;
let command = Command::instantiate_async(&mut store, &component, &linker).await?;
let result = command.wasi_cli_run().call_run(store);
println!("Result from WASM: {:?}", result.await);
Ok(())
}
Metadata
Metadata
Assignees
Labels
bugIncorrect behavior in the current implementation that needs fixingIncorrect behavior in the current implementation that needs fixing