mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
repl_wasm: rename Cargo feature wasmer->wasi_test
This commit is contained in:
parent
d389601035
commit
e6325fa78f
4 changed files with 18 additions and 19 deletions
|
@ -1,16 +1,16 @@
|
|||
use futures::executor;
|
||||
|
||||
extern "C" {
|
||||
fn wasmer_create_app(app_bytes_ptr: *const u8, app_bytes_len: usize) -> u32;
|
||||
fn wasmer_run_app() -> usize;
|
||||
fn wasmer_get_result_and_memory(buffer_alloc_addr: *mut u8) -> usize;
|
||||
fn wasmer_copy_input_string(src_buffer_addr: *mut u8);
|
||||
fn wasmer_copy_output_string(output_ptr: *const u8, output_len: usize);
|
||||
fn test_create_app(app_bytes_ptr: *const u8, app_bytes_len: usize) -> u32;
|
||||
fn test_run_app() -> usize;
|
||||
fn test_get_result_and_memory(buffer_alloc_addr: *mut u8) -> usize;
|
||||
fn test_copy_input_string(src_buffer_addr: *mut u8);
|
||||
fn test_copy_output_string(output_ptr: *const u8, output_len: usize);
|
||||
}
|
||||
|
||||
/// Async wrapper to match the equivalent JS function
|
||||
pub async fn js_create_app(wasm_module_bytes: &[u8]) -> Result<(), String> {
|
||||
let ok = unsafe { wasmer_create_app(wasm_module_bytes.as_ptr(), wasm_module_bytes.len()) } != 0;
|
||||
let ok = unsafe { test_create_app(wasm_module_bytes.as_ptr(), wasm_module_bytes.len()) } != 0;
|
||||
if ok {
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -19,22 +19,21 @@ pub async fn js_create_app(wasm_module_bytes: &[u8]) -> Result<(), String> {
|
|||
}
|
||||
|
||||
pub fn js_run_app() -> usize {
|
||||
unsafe { wasmer_run_app() }
|
||||
unsafe { test_run_app() }
|
||||
}
|
||||
|
||||
pub fn js_get_result_and_memory(buffer_alloc_addr: *mut u8) -> usize {
|
||||
unsafe { wasmer_get_result_and_memory(buffer_alloc_addr) }
|
||||
unsafe { test_get_result_and_memory(buffer_alloc_addr) }
|
||||
}
|
||||
|
||||
/// Entrypoint for Wasmer tests
|
||||
/// Entrypoint for tests using WASI and a CLI interpreter
|
||||
/// - Synchronous API, to avoid the need to run an async executor across the Wasm/native boundary.
|
||||
/// (wasmer has a sync API for creating an Instance, whereas browsers don't)
|
||||
/// - Uses an extra callback to allocate & copy the input string (wasm_bindgen does this for JS)
|
||||
/// - Uses an extra callback to allocate & copy the input string (in the browser version, wasm_bindgen does this)
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint_from_test(src_len: usize) -> bool {
|
||||
let mut src_buffer = std::vec![0; src_len];
|
||||
let src = unsafe {
|
||||
wasmer_copy_input_string(src_buffer.as_mut_ptr());
|
||||
test_copy_input_string(src_buffer.as_mut_ptr());
|
||||
String::from_utf8_unchecked(src_buffer)
|
||||
};
|
||||
let result_async = crate::repl::entrypoint_from_js(src);
|
||||
|
@ -43,7 +42,7 @@ pub extern "C" fn entrypoint_from_test(src_len: usize) -> bool {
|
|||
|
||||
let output = result.unwrap_or_else(|s| s);
|
||||
|
||||
unsafe { wasmer_copy_output_string(output.as_ptr(), output.len()) }
|
||||
unsafe { test_copy_output_string(output.as_ptr(), output.len()) }
|
||||
|
||||
ok
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue