diff --git a/.github/workflows/build-assets.yml b/.github/workflows/build-assets.yml index b5103502..85597b7c 100644 --- a/.github/workflows/build-assets.yml +++ b/.github/workflows/build-assets.yml @@ -36,43 +36,43 @@ jobs: - name: Make core run: make core - - name: Upload quickjs_provider to artifacts + - name: Upload plugin to artifacts uses: actions/upload-artifact@v4 with: - name: provider - path: target/wasm32-wasip1/release/javy_quickjs_provider.wasm + name: plugin + path: target/wasm32-wasip1/release/plugin.wasm - - name: Wizen and archive wizened quickjs_provider + - name: Wizen and archive wizened plugin run: | - wizer target/wasm32-wasip1/release/javy_quickjs_provider.wasm --allow-wasi --init-func initialize_runtime --wasm-bulk-memory true -o target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm - gzip -k -f target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm && mv target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm.gz javy-quickjs_provider.wasm.gz + wizer target/wasm32-wasip1/release/plugin.wasm --allow-wasi --init-func initialize_runtime --wasm-bulk-memory true -o target/wasm32-wasip1/release/plugin_wizened.wasm + gzip -k -f target/wasm32-wasip1/release/plugin_wizened.wasm && mv target/wasm32-wasip1/release/plugin_wizened.wasm.gz plugin.wasm.gz - - name: Upload archived quickjs_provider to artifacts + - name: Upload archived plugin to artifacts uses: actions/upload-artifact@v4 with: - name: javy-quickjs_provider.wasm.gz - path: javy-quickjs_provider.wasm.gz + name: plugin.wasm.gz + path: plugin.wasm.gz - - name: Upload archived quickjs_provider to release + - name: Upload archived plugin to release if: github.event_name == 'release' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release upload ${{ github.event.release.tag_name }} javy-quickjs_provider.wasm.gz + run: gh release upload ${{ github.event.release.tag_name }} plugin.wasm.gz - - name: Generate archived quickjs_provider hash - run: shasum -a 256 javy-quickjs_provider.wasm.gz | awk '{ print $1 }' > javy-quickjs_provider.wasm.gz.sha256 + - name: Generate archived plugin hash + run: shasum -a 256 plugin.wasm.gz | awk '{ print $1 }' > plugin.wasm.gz.sha256 - name: Upload asset hash to artifacts uses: actions/upload-artifact@v4 with: - name: javy-quickjs_provider.wasm.gz.sha256 - path: javy-quickjs_provider.wasm.gz.sha256 + name: plugin.wasm.gz.sha256 + path: plugin.wasm.gz.sha256 - name: Upload asset hash to release if: github.event_name == 'release' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release upload ${{ github.event.release.tag_name }} javy-quickjs_provider.wasm.gz.sha256 + run: gh release upload ${{ github.event.release.tag_name }} plugin.wasm.gz.sha256 compile_cli: name: compile_cli-${{ matrix.name }} @@ -126,7 +126,7 @@ jobs: - uses: actions/download-artifact@v4 with: - name: provider + name: plugin path: target/wasm32-wasip1/release/ - name: Build CLI ${{ matrix.os }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d037fe47..b6e0d968 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,11 +51,11 @@ jobs: - name: Lint Runner run: cargo clippy --package=javy-runner -- -D warnings - - name: Upload quickjs_provider to artifacts + - name: Upload plugin to artifacts uses: actions/upload-artifact@v4 with: - name: provider - path: target/wasm32-wasip1/release/javy_quickjs_provider.wasm + name: plugin + path: target/wasm32-wasip1/release/plugin.wasm cli: name: test_cli @@ -70,7 +70,7 @@ jobs: - uses: actions/download-artifact@v4 with: - name: provider + name: plugin path: target/wasm32-wasip1/release/ - name: Test CLI diff --git a/crates/cli/benches/benchmark.rs b/crates/cli/benches/benchmark.rs index aca1085b..4f77fa6d 100644 --- a/crates/cli/benches/benchmark.rs +++ b/crates/cli/benches/benchmark.rs @@ -118,14 +118,14 @@ impl FunctionCase { let mut store = Store::new(&self.engine, wasi); if let Linking::Dynamic = self.linking { - let qjs_provider = Module::new( + let plugin = Module::new( &self.engine, fs::read(Path::new( - "../../target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm", + "../../target/wasm32-wasip1/release/plugin_wizened.wasm", ))?, )?; - let instance = linker.instantiate(store.as_context_mut(), &qjs_provider)?; - linker.instance(store.as_context_mut(), "javy_quickjs_provider_v2", instance)?; + let instance = linker.instantiate(store.as_context_mut(), &plugin)?; + linker.instance(store.as_context_mut(), "javy_quickjs_provider_v3", instance)?; } Ok((linker, store)) diff --git a/crates/cli/build.rs b/crates/cli/build.rs index 8e7a547a..17d8995c 100644 --- a/crates/cli/build.rs +++ b/crates/cli/build.rs @@ -8,22 +8,22 @@ use anyhow::Result; fn main() -> Result<()> { if let Ok("cargo-clippy") = env::var("CARGO_CFG_FEATURE").as_ref().map(String::as_str) { - stub_javy_core_for_clippy() + stub_plugin_for_clippy() } else { - copy_javy_core() + copy_plugin() } } -// When using clippy, we need to write stubbed provider.wasm file to ensure -// compilation succeeds. This skips building the actual provider.wasm that would +// When using clippy, we need to write stubbed plugin.wasm file to ensure +// compilation succeeds. This skips building the actual plugin.wasm that would // be injected into the CLI binary. -fn stub_javy_core_for_clippy() -> Result<()> { +fn stub_plugin_for_clippy() -> Result<()> { let out_dir = PathBuf::from(env::var("OUT_DIR")?); - let provider_path = out_dir.join("provider.wasm"); + let plugin_path = out_dir.join("plugin.wasm"); - if !provider_path.exists() { - std::fs::write(provider_path, [])?; - println!("cargo:warning=using stubbed provider.wasm for static analysis purposes..."); + if !plugin_path.exists() { + std::fs::write(plugin_path, [])?; + println!("cargo:warning=using stubbed plugin.wasm for static analysis purposes..."); } Ok(()) } @@ -34,8 +34,8 @@ fn read_file(path: impl AsRef) -> Result> { Ok(buf) } -// Copy the provider binary build from the `core` crate -fn copy_javy_core() -> Result<()> { +// Copy the plugin binary build from the `core` crate +fn copy_plugin() -> Result<()> { let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR")?; let module_path = PathBuf::from(&cargo_manifest_dir) .parent() @@ -43,8 +43,8 @@ fn copy_javy_core() -> Result<()> { .parent() .unwrap() .join("target/wasm32-wasip1/release"); - let quickjs_provider_path = module_path.join("javy_quickjs_provider.wasm"); - let quickjs_provider_wizened_path = module_path.join("javy_quickjs_provider_wizened.wasm"); + let plugin_path = module_path.join("plugin.wasm"); + let plugin_wizened_path = module_path.join("plugin_wizened.wasm"); let mut wizer = wizer::Wizer::new(); let wizened = wizer @@ -52,20 +52,17 @@ fn copy_javy_core() -> Result<()> { .keep_init_func(true) // Necessary for static codegen. .allow_wasi(true)? .wasm_bulk_memory(true) - .run(read_file(&quickjs_provider_path)?.as_slice())?; - fs::File::create(&quickjs_provider_wizened_path)?.write_all(&wizened)?; + .run(read_file(&plugin_path)?.as_slice())?; + fs::File::create(&plugin_wizened_path)?.write_all(&wizened)?; - println!( - "cargo:rerun-if-changed={}", - quickjs_provider_path.to_str().unwrap() - ); + println!("cargo:rerun-if-changed={}", plugin_path.to_str().unwrap()); println!("cargo:rerun-if-changed=build.rs"); - if quickjs_provider_wizened_path.exists() { + if plugin_wizened_path.exists() { let out_dir = env::var("OUT_DIR")?; - let copied_provider_path = Path::new(&out_dir).join("provider.wasm"); + let copied_plugin_path = Path::new(&out_dir).join("plugin.wasm"); - fs::copy(&quickjs_provider_wizened_path, copied_provider_path)?; + fs::copy(&plugin_wizened_path, copied_plugin_path)?; } Ok(()) } diff --git a/crates/cli/src/bytecode.rs b/crates/cli/src/bytecode.rs index e0657f86..aecd054c 100644 --- a/crates/cli/src/bytecode.rs +++ b/crates/cli/src/bytecode.rs @@ -2,10 +2,10 @@ use anyhow::{anyhow, Result}; use wasi_common::{sync::WasiCtxBuilder, WasiCtx}; use wasmtime::{AsContextMut, Engine, Instance, Linker, Memory, Module, Store}; -use crate::providers::Provider; +use crate::plugins::Plugin; -pub fn compile_source(provider: &Provider, js_source_code: &[u8]) -> Result> { - let (mut store, instance, memory) = create_wasm_env(provider)?; +pub fn compile_source(plugin: &Plugin, js_source_code: &[u8]) -> Result> { + let (mut store, instance, memory) = create_wasm_env(plugin)?; let (js_src_ptr, js_src_len) = 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)?; @@ -13,9 +13,9 @@ pub fn compile_source(provider: &Provider, js_source_code: &[u8]) -> Result Result<(Store, Instance, Memory)> { +fn create_wasm_env(plugin: &Plugin) -> Result<(Store, Instance, Memory)> { let engine = Engine::default(); - let module = Module::new(&engine, provider.as_bytes())?; + let module = Module::new(&engine, plugin.as_bytes())?; let mut linker = Linker::new(&engine); wasi_common::sync::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker( &mut linker, diff --git a/crates/cli/src/codegen/builder.rs b/crates/cli/src/codegen/builder.rs index 7df7414d..ff02a5b3 100644 --- a/crates/cli/src/codegen/builder.rs +++ b/crates/cli/src/codegen/builder.rs @@ -1,7 +1,7 @@ use crate::{ codegen::{CodeGenType, Generator}, js_config::JsConfig, - providers::Provider, + plugins::Plugin, }; use anyhow::{bail, Result}; use std::path::PathBuf; @@ -50,8 +50,8 @@ impl WitOptions { /// A code generation builder. #[derive(Default)] pub(crate) struct CodeGenBuilder { - /// The provider to use. - provider: Provider, + /// The plugin to use. + plugin: Plugin, /// WIT options for code generation. wit_opts: WitOptions, /// Whether to compress the original JS source. @@ -64,9 +64,9 @@ impl CodeGenBuilder { Self::default() } - /// Set the provider. - pub fn provider(&mut self, provider: Provider) -> &mut Self { - self.provider = provider; + /// Set the plugin. + pub fn plugin(&mut self, plugin: Plugin) -> &mut Self { + self.plugin = plugin; self } @@ -89,7 +89,7 @@ impl CodeGenBuilder { bail!("Cannot set JS runtime options when building a dynamic module") } } - let mut generator = Generator::new(ty, js_runtime_config, self.provider); + let mut generator = Generator::new(ty, js_runtime_config, self.plugin); generator.source_compression = self.source_compression; generator.wit_opts = self.wit_opts; Ok(generator) diff --git a/crates/cli/src/codegen/mod.rs b/crates/cli/src/codegen/mod.rs index 64695cfe..5fac5e3a 100644 --- a/crates/cli/src/codegen/mod.rs +++ b/crates/cli/src/codegen/mod.rs @@ -26,11 +26,11 @@ //! contains instructions to execute that bytecode through dynamic linking //! at runtime. //! -//! Dynamic code generation requires a provider module to be used and linked +//! Dynamic code generation requires a plugin module to be used and linked //! against at runtime in order to execute the JavaScript bytecode. This -//! operation involves carefully ensuring that a given provider version matches -//! the provider version of the imports requested by the generated Wasm module -//! as well as ensuring that any features available in the provider match the +//! operation involves carefully ensuring that a given plugin version matches +//! the plugin version of the imports requested by the generated Wasm module +//! as well as ensuring that any features available in the plugin match the //! features requsted by the JavaScript bytecode. mod builder; @@ -50,7 +50,7 @@ use wasi_common::{pipe::ReadPipe, sync::WasiCtxBuilder, WasiCtx}; use wasm_opt::{OptimizationOptions, ShrinkLevel}; use wizer::{Linker, Wizer}; -use crate::{js_config::JsConfig, providers::Provider, JS}; +use crate::{js_config::JsConfig, plugins::Plugin, JS}; use anyhow::Result; static mut WASI: OnceLock = OnceLock::new(); @@ -111,8 +111,8 @@ pub(crate) struct Generator { pub ty: CodeGenType, /// JS runtime config. pub js_runtime_config: JsConfig, - /// Provider to use. - pub provider: Provider, + /// Plugin to use. + pub plugin: Plugin, /// JavaScript function exports. function_exports: Exports, /// Whether to embed the compressed JS source in the generated module. @@ -123,12 +123,12 @@ pub(crate) struct Generator { impl Generator { /// Creates a new [`Generator`]. - pub fn new(ty: CodeGenType, js_runtime_config: JsConfig, provider: Provider) -> Self { + pub fn new(ty: CodeGenType, js_runtime_config: JsConfig, plugin: Plugin) -> Self { Self { ty, js_runtime_config, source_compression: true, - provider, + plugin, function_exports: Default::default(), wit_opts: Default::default(), } @@ -160,7 +160,7 @@ impl Generator { Ok(linker) })))? .wasm_bulk_memory(true) - .run(self.provider.as_bytes())?; + .run(self.plugin.as_bytes())?; config.parse(&wasm)? } CodeGenType::Dynamic => Module::with_config(config), @@ -192,7 +192,7 @@ impl Generator { )) } CodeGenType::Dynamic => { - let import_namespace = self.provider.import_namespace()?; + let import_namespace = self.plugin.import_namespace()?; let canonical_abi_realloc_type = module.types.add( &[ValType::I32, ValType::I32, ValType::I32, ValType::I32], &[ValType::I32], @@ -211,11 +211,8 @@ impl Generator { &[ValType::I32, ValType::I32, ValType::I32, ValType::I32], &[], ); - let (invoke_fn_id, _) = module.add_import_func( - &self.provider.import_namespace()?, - "invoke", - invoke_type, - ); + let (invoke_fn_id, _) = + module.add_import_func(&self.plugin.import_namespace()?, "invoke", invoke_type); let (memory_id, _) = module.add_import_memory( &import_namespace, @@ -244,14 +241,14 @@ impl Generator { js: &JS, imports: &Identifiers, ) -> Result { - let bytecode = js.compile(&self.provider)?; + let bytecode = js.compile(&self.plugin)?; let bytecode_len: i32 = bytecode.len().try_into()?; let bytecode_data = module.data.add(DataKind::Passive, bytecode); let mut main = FunctionBuilder::new(&mut module.types, &[], &[]); let bytecode_ptr_local = module.locals.add(ValType::I32); main.func_body() - // Allocate memory in javy_quickjs_provider for bytecode array. + // Allocate memory in plugin instance for bytecode array. .i32_const(0) // orig ptr .i32_const(0) // orig size .i32_const(1) // alignment @@ -461,7 +458,7 @@ fn print_wat(_wasm_binary: &[u8]) -> Result<()> { #[cfg(test)] mod test { use crate::js_config::JsConfig; - use crate::providers::Provider; + use crate::plugins::Plugin; use super::Generator; use super::WitOptions; @@ -472,11 +469,11 @@ mod test { let gen = Generator::new( crate::codegen::CodeGenType::Dynamic, JsConfig::default(), - Provider::Default, + Plugin::Default, ); assert!(!gen.js_runtime_config.has_configs()); assert!(gen.source_compression); - assert!(matches!(gen.provider, Provider::Default)); + assert!(matches!(gen.plugin, Plugin::Default)); assert_eq!(gen.wit_opts, WitOptions::default()); Ok(()) diff --git a/crates/cli/src/commands.rs b/crates/cli/src/commands.rs index 5249563e..848d7736 100644 --- a/crates/cli/src/commands.rs +++ b/crates/cli/src/commands.rs @@ -1,4 +1,4 @@ -use crate::{js_config::JsConfig, option::OptionMeta, option_group, providers::Provider}; +use crate::{js_config::JsConfig, option::OptionMeta, option_group, plugins::Plugin}; use anyhow::{anyhow, Result}; use clap::{ builder::{StringValueParser, TypedValueParser, ValueParserFactory}, @@ -45,7 +45,7 @@ pub enum Command { /// Generates WebAssembly from a JavaScript source. #[command(arg_required_else_help = true)] Build(BuildCommandOpts), - /// Emits the provider binary that is required to run dynamically + /// Emits the plugin binary that is required to run dynamically /// linked WebAssembly modules. EmitProvider(EmitProviderCommandOpts), } @@ -61,8 +61,8 @@ pub struct CompileCommandOpts { pub output: PathBuf, #[arg(short)] - /// Creates a smaller module that requires a dynamically linked QuickJS provider Wasm - /// module to execute (see `emit-provider` command). + /// Creates a smaller module that requires a dynamically linked QuickJS + /// plugin Wasm module to execute (see `emit-provider` command). pub dynamic: bool, #[structopt(long)] @@ -107,7 +107,7 @@ pub struct BuildCommandOpts { #[derive(Debug, Parser)] pub struct EmitProviderCommandOpts { #[structopt(short, long)] - /// Output path for the provider binary (default is stdout). + /// Output path for the plugin binary (default is stdout). pub out: Option, } @@ -182,7 +182,7 @@ option_group! { #[derive(Clone, Debug)] pub enum CodegenOption { /// Creates a smaller module that requires a dynamically linked QuickJS - /// provider Wasm module to execute (see `emit-provider` command). + /// plugin Wasm module to execute (see `emit-provider` command). Dynamic(bool), /// Optional path to WIT file describing exported functions. Only /// supports function exports with no arguments and no return values. @@ -278,10 +278,10 @@ impl TypedValueParser for JsGroupOptionParser { impl JsConfig { /// Build a JS runtime config from valid runtime config values. pub(super) fn from_group_values( - provider: &Provider, + plugin: &Plugin, group_values: Vec, ) -> Result { - let supported_properties = provider.config_schema()?; + let supported_properties = plugin.config_schema()?; let mut supported_names = HashSet::new(); for property in &supported_properties { @@ -331,7 +331,7 @@ mod tests { use crate::{ commands::{JsGroupOption, JsGroupValue}, js_config::JsConfig, - providers::Provider, + plugins::Plugin, }; use super::{CodegenOption, CodegenOptionGroup, GroupOption}; @@ -339,7 +339,7 @@ mod tests { #[test] fn js_config_from_config_values() -> Result<()> { - let group = JsConfig::from_group_values(&Provider::Default, vec![])?; + let group = JsConfig::from_group_values(&Plugin::Default, vec![])?; assert!(!group.has_configs()); assert_eq!(group.get("redirect-stdout-to-stderr"), None); assert_eq!(group.get("javy-json"), None); @@ -348,7 +348,7 @@ mod tests { assert_eq!(group.get("text-encoding"), None); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "redirect-stdout-to-stderr".to_string(), enabled: false, @@ -357,7 +357,7 @@ mod tests { assert_eq!(group.get("redirect-stdout-to-stderr"), Some(false)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "redirect-stdout-to-stderr".to_string(), enabled: true, @@ -366,7 +366,7 @@ mod tests { assert_eq!(group.get("redirect-stdout-to-stderr"), Some(true)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "javy-json".to_string(), enabled: false, @@ -375,7 +375,7 @@ mod tests { assert_eq!(group.get("javy-json"), Some(false)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "javy-json".to_string(), enabled: true, @@ -384,7 +384,7 @@ mod tests { assert_eq!(group.get("javy-json"), Some(true)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "javy-stream-io".to_string(), enabled: false, @@ -393,7 +393,7 @@ mod tests { assert_eq!(group.get("javy-stream-io"), Some(false)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "javy-stream-io".to_string(), enabled: true, @@ -402,7 +402,7 @@ mod tests { assert_eq!(group.get("javy-stream-io"), Some(true)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "simd-json-builtins".to_string(), enabled: false, @@ -411,7 +411,7 @@ mod tests { assert_eq!(group.get("simd-json-builtins"), Some(false)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "simd-json-builtins".to_string(), enabled: true, @@ -420,7 +420,7 @@ mod tests { assert_eq!(group.get("simd-json-builtins"), Some(true)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "text-encoding".to_string(), enabled: false, @@ -429,7 +429,7 @@ mod tests { assert_eq!(group.get("text-encoding"), Some(false)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![JsGroupValue::Option(JsGroupOption { name: "text-encoding".to_string(), enabled: true, @@ -438,7 +438,7 @@ mod tests { assert_eq!(group.get("text-encoding"), Some(true)); let group = JsConfig::from_group_values( - &Provider::Default, + &Plugin::Default, vec![ JsGroupValue::Option(JsGroupOption { name: "redirect-stdout-to-stderr".to_string(), diff --git a/crates/cli/src/js.rs b/crates/cli/src/js.rs index d158a246..5adb57d7 100644 --- a/crates/cli/src/js.rs +++ b/crates/cli/src/js.rs @@ -24,7 +24,7 @@ use swc_core::{ }, }; -use crate::providers::Provider; +use crate::plugins::Plugin; #[derive(Clone, Debug)] pub struct JS { @@ -50,9 +50,9 @@ impl JS { self.source_code.as_bytes() } - /// Compiles a JavaScript source to bytecode using a QuickJS provider. - pub fn compile(&self, provider: &Provider) -> Result> { - provider.compile_source(self.source_code.as_bytes()) + /// Compiles a JavaScript source to bytecode using a QuickJS plugin. + pub fn compile(&self, plugin: &Plugin) -> Result> { + plugin.compile_source(self.source_code.as_bytes()) } pub fn compress(&self) -> Result> { diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index f174bca6..1e0e0160 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -4,7 +4,7 @@ mod commands; mod js; mod js_config; mod option; -mod providers; +mod plugins; mod wit; use crate::codegen::WitOptions; @@ -15,7 +15,7 @@ use codegen::{CodeGenBuilder, CodeGenType}; use commands::CodegenOptionGroup; use js::JS; use js_config::JsConfig; -use providers::Provider; +use plugins::Plugin; use std::fs; use std::fs::File; use std::io::Write; @@ -24,7 +24,7 @@ fn main() -> Result<()> { let args = Cli::parse(); match &args.command { - Command::EmitProvider(opts) => emit_provider(opts), + Command::EmitProvider(opts) => emit_plugin(opts), Command::Compile(opts) => { eprintln!( r#" @@ -49,7 +49,7 @@ fn main() -> Result<()> { let config = JsConfig::default(); let mut gen = if opts.dynamic { - builder.provider(Provider::V2); + builder.plugin(Plugin::V2); builder.build(CodeGenType::Dynamic, config)? } else { builder.build(CodeGenType::Static, config)? @@ -68,7 +68,7 @@ fn main() -> Result<()> { .wit_opts(codegen.wit) .source_compression(codegen.source_compression); - let js_opts = JsConfig::from_group_values(&Provider::Default, opts.js.clone())?; + let js_opts = JsConfig::from_group_values(&Plugin::Default, opts.js.clone())?; let mut gen = if codegen.dynamic { builder.build(CodeGenType::Dynamic, js_opts)? } else { @@ -83,11 +83,11 @@ fn main() -> Result<()> { } } -fn emit_provider(opts: &EmitProviderCommandOpts) -> Result<()> { +fn emit_plugin(opts: &EmitProviderCommandOpts) -> Result<()> { let mut file: Box = match opts.out.as_ref() { Some(path) => Box::new(File::create(path)?), _ => Box::new(std::io::stdout()), }; - file.write_all(Provider::Default.as_bytes())?; + file.write_all(Plugin::Default.as_bytes())?; Ok(()) } diff --git a/crates/cli/src/providers.rs b/crates/cli/src/plugins.rs similarity index 81% rename from crates/cli/src/providers.rs rename to crates/cli/src/plugins.rs index 6e4e190f..57e9aea9 100644 --- a/crates/cli/src/providers.rs +++ b/crates/cli/src/plugins.rs @@ -8,12 +8,12 @@ use std::{ use wasi_common::{pipe::WritePipe, sync::WasiCtxBuilder}; use wasmtime::{AsContextMut, Engine, Linker}; -const QUICKJS_PROVIDER_MODULE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/provider.wasm")); +const PLUGIN_MODULE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/plugin.wasm")); -/// Use the legacy provider when using the `compile -d` command. +/// Use the legacy plugin when using the `compile -d` command. const QUICKJS_PROVIDER_V2_MODULE: &[u8] = include_bytes!("./javy_quickjs_provider_v2.wasm"); -/// A property that is in the config schema returned by the provider. +/// A property that is in the config schema returned by the plugin. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub(crate) struct JsConfigProperty { @@ -23,36 +23,36 @@ pub(crate) struct JsConfigProperty { pub(crate) doc: String, } -/// Different providers that are available. +/// Different plugins that are available. #[derive(Debug)] -pub enum Provider { - /// The default provider. +pub enum Plugin { + /// The default plugin. Default, - /// A provider for use with the `compile` to maintain backward compatibility. + /// A plugin for use with the `compile` to maintain backward compatibility. V2, } -impl Default for Provider { +impl Default for Plugin { fn default() -> Self { Self::Default } } -impl Provider { - /// Returns the provider Wasm module as a byte slice. +impl Plugin { + /// Returns the plugin Wasm module as a byte slice. pub fn as_bytes(&self) -> &[u8] { match self { - Self::Default => QUICKJS_PROVIDER_MODULE, + Self::Default => PLUGIN_MODULE, Self::V2 => QUICKJS_PROVIDER_V2_MODULE, } } - /// Uses the provider to generate QuickJS bytecode. + /// Uses the plugin to generate QuickJS bytecode. pub fn compile_source(&self, js_source_code: &[u8]) -> Result> { bytecode::compile_source(self, js_source_code) } - /// The import namespace to use for this provider. + /// The import namespace to use for this plugin. pub fn import_namespace(&self) -> Result { match self { Self::V2 => Ok("javy_quickjs_provider_v2".to_string()), @@ -68,14 +68,14 @@ impl Provider { None } }) - .ok_or_else(|| anyhow!("Provider is missing import_namespace custom section"))? + .ok_or_else(|| anyhow!("Plugin is missing import_namespace custom section"))? .data(&Default::default()); // Argument is required but not actually used for anything. Ok(str::from_utf8(&import_namespace)?.to_string()) } } } - /// The JS configuration properties supported by this provider. + /// The JS configuration properties supported by this plugin. pub fn config_schema(&self) -> Result> { match self { Self::V2 => Ok(vec![]), diff --git a/crates/cli/tests/dylib_test.rs b/crates/cli/tests/dylib_test.rs index 05031a25..60232253 100644 --- a/crates/cli/tests/dylib_test.rs +++ b/crates/cli/tests/dylib_test.rs @@ -8,7 +8,7 @@ static ROOT: &str = env!("CARGO_MANIFEST_DIR"); #[test] fn test_dylib() -> Result<()> { let js_src = "console.log(42);"; - let mut runner = Runner::with_dylib(provider_module()?)?; + let mut runner = Runner::with_dylib(plugin_module()?)?; let (_, logs, _) = runner.exec_through_dylib(js_src, UseExportedFn::EvalBytecode)?; assert_eq!("42\n", str::from_utf8(&logs)?); @@ -19,7 +19,7 @@ fn test_dylib() -> Result<()> { #[test] fn test_dylib_with_invoke_with_no_fn_name() -> Result<()> { let js_src = "console.log(42);"; - let mut runner = Runner::with_dylib(provider_module()?)?; + let mut runner = Runner::with_dylib(plugin_module()?)?; let (_, logs, _) = runner.exec_through_dylib(js_src, UseExportedFn::Invoke(None))?; assert_eq!("42\n", str::from_utf8(&logs)?); @@ -31,7 +31,7 @@ fn test_dylib_with_invoke_with_no_fn_name() -> Result<()> { fn test_dylib_with_error() -> Result<()> { let js_src = "function foo() { throw new Error('foo error'); } foo();"; - let mut runner = Runner::with_dylib(provider_module()?)?; + let mut runner = Runner::with_dylib(plugin_module()?)?; let res = runner.exec_through_dylib(js_src, UseExportedFn::EvalBytecode); @@ -51,7 +51,7 @@ fn test_dylib_with_error() -> Result<()> { fn test_dylib_with_exported_func() -> Result<()> { let js_src = "export function foo() { console.log('In foo'); }; console.log('Toplevel');"; - let mut runner = Runner::with_dylib(provider_module()?)?; + let mut runner = Runner::with_dylib(plugin_module()?)?; let (_, logs, _) = runner.exec_through_dylib(js_src, UseExportedFn::Invoke(Some("foo")))?; assert_eq!("Toplevel\nIn foo\n", str::from_utf8(&logs)?); @@ -59,7 +59,7 @@ fn test_dylib_with_exported_func() -> Result<()> { Ok(()) } -fn provider_module() -> Result> { +fn plugin_module() -> Result> { let mut lib_path = PathBuf::from(ROOT); lib_path.pop(); lib_path.pop(); @@ -67,7 +67,7 @@ fn provider_module() -> Result> { Path::new("target") .join("wasm32-wasip1") .join("release") - .join("javy_quickjs_provider_wizened.wasm"), + .join("plugin_wizened.wasm"), ); std::fs::read(lib_path).map_err(Into::into) diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 628a5fc7..a4ad7028 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -6,7 +6,7 @@ edition.workspace = true license.workspace = true [lib] -name = "javy_quickjs_provider" +name = "plugin" crate-type = ["cdylib"] [dependencies] diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index f3cda8b3..ac4d2e14 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -4,6 +4,7 @@ use std::fmt::{self, Display, Formatter}; use std::io::{self, Cursor, Write}; use std::path::{Path, PathBuf}; use std::process::Command; +use std::str; use std::{cmp, fs}; use tempfile::TempDir; use wasi_common::pipe::{ReadPipe, WritePipe}; @@ -45,9 +46,9 @@ pub struct Builder { preload: Option<(String, PathBuf)>, /// Whether to use the `compile` or `build` command. command: JavyCommand, - /// The javy provider version. + /// The javy plugin version. /// Used for import validation purposes only. - provider_version: u8, + plugin_version: u8, } impl Default for Builder { @@ -66,7 +67,7 @@ impl Default for Builder { javy_json: None, simd_json_builtins: None, text_encoding: None, - provider_version: 3, + plugin_version: 3, } } } @@ -132,8 +133,8 @@ impl Builder { self } - pub fn provider_version(&mut self, vsn: u8) -> &mut Self { - self.provider_version = vsn; + pub fn plugin_version(&mut self, vsn: u8) -> &mut Self { + self.plugin_version = vsn; self } @@ -162,7 +163,7 @@ impl Builder { built: _, preload, command, - provider_version, + plugin_version, } = std::mem::take(self); self.built = true; @@ -177,10 +178,10 @@ impl Builder { wit, world, preload, - provider_version, + plugin_version, ) } else { - Runner::compile_static(bin_path, root, input, wit, world, provider_version) + Runner::compile_static(bin_path, root, input, wit, world, plugin_version) } } JavyCommand::Build => Runner::build( @@ -205,7 +206,7 @@ pub struct Runner { linker: Linker, initial_fuel: u64, preload: Option<(String, Vec)>, - provider_version: u8, + plugin_version: u8, } #[derive(Debug)] @@ -310,7 +311,7 @@ impl Runner { linker, initial_fuel: u64::MAX, preload, - provider_version: 3, + plugin_version: 3, }) } @@ -343,7 +344,7 @@ impl Runner { linker, initial_fuel: u64::MAX, preload: None, - provider_version: vsn, + plugin_version: vsn, }) } @@ -377,7 +378,7 @@ impl Runner { linker, initial_fuel: u64::MAX, preload: Some((preload.0, preload_module)), - provider_version: vsn, + plugin_version: vsn, }) } @@ -388,13 +389,13 @@ impl Runner { linker: Self::setup_linker(&engine)?, initial_fuel: u64::MAX, preload: None, - provider_version: 3, + plugin_version: 3, }) } pub fn assert_known_base_imports(&self) -> Result<()> { let module = Module::from_binary(self.linker.engine(), &self.wasm)?; - let instance_name = format!("javy_quickjs_provider_v{}", self.provider_version); + let instance_name = format!("javy_quickjs_provider_v{}", self.plugin_version); let result = module.imports().filter(|i| { if i.module() == instance_name && i.name() == "canonical_abi_realloc" { @@ -434,7 +435,7 @@ impl Runner { self.assert_known_base_imports()?; let module = Module::from_binary(self.linker.engine(), &self.wasm)?; - let instance_name = format!("javy_quickjs_provider_v{}", self.provider_version); + let instance_name = format!("javy_quickjs_provider_v{}", self.plugin_version); let result = module.imports().filter(|i| { if i.module() == instance_name && i.name() == "invoke" { let ty = i.ty(); diff --git a/crates/test-macros/src/lib.rs b/crates/test-macros/src/lib.rs index 426bad5c..1bc9b1c8 100644 --- a/crates/test-macros/src/lib.rs +++ b/crates/test-macros/src/lib.rs @@ -295,7 +295,7 @@ fn expand_cli_tests(test_config: &CliTestConfig, func: syn::ItemFn) -> Result Result wasm - subgraph wasm[javy_core.wasm / javy_quickjs_provider.wasm] + subgraph wasm[plugin.wasm] javy-core --> javy javy --> rquickjs end @@ -109,10 +109,10 @@ You should gate your feature with a cargo feature if your feature/change: ### `javy-core` -Gets compiled to `javy_core.wasm` and `javy_quickjs_provider.wasm` for use by -the CLI and in environments for running dynamically linked modules. This isn't -intended to be used as a code library by third parties. Contains logic for -driving the `javy` crate for Wasm modules generated by `javy-cli`. +Gets compiled to `plugin.wasm` for use by the CLI and in environments for +running dynamically linked modules. This isn't intended to be used as a code +library by third parties. Contains logic for driving the `javy` crate for Wasm +modules generated by `javy-cli`. #### When to add a `cargo` feature diff --git a/docs/docs-using-dynamic-linking.md b/docs/docs-using-dynamic-linking.md index cdcef821..ffa4c87e 100644 --- a/docs/docs-using-dynamic-linking.md +++ b/docs/docs-using-dynamic-linking.md @@ -11,7 +11,7 @@ meet these requirements. To successfully instantiate and run a dynamically linked Javy module, the execution environment must provide a `javy_quickjs_provider_v` namespace for -importing that links to the exports provided by the `javy_quickjs_provider.wasm` +importing that links to the exports provided by the `plugin.wasm` module. Dynamically linked modules **cannot** be instantiated in environments that do not provide this import. @@ -19,9 +19,9 @@ Dynamically linked Javy modules are tied to QuickJS since they use QuickJS's bytecode representation. -#### Obtaining the provider module +#### Obtaining the plugin module -The `javy_quickjs_provider.wasm` module is available as an asset on the Javy +The `plugin.wasm` module is available as an asset on the Javy release you are using. It can also be obtained by running `javy emit-provider -o @@ -34,7 +34,7 @@ Run: ``` $ echo 'console.log("hello world!");' > my_code.js $ javy build -C dynamic -o my_code.wasm my_code.js -$ javy emit-provider -o provider.wasm -$ wasmtime run --preload javy_quickjs_provider_v3=provider.wasm my_code.wasm +$ javy emit-provider -o plugin.wasm +$ wasmtime run --preload javy_quickjs_provider_v3=plugin.wasm my_code.wasm hello world! ``` diff --git a/docs/docs-using-nodejs.md b/docs/docs-using-nodejs.md index 63c66d2d..76dbb6ad 100644 --- a/docs/docs-using-nodejs.md +++ b/docs/docs-using-nodejs.md @@ -6,7 +6,7 @@ This example does NOT show how to run a Node.js application in Javy. This is use ## Summary -This example shows how to use a dynamically linked Javy compiled WASM module. We use std in/out/error to communicate with the embedded javascript see [this blog post](https://k33g.hashnode.dev/wasi-communication-between-nodejs-and-wasm-modules-another-way-with-stdin-and-stdout) for details. +This example shows how to use a dynamically linked Javy compiled Wasm module. We use std in/out/error to communicate with the embedded javascript see [this blog post](https://k33g.hashnode.dev/wasi-communication-between-nodejs-and-wasm-modules-another-way-with-stdin-and-stdout) for details. ### Steps @@ -15,9 +15,9 @@ This example shows how to use a dynamically linked Javy compiled WASM module. We ```shell javy build -C dynamic -o embedded.wasm embedded.js ``` -2. Next emit the Javy provider +2. Next emit the Javy plugin ```shell -javy emit-provider -o provider.wasm +javy emit-provider -o plugin.wasm ``` 3. Then we can run `host.mjs` ```shell @@ -99,11 +99,11 @@ import { tmpdir } from "node:os"; import { WASI } from "wasi"; try { - const [embeddedModule, providerModule] = await Promise.all([ + const [embeddedModule, pluginModule] = await Promise.all([ compileModule("./embedded.wasm"), - compileModule("./provider.wasm"), + compileModule("./plugin.wasm"), ]); - const result = await runJavy(providerModule, embeddedModule, { n: 100 }); + const result = await runJavy(pluginModule, embeddedModule, { n: 100 }); console.log("Success!", JSON.stringify(result, null, 2)); } catch (e) { console.log(e); @@ -114,17 +114,17 @@ async function compileModule(wasmPath) { return WebAssembly.compile(bytes); } -async function runJavy(providerModule, embeddedModule, input) { +async function runJavy(pluginModule, embeddedModule, input) { const uniqueId = crypto.randomUUID(); - // Use stdin/stdout/stderr to communicate with WASM process + // Use stdin/stdout/stderr to communicate with Wasm instance // See https://k33g.hashnode.dev/wasi-communication-between-nodejs-and-wasm-modules-another-way-with-stdin-and-stdout const workDir = tmpdir(); const stdinFilePath = join(workDir, `stdin.wasm.${uniqueId}.txt`); const stdoutFilePath = join(workDir, `stdout.wasm.${uniqueId}.txt`); const stderrFilePath = join(workDir, `stderr.wasm.${uniqueId}.txt`); - // 👋 send data to the WASM program + // 👋 send data to the Wasm instance await writeFile(stdinFilePath, JSON.stringify(input), { encoding: "utf8" }); const [stdinFile, stdoutFile, stderrFile] = await Promise.all([ @@ -144,16 +144,16 @@ async function runJavy(providerModule, embeddedModule, input) { returnOnExit: true, }); - const providerInstance = await WebAssembly.instantiate( - providerModule, + const pluginInstance = await WebAssembly.instantiate( + pluginModule, wasi.getImportObject(), ); const instance = await WebAssembly.instantiate(embeddedModule, { - javy_quickjs_provider_v3: providerInstance.exports, + javy_quickjs_provider_v3: pluginInstance.exports, }); - // Javy provider is a WASI reactor see https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md?plain=1 - wasi.initialize(providerInstance); + // Javy plugin is a WASI reactor see https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md?plain=1 + wasi.initialize(pluginInstance); instance.exports._start(); const [out, err] = await Promise.all([