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 thewasmtime
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!
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.
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?
bjorn3 commented on issue #3937:
I think so.
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.
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 thewasmtime
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!
Haishi2016 commented on issue #3937:
I have a similar issue. Using
cargo tree
, I don't see any dependencies onwasm-bindgen
at any levels, though the generatedwasm
usingcargo build --target wasm32-wasi
has unresolved__wbindgen_placeholder__
imports.
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?
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.
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.
sunfishcode commented on issue #3937:
Thanks! https://github.com/bytecodealliance/wasmtime/pull/5394 is now a PR which updates that documentation.
Last updated: Dec 23 2024 at 12:05 UTC