Stream: git-wasmtime

Topic: wasmtime / issue #3937 Compiling a rust program to `wasm3...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2022 at 23:48):

Mossaka opened issue #3937:

Hey there, I have the following module that tries to implement a handler function for export

wit_bindgen_rust::export!("../../wit/ephemeral/wasi-ce.wit");
use wasi_ce::*;
use cloudevents::{Event, AttributesReader};

struct WasiCe {}

impl wasi_ce::WasiCe for WasiCe {
    fn ce_handler(event: String) -> Result<String,Error> {
        let event_: Event = serde_json::from_str(event.as_str()).unwrap();
        println!("event id: {}", event_.id());
        Ok(event)
    }
}

It uses the cloudevents-sdk to deserialize the argument to a struct.

The wit file is extremely simple, just contains one handler function:
ce-handler: function(event: string) -> expected<string, error>

I am using the wit-bindgen tool for high level interface types.

After I compiled the program to wasm module using cargo build --target wasm32-wasi --release, and then I tried to run this wasm module in the wasmtime host (in python), and it outputs this runtime error:

Traceback (most recent call last):
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/host_py.py", line 43, in <module>
    run(event)
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/host_py.py", line 24, in run
    wasm = WasiCe(store, linker, module)
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/bindings.py", line 73, in __init__
    self.instance = linker.instantiate(store, module)
  File "/usr/local/Caskroom/miniconda/base/envs/myenv/lib/python3.9/site-packages/wasmtime/_linker.py", line 165, in instantiate
    raise WasmtimeError._from_ptr(error)
wasmtime._error.WasmtimeError: unknown import: `__wbindgen_placeholder__::__wbindgen_describe` has not been defined

Any suggestions on how to understand this error message and hints on solve would be greatly appreciated!

view this post on Zulip Wasmtime GitHub notifications bot (Mar 17 2022 at 00:27):

bjorn3 commented on issue #3937:

One of cloudevents' dependencies uses wasm-bindgen which requires you to run the wasm-bindegen tool over the wasm file. Wasm-bindgen is a tool to allow interaction between wasm and javascript (eg browser or nodejs). It does not work with wasm runtimes that don't use javascript like wasmtime. Note that cloudflare workers uses the v8 js engine to run wasm.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 17 2022 at 01:32):

Mossaka commented on issue #3937:

Okay thanks! Does this mean that if I want to use wasmtime as the runtime, I can't use cloudevents-sdk crate anymore, right?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 17 2022 at 11:10):

bjorn3 commented on issue #3937:

I think so.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 17 2022 at 17:51):

alexcrichton commented on issue #3937:

Yes it looks like one of your dependency crates is using wasm-bindgen and wasm-bindgen injects imports into the wasm module which are expected to be filled in by JS but that's not happening here, hence the unknown import error.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 17 2022 at 17:51):

alexcrichton closed issue #3937:

Hey there, I have the following module that tries to implement a handler function for export

wit_bindgen_rust::export!("../../wit/ephemeral/wasi-ce.wit");
use wasi_ce::*;
use cloudevents::{Event, AttributesReader};

struct WasiCe {}

impl wasi_ce::WasiCe for WasiCe {
    fn ce_handler(event: String) -> Result<String,Error> {
        let event_: Event = serde_json::from_str(event.as_str()).unwrap();
        println!("event id: {}", event_.id());
        Ok(event)
    }
}

It uses the cloudevents-sdk to deserialize the argument to a struct.

The wit file is extremely simple, just contains one handler function:
ce-handler: function(event: string) -> expected<string, error>

I am using the wit-bindgen tool for high level interface types.

After I compiled the program to wasm module using cargo build --target wasm32-wasi --release, and then I tried to run this wasm module in the wasmtime host (in python), and it outputs this runtime error:

Traceback (most recent call last):
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/host_py.py", line 43, in <module>
    run(event)
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/host_py.py", line 24, in run
    wasm = WasiCe(store, linker, module)
  File "/Users/mossaka/Developer/wasi-experimental-toolkit/tests/bindings.py", line 73, in __init__
    self.instance = linker.instantiate(store, module)
  File "/usr/local/Caskroom/miniconda/base/envs/myenv/lib/python3.9/site-packages/wasmtime/_linker.py", line 165, in instantiate
    raise WasmtimeError._from_ptr(error)
wasmtime._error.WasmtimeError: unknown import: `__wbindgen_placeholder__::__wbindgen_describe` has not been defined

Any suggestions on how to understand this error message and hints on solve would be greatly appreciated!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 12 2022 at 14:33):

Haishi2016 commented on issue #3937:

I have a similar issue. Using cargo tree, I don't see any dependencies on wasm-bindgen at any levels, though the generated wasm using cargo build --target wasm32-wasi has unresolved __wbindgen_placeholder__ imports.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 13 2022 at 16:34):

sunfishcode commented on issue #3937:

@Haishi2016 It's difficult to say without knowing more about your project. Could you file a new issue about this, and say more about how your project works and what dependencies you have?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2022 at 17:37):

b4stien commented on issue #3937:

FYI there is a doc currently pointing to wasm-bindgen in the repo, with a small disclaimer that the whole section actually does not work at all.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2022 at 17:37):

b4stien edited a comment on issue #3937:

FYI there is a doc currently pointing to wasm-bindgen in the repo, with a small disclaimer that the whole section actually does not work at all.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2022 at 20:55):

sunfishcode commented on issue #3937:

Thanks! https://github.com/bytecodealliance/wasmtime/pull/5394 is now a PR which updates that documentation.


Last updated: Oct 23 2024 at 20:03 UTC