Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using async: true wasmtime run always gives Module error #10168

Closed
profitgrowinginnovator opened this issue Feb 2, 2025 · 2 comments
Closed
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@profitgrowinginnovator
Copy link

profitgrowinginnovator commented Feb 2, 2025

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(())
}

@profitgrowinginnovator profitgrowinginnovator added the bug Incorrect behavior in the current implementation that needs fixing label Feb 2, 2025
@bjorn3
Copy link
Contributor

bjorn3 commented Feb 2, 2025

Support for the async ABI of the component model is not yet implemented in Wasmtime as it was only recently introduced in the component model. There is an open PR to implement it: #9582

@profitgrowinginnovator
Copy link
Author

Thanks for letting me know. I just found out about https://github.com/bytecodealliance/wrpc Hopefully this solves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

No branches or pull requests

2 participants