-
Notifications
You must be signed in to change notification settings - Fork 51
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
provide wasi api style like FFI interface exmaple #215
Comments
@HerrCai0907 Does your host support https://github.com/WebAssembly/multi-memory, can you elaborate a little bit what APIs would you like to use? |
For example wasi: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx It provide an series API to operate file / socket ... The API looks like:
It means moonbit should provide a raw linear memory offset to low level runtime and let low level runtime can read / write data from/to this linear memeory. |
If you can run wasm-gc then you can embed wat instructions: https://github.com/peter-jerry-ye/wasi |
My wish is WASIX support. And WebGPU support would be much better. |
But it is an incompatible solution. If I want to import several thing together, then I need to do integrate, extract the heap related code and reuse it. |
@HerrCai0907 Here are some approaches for your wish (tips: for now, all the following options have no wasm-gc support)
|
I do successfully call some wasi methods over WasmEdge runtime, but unfortunately, only partly supported. Because there's no way to get the address of a pointer/object in MoonBit.
How to pass a string to wasi methods,
#[allow(unused_unsafe, clippy::all)]
/// Emit a log message.
///
/// A log message has a `level` describing what kind of message is being
/// sent, a context, which is an uninterpreted string meant to help
/// consumers group similar messages, and a string containing the message
/// text.
pub fn log(level: Level, context: &str, message: &str) {
unsafe {
let vec0 = context;
let ptr0 = vec0.as_ptr().cast::<u8>();
let len0 = vec0.len();
let vec1 = message;
let ptr1 = vec1.as_ptr().cast::<u8>();
let len1 = vec1.len();
#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8, _: usize) {
::core::panicking::panic("internal error: entered unreachable code")
}
wit_import(
level.clone() as i32,
ptr0.cast_mut(t,
len0,
ptr1.cast_mut(),
len1,
);
}
}
|
@yamajik We have inline wasm supported, which allows you to manipulate pointer/address. We will provide |
Is the WASI style API supported by moonbit? for example provide a raw linear memory view via FFI.
The text was updated successfully, but these errors were encountered: