Skip to content

Commit

Permalink
Fully thread the source-compression value (#761)
Browse files Browse the repository at this point in the history
* Fully thread the `source-compression` value

This commit fixes the handling of the `source-compression` option when
`C dynamic` is set. Even though the codegen option gropup defines the
options as `true` by default, it was not threaded correctly.

Additionally this commit set `source-compression` as `true` in the
default implementation of the builders to ensure that the CLI options
intent is accurately reflected.

* Add sanity tests
  • Loading branch information
saulecabrera authored Sep 18, 2024
1 parent 44b29e0 commit 2333d1b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/cli/src/codegen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl CodeGenBuilder {

fn build_dynamic(self) -> Result<Box<dyn CodeGen>> {
let mut dynamic_gen = Box::new(DynamicGenerator::new());
dynamic_gen.source_compression = self.source_compression;

if let Some(v) = self.provider_version {
dynamic_gen.import_namespace = String::from("javy_quickjs_provider_v");
Expand Down
21 changes: 19 additions & 2 deletions crates/cli/src/codegen/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) struct DynamicGenerator {
/// JavaScript function exports.
function_exports: Exports,
/// Whether to embed the compressed JS source in the generated module.
source_compression: bool,
pub source_compression: bool,
/// WIT options for code generation.
pub wit_opts: WitOptions,
}
Expand All @@ -58,7 +58,7 @@ impl DynamicGenerator {
/// Creates a new [`DynamicGenerator`].
pub fn new() -> Self {
Self {
source_compression: Default::default(),
source_compression: true,
import_namespace: "".into(),
function_exports: Default::default(),
wit_opts: Default::default(),
Expand Down Expand Up @@ -304,3 +304,20 @@ fn print_wat(wasm_binary: &[u8]) -> Result<()> {
fn print_wat(_wasm_binary: &[u8]) -> Result<()> {
Ok(())
}

#[cfg(test)]
mod test {
use super::DynamicGenerator;
use super::WitOptions;
use anyhow::Result;

#[test]
fn default_values() -> Result<()> {
let gen = DynamicGenerator::new();
assert!(gen.source_compression);
assert_eq!(gen.import_namespace, "");
assert_eq!(gen.wit_opts, WitOptions::default());

Ok(())
}
}
19 changes: 18 additions & 1 deletion crates/cli/src/codegen/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl StaticGenerator {
let engine = include_bytes!(concat!(env!("OUT_DIR"), "/engine.wasm"));
Self {
engine,
source_compression: Default::default(),
source_compression: true,
function_exports: Default::default(),
wit_opts: Default::default(),
js_runtime_config,
Expand Down Expand Up @@ -201,3 +201,20 @@ fn optimize_wasm(wasm: &[u8]) -> Result<Vec<u8>> {

Ok(fs::read(&tempfile_path)?)
}

#[cfg(test)]
mod test {
use super::StaticGenerator;
use super::WitOptions;
use anyhow::Result;
use javy_config::Config;

#[test]
fn default_values() -> Result<()> {
let gen = StaticGenerator::new(Config::default());
assert!(gen.source_compression);
assert_eq!(gen.wit_opts, WitOptions::default());

Ok(())
}
}

0 comments on commit 2333d1b

Please sign in to comment.