I'm trying to debug my call to a witx-bindgen wrapper by adding log statements to the function. I think I'm hitting https://www.gitmemory.com/issue/rustwasm/wasm-bindgen/2554/842354646 if I try to use #[wasm_bindgen(js_namespace = console)]
Is there another way?
Can you describe your use case better? In general the two aren't intended to compose (witx-bindgen and wasm-bindgen) and you should probably stick to one or the other. If you're on the web you should be able to put them together theoretically but it's probably not worth it. Off-the-web there's no real meaning for wasm-bindgen, so you wouldn't want to use wasm-bindgen and you'd want to use witx-bindgen instead
I think so. I'm trying to witx-bindgen a string from c# to rust. I've used the witx-bindgen to generate the rust import, and handcrafted the c# export - no doubt I've got this wrong. So I'm trying to see what rust receives but get
std::panicking::begin_panic_fmt::h5f1c42481fee165b@http://localhost:8000/hello_wasi.wasm:wasm-function[393]:0x18f62
std::io::stdio::_print::h622370e54afc2a27@http://localhost:8000/hello_wasi.wasm:wasm-function[15]:0x5e1c
reverse@http://localhost:8000/hello_wasi.wasm:wasm-function[33]:0x9831
with
mod w1 {
#[export_name = "reverse"]
unsafe extern "C" fn __witx_bindgen_reverse(arg0: i32, arg1: i32, ) -> i32{
println!("__witx_bindgen_reverse");
let len0 = arg1 as usize;
So I'm wondering if there's any way to debug. As far as I can tell the the 2 args are ok - I've pasted the first few byes from arg0 and they come out as the right UTF8 chars, and the length, arg1 looks correct
oh sorry, you linked to a wasm-bindgen bug so I thought there might be wasm-bindgen somewhere
sorry I'm not entirely sure what the issue is, can you describe a bit more?
I linked that because I first tried to wasm-bindgen console.log so I could use that to debug my pointers. I'm jumping around, sorry for that. Ignoring the println! as I've removed that for now. I get
exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
at core::str::converts::from_utf8::h044e2484382de369 (http://localhost:8000/hello_wasi.wasm:wasm-function[21]:0x7104)
at alloc::string::String::from_utf8::hdff6602827172de1 (http://localhost:8000/hello_wasi.wasm:wasm-function[24]:0x7b06)
at reverse (http://localhost:8000/hello_wasi.wasm:wasm-function[35]:0x99a6)
So basically I'm trying to debug that, i.e. am I passing a valid set of bytes to the function
https://doc.rust-lang.org/std/vec/struct.Vec.html#method.from_raw_parts says "ptr needs to have been previously allocated via String/Vec<T> (at least, it’s highly likely to be incorrect if it wasn’t)." . Hmm, well its not, its just the memory address passed from the caller...
I don't think I really understand how this works, these are 2 different wasm modules, with their own linear memory spaces and share nothing as I understand it. but the pointer to the byte[] is the same on both wasm modules which seems to contradict my understanding.
I suppose for this to work I'd need some shared memory, and then have both sides use that. This would mean changing both sides to read and write to that shared memory and not their own linear memory. I think I didn't read well enough the use cases which seem to be for communicating between the host and the wasm module, not inter wasm modules.
witx-bindgen is very much meant to enable inter-module communication, too. The wasmlink crate might point you in the right direction
Thanks, yes, that is the missing link(er) in my knowledge.
Scott Waye has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC