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

Change JS config to use a schema and JSON #794

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ jobs:
- name: Test
env:
CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime --dir=.
run: cargo hack test --target=wasm32-wasip1 --workspace --exclude=javy-cli --exclude=javy-config --exclude=javy-runner --each-feature -- --nocapture

- name: Test Config
run: cargo test --package=javy-config
run: cargo hack test --target=wasm32-wasip1 --workspace --exclude=javy-cli --exclude=javy-runner --each-feature -- --nocapture

- name: Test Runner
run: cargo test --package=javy-runner
Expand Down
11 changes: 1 addition & 10 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ members = [
"crates/core",
"crates/cli",
"crates/test-macros",
"crates/config",
"crates/runner",
"fuzz",
]
Expand All @@ -23,11 +22,11 @@ wasmtime-wasi = "19"
wasi-common = "19"
anyhow = "1.0"
once_cell = "1.20"
bitflags = "2.6.0"
javy-config = { path = "crates/config" }
javy = { path = "crates/javy", version = "3.0.2-alpha.1" }
javy = { path = "crates/javy", version = "3.1.0-alpha.1" }
tempfile = "3.13.0"
uuid = { version = "1.10", features = ["v4"] }
serde = { version = "1.0", default-features = false }
serde_json = "1.0"

[profile.release]
lto = true
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ docs:
cargo doc --package=javy-core --open --target=wasm32-wasip1

test-javy:
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime --dir=." cargo test --package=javy --target=wasm32-wasip1 --features json,messagepack -- --nocapture
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime --dir=." cargo hack test --package=javy --target=wasm32-wasip1 --each-feature -- --nocapture

test-core:
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime" cargo test --package=javy-core --target=wasm32-wasip1 -- --nocapture
Expand All @@ -44,10 +44,7 @@ test-wpt:
npm install --prefix wpt
npm test --prefix wpt

test-config:
CARGO_PROFILE_RELEASE_LTO=off cargo test --package=javy-config -- --nocapture

tests: test-javy test-core test-runner test-cli test-wpt test-config
tests: test-javy test-core test-runner test-cli test-wpt

fmt: fmt-javy fmt-core fmt-cli

Expand Down
5 changes: 2 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ convert_case = "0.6.0"
wasm-opt = "0.116.1"
tempfile = { workspace = true }
clap = { version = "4.5.19", features = ["derive"] }
javy-config = { workspace = true }
serde = { workspace = true, default-features = false }
serde_json = { workspace = true }

[dev-dependencies]
serde_json = "1.0"
lazy_static = "1.5"
serde = { version = "1.0", default-features = false, features = ["derive"] }
criterion = "0.5"
num-format = "0.4.4"
wasmparser = "0.218.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/codegen/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
codegen::{CodeGenType, Generator},
js_config::JsConfig,
providers::Provider,
};
use anyhow::{bail, Result};
use javy_config::Config;
use std::path::PathBuf;

/// Options for using WIT in the code generation process.
Expand Down Expand Up @@ -83,9 +83,9 @@ impl CodeGenBuilder {
}

/// Build a [`CodeGenerator`].
pub fn build(self, ty: CodeGenType, js_runtime_config: Config) -> Result<Generator> {
pub fn build(self, ty: CodeGenType, js_runtime_config: JsConfig) -> Result<Generator> {
if let CodeGenType::Dynamic = ty {
if js_runtime_config != Config::default() {
if js_runtime_config.has_configs() {
bail!("Cannot set JS runtime options when building a dynamic module")
}
}
Expand Down
21 changes: 9 additions & 12 deletions crates/cli/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ use std::{fs, rc::Rc, sync::OnceLock};

pub(crate) use builder::*;

use javy_config::Config;

mod transform;

mod exports;
Expand All @@ -52,7 +50,7 @@ use wasi_common::{pipe::ReadPipe, sync::WasiCtxBuilder, WasiCtx};
use wasm_opt::{OptimizationOptions, ShrinkLevel};
use wizer::{Linker, Wizer};

use crate::{providers::Provider, JS};
use crate::{js_config::JsConfig, providers::Provider, JS};
use anyhow::Result;

static mut WASI: OnceLock<WasiCtx> = OnceLock::new();
Expand Down Expand Up @@ -112,7 +110,7 @@ pub(crate) struct Generator {
/// Codegen type to use.
pub ty: CodeGenType,
/// JS runtime config.
pub js_runtime_config: Config,
pub js_runtime_config: JsConfig,
/// Provider to use.
pub provider: Provider,
/// JavaScript function exports.
Expand All @@ -125,7 +123,7 @@ pub(crate) struct Generator {

impl Generator {
/// Creates a new [`Generator`].
pub fn new(ty: CodeGenType, js_runtime_config: Config, provider: Provider) -> Self {
pub fn new(ty: CodeGenType, js_runtime_config: JsConfig, provider: Provider) -> Self {
Self {
ty,
js_runtime_config,
Expand All @@ -141,15 +139,14 @@ impl Generator {
let config = transform::module_config();
let module = match &self.ty {
CodeGenType::Static => {
// Copy config bits into stdin for `initialize_runtime` function.
// Copy config JSON into stdin for `initialize_runtime` function.
let runtime_config = self.js_runtime_config.to_json()?;
unsafe {
WASI.get_or_init(|| {
WasiCtxBuilder::new()
.inherit_stderr()
.inherit_stdout()
.stdin(Box::new(ReadPipe::from(
self.js_runtime_config.bits().to_le_bytes().as_slice(),
)))
.stdin(Box::new(ReadPipe::from(runtime_config)))
.build()
});
};
Expand Down Expand Up @@ -463,21 +460,21 @@ fn print_wat(_wasm_binary: &[u8]) -> Result<()> {

#[cfg(test)]
mod test {
use crate::js_config::JsConfig;
use crate::providers::Provider;

use super::Generator;
use super::WitOptions;
use anyhow::Result;
use javy_config::Config;

#[test]
fn default_values() -> Result<()> {
let gen = Generator::new(
crate::codegen::CodeGenType::Dynamic,
Config::default(),
JsConfig::default(),
Provider::Default,
);
assert_eq!(gen.js_runtime_config, Config::default());
assert!(!gen.js_runtime_config.has_configs());
assert!(gen.source_compression);
assert!(matches!(gen.provider, Provider::Default));
assert_eq!(gen.wit_opts, WitOptions::default());
Expand Down
Loading
Loading