From bf8bb6ee97d0cbdce58e9d2f61c98033274769e9 Mon Sep 17 00:00:00 2001 From: Jeffrey Charles Date: Tue, 13 Aug 2024 09:49:14 -0400 Subject: [PATCH] Fix CI (#712) * Fix CI * Remove deprecated crates from workspace * Forgot one update to store --- Cargo.lock | 339 ----------------------- Cargo.toml | 2 - Makefile | 10 +- crates/cli/benches/benchmark.rs | 24 +- crates/cli/src/bytecode.rs | 47 ++-- crates/cli/tests/dylib_test.rs | 81 ++++-- crates/cli/tests/dynamic_linking_test.rs | 13 +- crates/javy/src/alloc.rs | 4 +- crates/javy/tests/misc.rs | 2 + 9 files changed, 111 insertions(+), 411 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39e786cc..ebfb31a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,16 +586,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -1011,21 +1001,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1299,101 +1274,6 @@ dependencies = [ "triomphe", ] -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" - -[[package]] -name = "hyper" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower", - "tower-service", - "tracing", -] - [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1885,23 +1765,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -2000,50 +1863,6 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.70", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "outref" version = "0.1.0" @@ -2104,26 +1923,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.70", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -2249,33 +2048,6 @@ dependencies = [ "rand", ] -[[package]] -name = "quickjs-wasm-rs" -version = "3.1.0" -dependencies = [ - "anyhow", - "once_cell", - "quickcheck", - "quickjs-wasm-sys", - "serde", - "serde_bytes", -] - -[[package]] -name = "quickjs-wasm-sys" -version = "1.2.1" -dependencies = [ - "anyhow", - "bindgen", - "cc", - "http-body-util", - "hyper", - "hyper-tls", - "hyper-util", - "tokio", - "walkdir", -] - [[package]] name = "quote" version = "1.0.36" @@ -2553,15 +2325,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -2574,29 +2337,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -2639,15 +2379,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_bytes" -version = "0.11.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" -dependencies = [ - "serde", -] - [[package]] name = "serde_derive" version = "1.0.204" @@ -3183,31 +2914,9 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2", - "tokio-macros", "windows-sys 0.48.0", ] -[[package]] -name = "tokio-macros" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.70", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "toml" version = "0.8.14" @@ -3253,33 +2962,6 @@ dependencies = [ "winnow 0.6.13", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - [[package]] name = "tracing" version = "0.1.40" @@ -3322,12 +3004,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "typed-arena" version = "2.0.2" @@ -3429,12 +3105,6 @@ dependencies = [ "ryu", ] -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "vergen" version = "8.3.1" @@ -3491,15 +3161,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 216069ad..1dc0aa48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,5 @@ [workspace] members = [ - "crates/quickjs-wasm-sys", - "crates/quickjs-wasm-rs", "crates/javy", "crates/apis", "crates/core", diff --git a/Makefile b/Makefile index 8bd7045f..974fac55 100644 --- a/Makefile +++ b/Makefile @@ -49,15 +49,7 @@ test-config: tests: test-javy test-core test-runner test-cli test-wpt test-config -fmt: fmt-quickjs-wasm-sys fmt-quickjs-wasm-rs fmt-javy fmt-apis fmt-core fmt-cli - -fmt-quickjs-wasm-sys: - cargo fmt --package=quickjs-wasm-sys -- --check - cargo clippy --package=quickjs-wasm-sys --target=wasm32-wasi --all-targets -- -D warnings - -fmt-quickjs-wasm-rs: - cargo fmt --package=quickjs-wasm-rs -- --check - cargo clippy --package=quickjs-wasm-rs --target=wasm32-wasi --all-targets -- -D warnings +fmt: fmt-javy fmt-apis fmt-core fmt-cli fmt-javy: cargo fmt --package=javy -- --check diff --git a/crates/cli/benches/benchmark.rs b/crates/cli/benches/benchmark.rs index a310b21b..9f62928a 100644 --- a/crates/cli/benches/benchmark.rs +++ b/crates/cli/benches/benchmark.rs @@ -7,7 +7,7 @@ use wasi_common::{ sync::WasiCtxBuilder, WasiCtx, }; -use wasmtime::{Engine, Linker, Module, Store}; +use wasmtime::{AsContextMut, Engine, Linker, Module, Store}; struct FunctionCase { name: String, @@ -84,22 +84,26 @@ impl FunctionCase { Ok(function_case) } - pub fn run(&self, linker: &mut Linker, mut store: &mut Store) -> Result<()> { + pub fn run( + &self, + linker: &mut Linker, + mut store: impl AsContextMut, + ) -> Result<()> { let js_module = match &self.precompiled_elf_bytes { Some(bytes) => unsafe { Module::deserialize(&self.engine, bytes) }?, None => Module::new(&self.engine, &self.wasm_bytes)?, }; - let consumer_instance = linker.instantiate(&mut store, &js_module)?; - linker.instance(&mut store, "consumer", consumer_instance)?; + let consumer_instance = linker.instantiate(store.as_context_mut(), &js_module)?; + linker.instance(store.as_context_mut(), "consumer", consumer_instance)?; linker - .get(&mut store, "consumer", "_start") + .get(store.as_context_mut(), "consumer", "_start") .unwrap() .into_func() .unwrap() - .typed::<(), ()>(&mut store)? - .call(&mut store, ())?; + .typed::<(), ()>(store.as_context())? + .call(store.as_context_mut(), ())?; Ok(()) } @@ -120,8 +124,8 @@ impl FunctionCase { "../../target/wasm32-wasi/release/javy_quickjs_provider_wizened.wasm", ))?, )?; - let instance = linker.instantiate(&mut store, &qjs_provider)?; - linker.instance(&mut store, "javy_quickjs_provider_v2", instance)?; + let instance = linker.instantiate(store.as_context_mut(), &qjs_provider)?; + linker.instance(store.as_context_mut(), "javy_quickjs_provider_v2", instance)?; } Ok((linker, store)) @@ -169,7 +173,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { |b, f| { b.iter_with_setup( || function_case.setup().unwrap(), - |(mut linker, mut store)| f.run(&mut linker, &mut store).unwrap(), + |(mut linker, mut store)| f.run(&mut linker, store.as_context_mut()).unwrap(), ) }, ); diff --git a/crates/cli/src/bytecode.rs b/crates/cli/src/bytecode.rs index 021595de..bbf15333 100644 --- a/crates/cli/src/bytecode.rs +++ b/crates/cli/src/bytecode.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use wasi_common::{sync::WasiCtxBuilder, WasiCtx}; -use wasmtime::{Engine, Instance, Linker, Memory, Module, Store}; +use wasmtime::{AsContextMut, Engine, Instance, Linker, Memory, Module, Store}; pub const QUICKJS_PROVIDER_MODULE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/provider.wasm")); @@ -8,9 +8,9 @@ pub const QUICKJS_PROVIDER_MODULE: &[u8] = pub fn compile_source(js_source_code: &[u8]) -> Result> { let (mut store, instance, memory) = create_wasm_env()?; let (js_src_ptr, js_src_len) = - copy_source_code_into_instance(js_source_code, &mut store, &instance, &memory)?; - let ret_ptr = call_compile(js_src_ptr, js_src_len, &mut store, &instance)?; - let bytecode = copy_bytecode_from_instance(ret_ptr, &mut store, &memory)?; + copy_source_code_into_instance(js_source_code, store.as_context_mut(), &instance, &memory)?; + let ret_ptr = call_compile(js_src_ptr, js_src_len, store.as_context_mut(), &instance)?; + let bytecode = copy_bytecode_from_instance(ret_ptr, store.as_context_mut(), &memory)?; Ok(bytecode) } @@ -24,29 +24,39 @@ fn create_wasm_env() -> Result<(Store, Instance, Memory)> { )?; let wasi = WasiCtxBuilder::new().inherit_stderr().build(); let mut store = Store::new(&engine, wasi); - let instance = linker.instantiate(&mut store, &module)?; - let memory = instance.get_memory(&mut store, "memory").unwrap(); + let instance = linker.instantiate(store.as_context_mut(), &module)?; + let memory = instance + .get_memory(store.as_context_mut(), "memory") + .unwrap(); Ok((store, instance, memory)) } fn copy_source_code_into_instance( js_source_code: &[u8], - mut store: &mut Store, + mut store: impl AsContextMut, instance: &Instance, memory: &Memory, ) -> Result<(u32, u32)> { - let realloc_fn = instance - .get_typed_func::<(u32, u32, u32, u32), u32>(&mut store, "canonical_abi_realloc")?; + let realloc_fn = instance.get_typed_func::<(u32, u32, u32, u32), u32>( + store.as_context_mut(), + "canonical_abi_realloc", + )?; let js_src_len = js_source_code.len().try_into()?; let original_ptr = 0; let original_size = 0; let alignment = 1; let size = js_src_len; - let js_source_ptr = - realloc_fn.call(&mut store, (original_ptr, original_size, alignment, size))?; + let js_source_ptr = realloc_fn.call( + store.as_context_mut(), + (original_ptr, original_size, alignment, size), + )?; - memory.write(&mut store, js_source_ptr.try_into()?, js_source_code)?; + memory.write( + store.as_context_mut(), + js_source_ptr.try_into()?, + js_source_code, + )?; Ok((js_source_ptr, js_src_len)) } @@ -54,29 +64,30 @@ fn copy_source_code_into_instance( fn call_compile( js_src_ptr: u32, js_src_len: u32, - mut store: &mut Store, + mut store: impl AsContextMut, instance: &Instance, ) -> Result { - let compile_src_fn = instance.get_typed_func::<(u32, u32), u32>(&mut store, "compile_src")?; + let compile_src_fn = + instance.get_typed_func::<(u32, u32), u32>(store.as_context_mut(), "compile_src")?; let ret_ptr = compile_src_fn - .call(&mut store, (js_src_ptr, js_src_len)) + .call(store.as_context_mut(), (js_src_ptr, js_src_len)) .map_err(|_| anyhow!("JS compilation failed"))?; Ok(ret_ptr) } fn copy_bytecode_from_instance( ret_ptr: u32, - mut store: &mut Store, + mut store: impl AsContextMut, memory: &Memory, ) -> Result> { let mut ret_buffer = [0; 8]; - memory.read(&mut store, ret_ptr.try_into()?, &mut ret_buffer)?; + memory.read(store.as_context_mut(), ret_ptr.try_into()?, &mut ret_buffer)?; let bytecode_ptr = u32::from_le_bytes(ret_buffer[0..4].try_into()?); let bytecode_len = u32::from_le_bytes(ret_buffer[4..8].try_into()?); let mut bytecode = vec![0; bytecode_len.try_into()?]; - memory.read(&mut store, bytecode_ptr.try_into()?, &mut bytecode)?; + memory.read(store.as_context(), bytecode_ptr.try_into()?, &mut bytecode)?; Ok(bytecode) } diff --git a/crates/cli/tests/dylib_test.rs b/crates/cli/tests/dylib_test.rs index 24c4a3ac..89463072 100644 --- a/crates/cli/tests/dylib_test.rs +++ b/crates/cli/tests/dylib_test.rs @@ -2,7 +2,7 @@ use anyhow::Result; use std::boxed::Box; use std::str; use wasi_common::{pipe::WritePipe, sync::WasiCtxBuilder, WasiCtx, WasiFile}; -use wasmtime::{Engine, Instance, Linker, Store}; +use wasmtime::{AsContextMut, Engine, Instance, Linker, Store}; mod common; @@ -49,9 +49,10 @@ fn run_js_src(js_src: &str, stderr: &T) -> Result let (instance, mut store) = create_wasm_env(stderr)?; let eval_bytecode_func = - instance.get_typed_func::<(u32, u32), ()>(&mut store, "eval_bytecode")?; - let (bytecode_ptr, bytecode_len) = compile_src(js_src.as_bytes(), &instance, &mut store)?; - eval_bytecode_func.call(&mut store, (bytecode_ptr, bytecode_len))?; + instance.get_typed_func::<(u32, u32), ()>(store.as_context_mut(), "eval_bytecode")?; + let (bytecode_ptr, bytecode_len) = + compile_src(js_src.as_bytes(), &instance, store.as_context_mut())?; + eval_bytecode_func.call(store.as_context_mut(), (bytecode_ptr, bytecode_len))?; Ok(()) } @@ -62,11 +63,14 @@ fn run_invoke( ) -> Result<()> { let (instance, mut store) = create_wasm_env(stderr)?; - let invoke_func = instance.get_typed_func::<(u32, u32, u32, u32), ()>(&mut store, "invoke")?; - let (bytecode_ptr, bytecode_len) = compile_src(js_src.as_bytes(), &instance, &mut store)?; - let (fn_name_ptr, fn_name_len) = copy_func_name(fn_to_invoke, &instance, &mut store)?; + let invoke_func = + instance.get_typed_func::<(u32, u32, u32, u32), ()>(store.as_context_mut(), "invoke")?; + let (bytecode_ptr, bytecode_len) = + compile_src(js_src.as_bytes(), &instance, store.as_context_mut())?; + let (fn_name_ptr, fn_name_len) = + copy_func_name(fn_to_invoke, &instance, store.as_context_mut())?; invoke_func.call( - &mut store, + store.as_context_mut(), (bytecode_ptr, bytecode_len, fn_name_ptr, fn_name_len), )?; Ok(()) @@ -84,7 +88,7 @@ fn create_wasm_env( let module = common::create_quickjs_provider_module(&engine)?; let mut store = Store::new(&engine, wasi); - let instance = linker.instantiate(&mut store, &module)?; + let instance = linker.instantiate(store.as_context_mut(), &module)?; Ok((instance, store)) } @@ -92,17 +96,28 @@ fn create_wasm_env( fn compile_src( js_src: &[u8], instance: &Instance, - mut store: &mut Store, + mut store: impl AsContextMut, ) -> Result<(u32, u32)> { - let memory = instance.get_memory(&mut store, "memory").unwrap(); - let compile_src_func = instance.get_typed_func::<(u32, u32), u32>(&mut store, "compile_src")?; - - let js_src_ptr = allocate_memory(instance, store, 1, js_src.len().try_into()?)?; - memory.write(&mut store, js_src_ptr.try_into()?, js_src)?; + let memory = instance + .get_memory(store.as_context_mut(), "memory") + .unwrap(); + let compile_src_func = + instance.get_typed_func::<(u32, u32), u32>(store.as_context_mut(), "compile_src")?; + + let js_src_ptr = allocate_memory( + instance, + store.as_context_mut(), + 1, + js_src.len().try_into()?, + )?; + memory.write(store.as_context_mut(), js_src_ptr.try_into()?, js_src)?; - let ret_ptr = compile_src_func.call(&mut store, (js_src_ptr, js_src.len().try_into()?))?; + let ret_ptr = compile_src_func.call( + store.as_context_mut(), + (js_src_ptr, js_src.len().try_into()?), + )?; let mut ret_buffer = [0; 8]; - memory.read(&mut store, ret_ptr.try_into()?, &mut ret_buffer)?; + memory.read(store.as_context(), ret_ptr.try_into()?, &mut ret_buffer)?; let bytecode_ptr = u32::from_le_bytes(ret_buffer[0..4].try_into()?); let bytecode_len = u32::from_le_bytes(ret_buffer[4..8].try_into()?); @@ -112,27 +127,43 @@ fn compile_src( fn copy_func_name( fn_name: &str, instance: &Instance, - mut store: &mut Store, + mut store: impl AsContextMut, ) -> Result<(u32, u32)> { - let memory = instance.get_memory(&mut store, "memory").unwrap(); + let memory = instance + .get_memory(store.as_context_mut(), "memory") + .unwrap(); let fn_name_bytes = fn_name.as_bytes(); - let fn_name_ptr = allocate_memory(instance, store, 1, fn_name_bytes.len().try_into()?)?; - memory.write(&mut store, fn_name_ptr.try_into()?, fn_name_bytes)?; + let fn_name_ptr = allocate_memory( + instance, + store.as_context_mut(), + 1, + fn_name_bytes.len().try_into()?, + )?; + memory.write( + store.as_context_mut(), + fn_name_ptr.try_into()?, + fn_name_bytes, + )?; Ok((fn_name_ptr, fn_name_bytes.len().try_into()?)) } fn allocate_memory( instance: &Instance, - mut store: &mut Store, + mut store: impl AsContextMut, alignment: u32, new_size: u32, ) -> Result { - let realloc_func = instance - .get_typed_func::<(u32, u32, u32, u32), u32>(&mut store, "canonical_abi_realloc")?; + let realloc_func = instance.get_typed_func::<(u32, u32, u32, u32), u32>( + store.as_context_mut(), + "canonical_abi_realloc", + )?; let orig_ptr = 0; let orig_size = 0; realloc_func - .call(&mut store, (orig_ptr, orig_size, alignment, new_size)) + .call( + store.as_context_mut(), + (orig_ptr, orig_size, alignment, new_size), + ) .map_err(Into::into) } diff --git a/crates/cli/tests/dynamic_linking_test.rs b/crates/cli/tests/dynamic_linking_test.rs index cd5a0d27..cd2dc340 100644 --- a/crates/cli/tests/dynamic_linking_test.rs +++ b/crates/cli/tests/dynamic_linking_test.rs @@ -7,7 +7,7 @@ use uuid::Uuid; use wasi_common::pipe::{ReadPipe, WritePipe}; use wasi_common::sync::WasiCtxBuilder; use wasi_common::WasiCtx; -use wasmtime::{Config, Engine, ExternType, Linker, Module, Store}; +use wasmtime::{AsContextMut, Config, Engine, ExternType, Linker, Module, Store}; mod common; @@ -223,15 +223,16 @@ fn invoke_fn_on_generated_module( let quickjs_provider_module = common::create_quickjs_provider_module(&engine)?; let js_module = Module::from_binary(&engine, &js_wasm)?; - let quickjs_provider_instance = linker.instantiate(&mut store, &quickjs_provider_module)?; + let quickjs_provider_instance = + linker.instantiate(store.as_context_mut(), &quickjs_provider_module)?; linker.instance( - &mut store, + store.as_context_mut(), "javy_quickjs_provider_v2", quickjs_provider_instance, )?; - let js_instance = linker.instantiate(&mut store, &js_module)?; - let func = js_instance.get_typed_func::<(), ()>(&mut store, func)?; - func.call(&mut store, ())?; + let js_instance = linker.instantiate(store.as_context_mut(), &js_module)?; + let func = js_instance.get_typed_func::<(), ()>(store.as_context_mut(), func)?; + func.call(store.as_context_mut(), ())?; drop(store); // Need to drop store to access contents of stderr. let log_output = stderr.try_into_inner().unwrap().into_inner(); diff --git a/crates/javy/src/alloc.rs b/crates/javy/src/alloc.rs index 706e8b13..ee6c23ad 100644 --- a/crates/javy/src/alloc.rs +++ b/crates/javy/src/alloc.rs @@ -18,8 +18,8 @@ const ZERO_SIZE_ALLOCATION_PTR: *mut u8 = 1 as _; /// /// 1. Allocate memory of new_size with alignment. /// 2. If original_ptr != 0. -/// a. copy min(new_size, original_size) bytes from original_ptr to new memory. -/// b. de-allocate original_ptr. +/// a. copy min(new_size, original_size) bytes from original_ptr to new memory. +/// b. de-allocate original_ptr. /// 3. Return new memory ptr. /// /// # Safety diff --git a/crates/javy/tests/misc.rs b/crates/javy/tests/misc.rs index 8f4dd5a9..b359c6ab 100644 --- a/crates/javy/tests/misc.rs +++ b/crates/javy/tests/misc.rs @@ -1,4 +1,6 @@ +#[cfg(feature = "json")] use anyhow::Result; +#[cfg(feature = "json")] use javy::{quickjs::context::EvalOptions, Config, Runtime}; #[cfg(feature = "json")]