David Alsh
David Alsh
Explore posts from servers
LTLeaning Technologies
Created by David Alsh on 11/14/2024 in #support
Is WebVM faster on x86_64 hosts compared to arm64 MacOS hosts?
I am evaluating WebVM as a tool to sandbox a "playground" environment for a internal company compiler tool as it allows us the ability to run unmodified linux-x86 (does it support 64 bit binaries?) binaries which simplifies our execution environment as compared to compiling the compiler to WASM and writing JavaScript bindings. One concern I have is that the performance is quite poor - but I have only had the chance to evaluate it on an M1 MacBook Pro host so I am wondering if x86 translation is the cause of this poor performance? Is WebVM faster on an x86_64 host? If so, are there plans to add support for linux-arm64 virtualization so arm hosts can perform better?
2 replies
DDeno
Created by David Alsh on 3/8/2024 in #help
Rust: Unable to bootstrap MainWorker
My message was too long, moved it to a GitHub discussion: https://github.com/denoland/deno/discussions/22788
2 replies
DDeno
Created by David Alsh on 1/29/2024 in #help
How to call a JS function from Rust?
Hi, I'd like to call a JS function from Rust but I can't seem to find an example that does so. I got this far with the examples and blog tutorials.
// index.js
function add(a, b) {
return a + b
}

// Do I need these?
// globalThis.add = add
// export { add }
// index.js
function add(a, b) {
return a + b
}

// Do I need these?
// globalThis.add = add
// export { add }
// main.rs
async fn main_async() {
let main_module = resolve_path(
"./index.js",
env::current_dir().unwrap().join("js").as_path()
).unwrap();

let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(Rc::new(FsModuleLoader)),
..Default::default()
});

let mod_id = js_runtime.load_main_module(&main_module, None).await.unwrap();

let result = js_runtime.mod_evaluate(mod_id);

js_runtime.run_event_loop(PollEventLoopOptions::default()).await.unwrap();

result.await.unwrap();
}

fn main() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
runtime.block_on(main_async())
}
// main.rs
async fn main_async() {
let main_module = resolve_path(
"./index.js",
env::current_dir().unwrap().join("js").as_path()
).unwrap();

let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(Rc::new(FsModuleLoader)),
..Default::default()
});

let mod_id = js_runtime.load_main_module(&main_module, None).await.unwrap();

let result = js_runtime.mod_evaluate(mod_id);

js_runtime.run_event_loop(PollEventLoopOptions::default()).await.unwrap();

result.await.unwrap();
}

fn main() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
runtime.block_on(main_async())
}
How can I call add(1, 2) from rust?
15 replies