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
Wai bindgen rust is not working with the JS feature #39
Comments
Ok, I found the line that throws the error: (source) pub unsafe fn data_unchecked_mut(&self) -> &mut [u8] {
unimplemented!("direct data pointer access is not possible in JavaScript");
} Here is the generated method on the instance, using pub fn get_color(
&self,
store: &mut wasmer::Store,
) -> Result<Color, wasmer::RuntimeError> {
let _memory = &self.memory;
let result0 = self.func_get_color.call(store)?;
let _memory_view = _memory.view(&store);
let load1 = unsafe { _memory_view.data_unchecked_mut() }
.load::<f32>(result0 + 0)?;
let _memory_view = _memory.view(&store);
let load2 = unsafe { _memory_view.data_unchecked_mut() }
.load::<f32>(result0 + 4)?;
let _memory_view = _memory.view(&store);
let load3 = unsafe { _memory_view.data_unchecked_mut() }
.load::<f32>(result0 + 8)?;
Ok(Color {
r: load1,
g: load2,
b: load3,
})
} I do not understand why it is not freeing after reading the value, but I guess that is not related to the problem that I am having. In short, why even have the |
After some testing, I have verified that there is a way to get (and modify) the memory of another WASM module on the web with the Proof of concept: Here is how I pass data into the plugin: fn export_to_plugin(memory: &Memory, store: &mut Store, instance: &Instance, data: &[u8]) -> u64 {
let allocate = instance
.exports
.get_typed_function::<i32, i64>(&store, "allocate_for_host")
.unwrap();
let mut allocate = |size: u32| allocate.call(store, size as i32).unwrap() as u64;
let fatptr = allocate(data.len() as u32);
let (addr, _) = from_fatptr(fatptr);
let view = memory.view(store);
view.write(addr as u64, data).unwrap();
fatptr
} (Note that the plugin has to export a And here is how to import data from the plugin: fn import_from_plugin(
instace: &Instance,
memory: &Memory,
store: &mut Store,
fatptr: u64,
) -> Vec<u8> {
let (addr, len) = from_fatptr(fatptr);
let mut bytes = vec![0; len];
let view = memory.view(store);
view.read(addr as u64, &mut bytes[0..len]).unwrap();
let free = instace
.exports
.get_typed_function::<i64, ()>(store, "free_from_host")
.unwrap();
free.call(store, fatptr as i64).unwrap();
bytes
} (Again, plugin must implement Full code: To run it yourself, clone the repo at the Moving forward: The most logical move forward would be to change the generator macro based on the |
Scenario:
I want to use
wai_bindgen_wasmer
to create a Rust program that would import WASM plugins, and then run that program on a webpage. I unserstand that's what thejs
feature is for, but it is not working for me.Just to re-itarate, i DO NOT want to import the WASM plugin in JS runtime.
The problem:
When I use the
wai_bindgen_wasmer
runtime and compile that to WASM using wasm-pack, I get this error at runtime:panicked at 'should create instance: Incompatible Export Type', src\lib.rs:41:14
(source)I tried cloning the
wai
repo and using that instead, and it actually throws a different error:panicked at 'not implemented: direct data pointer access is not possible in JavaScript', C:\Programs\Cargo\bin\registry\src\github.com-1ecc6299db9ec823\wasmer-3.1.1\src\js\externals\memory_view.rs:87:9
The code is the same as above.
Steps to reproduce:
Clone this repo at the
wasm-pack-example-two-errors
tag, and then clonehttps://github.com/wasmerio/wai.git
into the repository. See therun-wasm-only.sh
andrun-wasm-only-forked.sh
scripts on how to run the example.The text was updated successfully, but these errors were encountered: