Skip to content

Commit c626f38

Browse files
committed
Added new files and cleaned up
1 parent 598042b commit c626f38

File tree

5 files changed

+685
-189
lines changed

5 files changed

+685
-189
lines changed

crates/spidermonkey-embedding-splicer/src/splice.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use std::path::PathBuf;
22
use std::time::Instant;
33

44
use anyhow::Result;
5+
use wasm_encoder::{Encode, Section};
6+
use wasmparser::ExternalKind;
7+
use wasmparser::MemArg;
8+
use wasmparser::Operator;
59
use wirm::ir::function::{FunctionBuilder, FunctionModifier};
610
use wirm::ir::id::{ExportsID, FunctionID, LocalID};
711
use wirm::ir::module::Module;
812
use wirm::ir::types::{BlockType, ElementItems, InstrumentationMode};
913
use wirm::module_builder::AddLocal;
1014
use wirm::opcode::{Inject, InjectAt};
1115
use wirm::{DataType, Opcode};
12-
use wasm_encoder::{Encode, Section};
13-
use wasmparser::ExternalKind;
14-
use wasmparser::MemArg;
15-
use wasmparser::Operator;
1616
use wit_component::metadata::{decode, Bindgen};
1717
use wit_component::StringEncoding;
1818
use wit_parser::Resolve;
@@ -312,10 +312,7 @@ pub fn splice_bindings(
312312
wasm.push(section.id());
313313
section.encode(&mut wasm);
314314

315-
eprintln!(
316-
"trace(splice:total): {} ms",
317-
t_total.elapsed().as_millis()
318-
);
315+
eprintln!("trace(splice:total): {} ms", t_total.elapsed().as_millis());
319316
Ok(SpliceResult {
320317
wasm,
321318
exports: componentized
@@ -443,7 +440,9 @@ pub fn splice(
443440
exports_cnt = s.count();
444441
section_sizes.push(("export".into(), range.end - range.start));
445442
}
446-
Ok(StartSection { range, .. }) => section_sizes.push(("start".into(), range.end - range.start)),
443+
Ok(StartSection { range, .. }) => {
444+
section_sizes.push(("start".into(), range.end - range.start))
445+
}
447446
Ok(ElementSection(s)) => {
448447
let range = s.range();
449448
section_sizes.push(("element".into(), range.end - range.start));
@@ -461,8 +460,8 @@ pub fn splice(
461460
custom_sections += 1;
462461
section_sizes.push((format!("custom:{name}"), size));
463462
}
464-
Ok(Version { .. }) | Ok(End(_)) => {},
465-
Ok(_) => {},
463+
Ok(Version { .. }) | Ok(End(_)) => {}
464+
Ok(_) => {}
466465
Err(_) => {}
467466
}
468467
}
@@ -479,7 +478,12 @@ pub fn splice(
479478
// Top 5 largest sections
480479
section_sizes.sort_by(|a, b| b.1.cmp(&a.1));
481480
for (i, (name, sz)) in section_sizes.iter().take(5).enumerate() {
482-
eprintln!("trace(wasm-splice:scan-top{}): {} bytes [{}]", i + 1, sz, name);
481+
eprintln!(
482+
"trace(wasm-splice:scan-top{}): {} bytes [{}]",
483+
i + 1,
484+
sz,
485+
name
486+
);
483487
}
484488
}
485489

@@ -992,23 +996,17 @@ fn synthesize_import_functions(
992996
.instructions
993997
.add_instr(table_instr_idx, Operator::I32Add);
994998
}
995-
builder
996-
.body
997-
.instructions
998-
.add_instr(
999-
table_instr_idx,
1000-
Operator::LocalGet {
1001-
local_index: *arg_idx,
1002-
},
1003-
);
999+
builder.body.instructions.add_instr(
1000+
table_instr_idx,
1001+
Operator::LocalGet {
1002+
local_index: *arg_idx,
1003+
},
1004+
);
10041005
builder
10051006
.body
10061007
.instructions
10071008
.add_instr(table_instr_idx, Operator::I32Add);
1008-
builder
1009-
.body
1010-
.instructions
1011-
.finish_instr(table_instr_idx);
1009+
builder.body.instructions.finish_instr(table_instr_idx);
10121010
eprintln!(
10131011
"trace(wasm-splice:imports:fixup-get-import): {} ms",
10141012
t_stage.elapsed().as_millis()

src/cli.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,60 @@ import { writeFile } from 'node:fs/promises';
66
import { resolve } from 'node:path';
77

88
export async function componentizeCmd(jsSource, opts) {
9-
const { component } = await componentize({
10-
sourcePath: jsSource,
11-
witPath: resolve(opts.wit),
12-
worldName: opts.worldName,
13-
runtimeArgs: opts.runtimeArgs,
14-
disableFeatures: opts.disable,
15-
preview2Adapter: opts.preview2Adapter,
16-
debugBindings: opts.debugBindings,
17-
debugBuild: opts.useDebugBuild,
18-
enableWizerLogging: opts.enableWizerLogging,
19-
});
20-
await writeFile(opts.out, component);
9+
const { component } = await componentize({
10+
sourcePath: jsSource,
11+
witPath: resolve(opts.wit),
12+
worldName: opts.worldName,
13+
runtimeArgs: opts.runtimeArgs,
14+
disableFeatures: opts.disable,
15+
preview2Adapter: opts.preview2Adapter,
16+
debugBindings: opts.debugBindings,
17+
debugBuild: opts.useDebugBuild,
18+
enableWizerLogging: opts.enableWizerLogging,
19+
splicerBin: opts.splicerBin,
20+
});
21+
await writeFile(opts.out, component);
2122
}
2223

2324
program
24-
.version('0.19.1')
25-
.description('Create a component from a JavaScript module')
26-
.usage('<js-source> --wit wit-world.wit -o <component-path>')
27-
.argument('<js-source>', 'JS source file to build')
28-
.requiredOption('-w, --wit <path>', 'WIT path to build with')
29-
.option('-n, --world-name <name>', 'WIT world to build')
30-
.option('--runtime-args <string>', 'arguments to pass to the runtime')
31-
.addOption(
32-
new Option('-d, --disable <feature...>', 'disable WASI features').choices(
33-
DEFAULT_FEATURES,
34-
),
35-
)
36-
.option(
37-
'--preview2-adapter <adapter>',
38-
'provide a custom preview2 adapter path',
39-
)
40-
.option('--use-debug-build', 'use a debug build of StarlingMonkey')
41-
.option('--debug-bindings', 'enable debug logging for bindings generation')
42-
.option(
43-
'--enable-wizer-logging',
44-
'enable debug logging for calls in the generated component',
45-
)
46-
.requiredOption('-o, --out <out>', 'output component file')
47-
.action(asyncAction(componentizeCmd));
25+
.version('0.19.1')
26+
.description('Create a component from a JavaScript module')
27+
.usage('<js-source> --wit wit-world.wit -o <component-path>')
28+
.argument('<js-source>', 'JS source file to build')
29+
.requiredOption('-w, --wit <path>', 'WIT path to build with')
30+
.option('-n, --world-name <name>', 'WIT world to build')
31+
.option('--runtime-args <string>', 'arguments to pass to the runtime')
32+
.addOption(
33+
new Option('-d, --disable <feature...>', 'disable WASI features').choices(
34+
DEFAULT_FEATURES,
35+
),
36+
)
37+
.option(
38+
'--preview2-adapter <adapter>',
39+
'provide a custom preview2 adapter path',
40+
)
41+
.option('--use-debug-build', 'use a debug build of StarlingMonkey')
42+
.option('--debug-bindings', 'enable debug logging for bindings generation')
43+
.option(
44+
'--enable-wizer-logging',
45+
'enable debug logging for calls in the generated component',
46+
)
47+
.option(
48+
'--splicer-bin <binary_path>',
49+
'use native CLI splicer for better performance',
50+
)
51+
.requiredOption('-o, --out <out>', 'output component file')
52+
.action(asyncAction(componentizeCmd));
4853

4954
program.showHelpAfterError();
5055

5156
program.parse();
5257

5358
function asyncAction(cmd) {
54-
return function () {
55-
const args = [...arguments];
56-
(async () => {
57-
await cmd.apply(null, args);
58-
})();
59-
};
59+
return function () {
60+
const args = [...arguments];
61+
(async () => {
62+
await cmd.apply(null, args);
63+
})();
64+
};
6065
}

0 commit comments

Comments
 (0)