diff --git a/Cargo.lock b/Cargo.lock index c31d8cdb..cd3366ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1468,6 +1468,7 @@ dependencies = [ "clap", "convert_case", "criterion", + "javy-config", "javy-runner", "lazy_static", "num-format", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 78f156ff..ca2a0dda 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -33,6 +33,7 @@ convert_case = "0.6.0" wasm-opt = "0.116.1" tempfile = { workspace = true } clap = { version = "4.5.15", features = ["derive"] } +javy-config = { workspace = true } [dev-dependencies] serde_json = "1.0" diff --git a/crates/cli/src/codegen/static.rs b/crates/cli/src/codegen/static.rs index bc7deabc..24560c31 100644 --- a/crates/cli/src/codegen/static.rs +++ b/crates/cli/src/codegen/static.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, fs, rc::Rc, sync::OnceLock}; use anyhow::Result; +use javy_config::Config; use walrus::{DataKind, ExportItem, FunctionBuilder, FunctionId, MemoryId, ValType}; use wasi_common::{pipe::ReadPipe, sync::WasiCtxBuilder, WasiCtx}; use wasm_opt::{OptimizationOptions, ShrinkLevel}; @@ -69,6 +70,10 @@ impl CodeGen for StaticGenerator { WASI.get_mut() .unwrap() .set_stdin(Box::new(ReadPipe::from(js.as_bytes()))); + + WASI.get_mut() + .unwrap() + .push_env("JS_RUNTIME_CONFIG", &Config::all().bits().to_string())?; }; let wasm = Wizer::new() diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index abd53eee..dfebcbc7 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -2,9 +2,9 @@ use anyhow::anyhow; use javy::Runtime; use once_cell::sync::OnceCell; use std::io::{self, Read}; -use std::slice; use std::str; use std::string::String; +use std::{env, slice}; use javy_config::Config; mod execution; @@ -19,7 +19,15 @@ static mut BYTECODE: OnceCell> = OnceCell::new(); pub extern "C" fn init() { let _wasm_ctx = WasmCtx::new(); - let runtime = runtime::new(Config::all()).unwrap(); + let js_runtime_config = Config::from_bits( + env::var("JS_RUNTIME_CONFIG") + .expect("JS_RUNTIME_CONFIG should be set") + .parse() + .expect("JS_RUNTIME_CONFIG should be a u32"), + ) + .expect("JS_RUNTIME_CONFIG should only contain valid flags"); + + let runtime = runtime::new(js_runtime_config).unwrap(); let mut contents = String::new(); io::stdin().read_to_string(&mut contents).unwrap();