mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +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
|
@ -33,7 +33,7 @@ roc_target = {path = "../compiler/roc_target"}
|
|||
roc_types = {path = "../compiler/types"}
|
||||
|
||||
[features]
|
||||
wasmer = ["futures"]
|
||||
wasi_test = ["futures"]
|
||||
|
||||
# Tell wasm-pack not to run wasm-opt automatically. We run it explicitly when we need to.
|
||||
# (Workaround for a CI install issue with wasm-pack https://github.com/rustwasm/wasm-pack/issues/864)
|
||||
|
|
|
@ -20,7 +20,7 @@ extern "C" {
|
|||
|
||||
// To debug in the browser, start up the web REPL as per instructions in repl_www/README.md
|
||||
// and sprinkle your code with console_log!("{:?}", my_value);
|
||||
// (Or if you're running the unit tests in Wasmer, you can just use println! or dbg!)
|
||||
// (Or if you're running the unit tests with WASI, you can just use println! or dbg!)
|
||||
#[macro_export]
|
||||
macro_rules! console_log {
|
||||
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -6,15 +6,15 @@ mod repl;
|
|||
//
|
||||
#[cfg(feature = "console_error_panic_hook")]
|
||||
extern crate console_error_panic_hook;
|
||||
#[cfg(not(feature = "wasmer"))]
|
||||
#[cfg(not(feature = "wasi_test"))]
|
||||
mod externs_js;
|
||||
#[cfg(not(feature = "wasmer"))]
|
||||
#[cfg(not(feature = "wasi_test"))]
|
||||
pub use externs_js::{entrypoint_from_js, js_create_app, js_get_result_and_memory, js_run_app};
|
||||
|
||||
//
|
||||
// Interface with test code outside the Wasm module
|
||||
//
|
||||
#[cfg(feature = "wasmer")]
|
||||
#[cfg(feature = "wasi_test")]
|
||||
mod externs_test;
|
||||
#[cfg(feature = "wasmer")]
|
||||
#[cfg(feature = "wasi_test")]
|
||||
pub use externs_test::{entrypoint_from_test, js_create_app, js_get_result_and_memory, js_run_app};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue