I'm working on a sandbox environment for user defined functions in a data processing engine. It is a perfect use case for wasm, and even better it doesn't need interface types. I have a super simple need for the types on the wasm methods. All I need to do is be able to pass in a borrowed byte array into the method and it can return an owned byte array. This data processing engine expects to use a specific data serialization method inside WASM functions. I've been experimenting with building a simple method that takes a byte array using both wasm-buildgen and building a similar library using wasm32-unknown-unknown target. I'm hitting a surprising mismatch when I then try and run these methods in a smaller runner program I wrote using wasmtime. When using wasm-bindgen the signature just looks like:
#[wasm_bindgen]
pub fn udf(input_buffer: &[u8]) -> u32
When trying without wasm-bindgen it looks like
#[no_mangle]
pub unsafe extern "C" fn add(input: *mut u8) -> u32 {
In both of these situations when I decompile the wasm produced the function takes two i32s which is what I expect So now when I try and run this I am using this:
let module = Module::from_file(store.engine(), "../adder/pkg/adder_bg.wasm").unwrap();
let instance = Instance::new(&store, &module, &[]).unwrap();
let add = instance.get_typed_func::<Option<ExternRef>, u32>("udf").unwrap();
let ext_ref = ExternRef::new([0,1]);
println!("0 + 1 = {}", add.call(Some(ext_ref)).unwrap());
Which is generating the following error:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: type mismatch with parameters
Caused by:
expected externref found i32', src/main.rs:23:72
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I'm pretty convinced that the externref on my runner is wrong but I don't know what is correct. What type should I pass in here?