diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 6576d34889..e07395ea44 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -865,7 +865,7 @@ fn roc_run<'a, I: IntoIterator>( generated_filename, args.into_iter().map(|os_str| { os_str.to_str().expect( - "Roc does not currently support passing non-UTF8 arguments to Wasmer.", + "Roc does not currently support passing non-UTF8 arguments to Wasm.", ) }), ); @@ -1240,33 +1240,28 @@ fn roc_run_native, S: AsRef>( #[cfg(feature = "run-wasm32")] fn run_wasm, S: AsRef<[u8]>>(wasm_path: &std::path::Path, args: I) { - use wasmer::{Instance, Module, Store}; + use bumpalo::collections::Vec; + use roc_wasm_interp::{DefaultImportDispatcher, Instance}; - let store = Store::default(); - let module = Module::from_file(&store, &wasm_path).unwrap(); + let bytes = std::fs::read(wasm_path).unwrap(); + let arena = Bump::new(); - // First, we create the `WasiEnv` - use wasmer_wasi::WasiState; - let mut wasi_env = WasiState::new("hello").args(args).finalize().unwrap(); - - // Then, we get the import object related to our WASI - // and attach it to the Wasm instance. - let import_object = wasi_env.import_object(&module).unwrap(); - - let instance = Instance::new(&module, &import_object).unwrap(); - - let start = instance.exports.get_function("_start").unwrap(); - - use wasmer_wasi::WasiError; - match start.call(&[]) { - Ok(_) => {} - Err(e) => match e.downcast::() { - Ok(WasiError::Exit(0)) => { - // we run the `_start` function, so exit(0) is expected - } - other => panic!("Wasmer error: {:?}", other), - }, + let mut argv = Vec::<&[u8]>::new_in(&arena); + for arg in args { + let mut arg_copy = Vec::::new_in(&arena); + arg_copy.extend_from_slice(arg.as_ref()); + argv.push(arg_copy.into_bump_slice()); } + let import_dispatcher = DefaultImportDispatcher::new(&argv); + + let mut instance = Instance::from_bytes(&arena, &bytes, import_dispatcher, false).unwrap(); + + instance + .call_export("_start", []) + .unwrap() + .unwrap() + .expect_i32() + .unwrap(); } #[cfg(not(feature = "run-wasm32"))]