Skip to content

Commit 2333d1b

Browse files
authored
Fully thread the source-compression value (#761)
* 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
1 parent 44b29e0 commit 2333d1b

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

crates/cli/src/codegen/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl CodeGenBuilder {
106106

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

110111
if let Some(v) = self.provider_version {
111112
dynamic_gen.import_namespace = String::from("javy_quickjs_provider_v");

crates/cli/src/codegen/dynamic.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(crate) struct DynamicGenerator {
4949
/// JavaScript function exports.
5050
function_exports: Exports,
5151
/// Whether to embed the compressed JS source in the generated module.
52-
source_compression: bool,
52+
pub source_compression: bool,
5353
/// WIT options for code generation.
5454
pub wit_opts: WitOptions,
5555
}
@@ -58,7 +58,7 @@ impl DynamicGenerator {
5858
/// Creates a new [`DynamicGenerator`].
5959
pub fn new() -> Self {
6060
Self {
61-
source_compression: Default::default(),
61+
source_compression: true,
6262
import_namespace: "".into(),
6363
function_exports: Default::default(),
6464
wit_opts: Default::default(),
@@ -304,3 +304,20 @@ fn print_wat(wasm_binary: &[u8]) -> Result<()> {
304304
fn print_wat(_wasm_binary: &[u8]) -> Result<()> {
305305
Ok(())
306306
}
307+
308+
#[cfg(test)]
309+
mod test {
310+
use super::DynamicGenerator;
311+
use super::WitOptions;
312+
use anyhow::Result;
313+
314+
#[test]
315+
fn default_values() -> Result<()> {
316+
let gen = DynamicGenerator::new();
317+
assert!(gen.source_compression);
318+
assert_eq!(gen.import_namespace, "");
319+
assert_eq!(gen.wit_opts, WitOptions::default());
320+
321+
Ok(())
322+
}
323+
}

crates/cli/src/codegen/static.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl StaticGenerator {
3636
let engine = include_bytes!(concat!(env!("OUT_DIR"), "/engine.wasm"));
3737
Self {
3838
engine,
39-
source_compression: Default::default(),
39+
source_compression: true,
4040
function_exports: Default::default(),
4141
wit_opts: Default::default(),
4242
js_runtime_config,
@@ -201,3 +201,20 @@ fn optimize_wasm(wasm: &[u8]) -> Result<Vec<u8>> {
201201

202202
Ok(fs::read(&tempfile_path)?)
203203
}
204+
205+
#[cfg(test)]
206+
mod test {
207+
use super::StaticGenerator;
208+
use super::WitOptions;
209+
use anyhow::Result;
210+
use javy_config::Config;
211+
212+
#[test]
213+
fn default_values() -> Result<()> {
214+
let gen = StaticGenerator::new(Config::default());
215+
assert!(gen.source_compression);
216+
assert_eq!(gen.wit_opts, WitOptions::default());
217+
218+
Ok(())
219+
}
220+
}

0 commit comments

Comments
 (0)