-
Notifications
You must be signed in to change notification settings - Fork 44
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
Hello world sample #1
Comments
I have only started writing this wrapper very recently(2 days ago to be precise), so I have to look more into the implementation source before I'll be able to create something usable. |
I hope I didn't come across like I expected this stuff to be there after just a few days. I'd like to help with this if possible, though my FFI skills aren't as good as they could be. |
No worries, it didn't sound like that at all. Since there isn't really much to work with in the crate, helping seems rather difficult. But I'd be happy to take some helping hands once there is a rough structure. |
Very interesting, feel free to inspect my Go implementation in case it's useful, I have a few samples too (two of them use WASI): Best. |
Got far enough implementation-wise that it is now possible to call exported functions(though I have not tested it too much yet). Added a very small example to show how it works currently. |
Took a look at the same and it definitely looks like bi-directional calls are working. It looks like there is no return value from a host function, and that the return value is the last parameter in the function list (e.g. the seconds to millis demo). So if I had a function that took 3 input parameters and had one return value, the signature for that host func ( unsafe extern "C" fn millis(
_rt: ffi::IM3Runtime,
p1: u64,
p2: u64,
p3: u64
retval: *mut u64,
_mem: *mut std::ffi::c_void,
) -> *const std::ffi::c_void {
// do unsafe things...
ffi::m3Err_none as _
} ? |
My real goal is to be able to add a config feature flag to the wapc crate so that I can choose whether I want to compile that library using wasmtime (running on servers/server OSes) or wasm3 (running on limited/embedded devices) |
No, the signature of the extern function is always the same, you would have to retrieve the arguments from the stackpointer, which is the second argument to that function. So something like this: unsafe extern "C" fn millis(
_rt: ffi::IM3Runtime,
sp: *mut u64,
_mem: *mut std::ffi::c_void,
) -> *const std::ffi::c_void {
let p1 = *sp;
let p2 = *sp.add(1);
let p3 = *sp.add(2);
*sp = MILLIS; // this is the return value, aka the first value on the stack will be it
ffi::m3Err_none as _ // this is the result return, whether the call was successful(m3Err_none) or not(like returning a trap for example)
} I am thinking about how to make this nicer to use so that the consumer doesn't have to dip into this extern mess themselves, but that most likely will involve some use of macros and im not sure about how I want to do this. |
I just added a small basic macro to aid in creating an extern wrapper function around a rust function that should help to avoid having to write this stuff manually. Should work in most cases I hope, haven't tested it too much yet. https://github.com/Veykril/wasm3-rs/blob/7915db91c4a7461cf827195e89124b9d91319727/examples/wasm_link.rs#L24-L27 You basically call the macro with the wrapper_function name followed by the to be wrapped functions signature. So if you have a function with the signature |
@Veykril what's the easiest way to run the examples?
But, it requires |
@vshymanskyy You can simply run an example by invoking |
wasm3-sys: Disable verbose errors
I have some errors when running example
|
Make sure you have initialized the submodule |
I'm struggling to find the right functions to call to make this work. I'd love to see a sample that utilizes the Rust bindings that:
println!()
work while under host interpretation.If there are some docs or some other source of information you can point me at, I can take a stab at this.
The text was updated successfully, but these errors were encountered: