Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set JS runtime config from CLI for static modules #736

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions crates/cli/src/codegen/static.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions crates/core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +19,15 @@ static mut BYTECODE: OnceCell<Vec<u8>> = 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();
Expand Down
Loading