-
Notifications
You must be signed in to change notification settings - Fork 12
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
Binding generator #27
Conversation
Thanks for contribution. I noticed the PR is using APIs of wamr_sys in generated code which is not our suggestions. We are hoping people use wamr-rust-sdk APIs to keep their code safe and don't involved those |
This reverts commit d44a894.
Here is the output for both example with new abstraction : #[no_mangle]
pub unsafe extern "C" fn __wamr_bindgen_test_function(
__wamr_environment: wamr_sys::wasm_exec_env_t,
_a: i32,
_b: f32,
_c: u32,
_d: u32,
_e: i64,
_f: i64,
_g: i32,
) -> i32 {
let __wamr_environment = wamr_rust_sdk::execution_environment::ExecutionEnvironment::from(
__wamr_environment,
);
let __wamr_instance = __wamr_environment.get_instance();
let _a = _a as i32;
let _c = __wamr_instance.app_to_native_str(_c).to_string();
let _d = __wamr_instance.app_to_native_str(_d);
let _e = _e as i64;
let _f = _f as u64;
let _g = _g as i8;
test_function(_a, _b, _c, _d, _e, _f, _g) as i32
} and : #[no_mangle]
pub unsafe extern "C" fn __wamr_bindgen_Test_test_function(
__wamr_environment: wamr_sys::wasm_exec_env_t,
__self: u32,
a: i32,
b: f32,
c: u32,
d: u32,
e: i64,
f: u32,
g: i32,
h: i32,
i: i32,
j: i32,
k: f64,
) -> i32 {
let __wamr_environment = wamr_rust_sdk::execution_environment::ExecutionEnvironment::from(
__wamr_environment,
);
let __wamr_instance = __wamr_environment.get_instance();
let __self: &Test = __wamr_instance.app_to_native_ref(__self);
let a = a as i32;
let c = __wamr_instance.app_to_native_str(c).to_string();
let d = __wamr_instance.app_to_native_str(d);
let e = e as i64;
let f: &u64 = __wamr_instance.app_to_native_ref(f);
let g = g as i8;
let h = h as u8;
let i = i as i16;
let j = j as u16;
Test::test_function(__self, a, b, c, d, e, f, g, h, i, j, k) as i32
} |
|
|
I am not quite following why we need to operate address like C in Rust World? |
How am I supposed to pass, for example, strings or arrays from WASM to the native and vice versa? (necessary for the serialization of complex structures). |
The whole idea is to keep user interfaces simple. We don't want to let APIs' users keep much concepts in their mind when programing with wamr-rust-sdk. Using a String as an example, it will be too much if they have to 1. move a string to wasm memory from host memory. 2. construct a In my mind, an ideal result is use one API, like |
Ok but I'm struggling to see how you plan to implement Furthermore, if you don't want to complicate the API for the end user, would it be possible to at least expose |
Sorry for the mis-understand. address translation is still necessary in rust-sdk. But rust-sdk users shouldn't be awarded of that. |
Hello, in order to easily interface WAMR with Rust, I wrote "wamr-bindgen" macros that automatically write the necessary code (signature, binding function, conversions). At the moment, it is only a crude prototype, but it is functional in the case of simple types and references on composite types (generic types and composite types passed by value/returned are not supported).
For the following standalone function :
the generated code is :
and for an impl on a structure :
the generated code is :
Can I have any advice on that ?