Skip to content

Commit 3c053e8

Browse files
committed
Fix Rust code formatting
1 parent b3b4928 commit 3c053e8

File tree

6 files changed

+63
-77
lines changed

6 files changed

+63
-77
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use clap::{Parser, Subcommand};
33
use std::fs;
44
use std::path::PathBuf;
55

6-
use spidermonkey_embedding_splicer::{splice, stub_wasi};
76
use spidermonkey_embedding_splicer::wit::Features;
7+
use spidermonkey_embedding_splicer::{splice, stub_wasi};
88

99
#[derive(Parser, Debug)]
1010
#[command(author, version, about, long_about = None)]
@@ -129,14 +129,8 @@ fn main() -> Result<()> {
129129

130130
let wit_path_str = wit_path.as_ref().map(|p| p.to_string_lossy().to_string());
131131

132-
let result = splice::splice_bindings(
133-
engine,
134-
world_name,
135-
wit_path_str,
136-
None,
137-
debug,
138-
)
139-
.map_err(|e| anyhow::anyhow!(e))?;
132+
let result = splice::splice_bindings(engine, world_name, wit_path_str, None, debug)
133+
.map_err(|e| anyhow::anyhow!(e))?;
140134
fs::write(&out_dir.join("component.wasm"), result.wasm).with_context(|| {
141135
format!(
142136
"Failed to write output file: {}",

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ pub struct Componentization {
129129
pub resource_imports: Vec<(String, String, u32)>,
130130
}
131131

132-
pub fn componentize_bindgen(
133-
resolve: &Resolve,
134-
wid: WorldId,
135-
) -> Result<Componentization> {
132+
pub fn componentize_bindgen(resolve: &Resolve, wid: WorldId) -> Result<Componentization> {
136133
let mut bindgen = JsBindgen {
137134
src: Source::default(),
138135
esm_bindgen: EsmBindgen::default(),
@@ -222,9 +219,7 @@ pub fn componentize_bindgen(
222219
let joined_bindings = specifier_list.join(",\n\t");
223220
import_wrappers.push((
224221
specifier.to_string(),
225-
format!(
226-
"defineBuiltinModule('{specifier}', {{\n\t{joined_bindings}\n}});"
227-
),
222+
format!("defineBuiltinModule('{specifier}', {{\n\t{joined_bindings}\n}});"),
228223
));
229224
}
230225

@@ -374,13 +369,13 @@ pub fn componentize_bindgen(
374369
output.push_str(&js_intrinsics);
375370
output.push_str(&bindgen.src);
376371

377-
import_wrappers.iter().for_each(|(_, src)| output.push_str(&format!("\n\n{src}")));
372+
import_wrappers
373+
.iter()
374+
.for_each(|(_, src)| output.push_str(&format!("\n\n{src}")));
378375

379-
bindgen.esm_bindgen.render_export_imports(
380-
&mut output,
381-
"$source_mod",
382-
&mut bindgen.local_names,
383-
);
376+
bindgen
377+
.esm_bindgen
378+
.render_export_imports(&mut output, "$source_mod", &mut bindgen.local_names);
384379

385380
Ok(Componentization {
386381
js_bindings: output.to_string(),
@@ -1206,10 +1201,12 @@ impl EsmBindgen {
12061201
}
12071202

12081203
let mut bind_exports = Source::default();
1209-
bind_exports.push_str("let __sourceName;
1204+
bind_exports.push_str(
1205+
"let __sourceName;
12101206
function bindExports(sourceName) {
12111207
__sourceName = sourceName;
1212-
let __iface;");
1208+
let __iface;",
1209+
);
12131210
for (export_name, binding) in &self.exports {
12141211
match binding {
12151212
Binding::Interface(bindings) => {
@@ -1275,19 +1272,25 @@ impl EsmBindgen {
12751272
}
12761273
}
12771274
Binding::Resource(local_name) => {
1278-
uwriteln!(output, "
1275+
uwriteln!(
1276+
output,
1277+
"
12791278
let {local_name};
1280-
");
1279+
"
1280+
);
12811281
uwriteln!(bind_exports, "
12821282
{local_name} = {imports_object}.{export_name};
12831283
if (typeof {local_name} !== 'function')
12841284
throw new BindingsError('{export_name}', 'function', '', `export function {export_name} () {{}};\n`);
12851285
");
12861286
}
12871287
Binding::Local(local_name) => {
1288-
uwriteln!(output, "
1288+
uwriteln!(
1289+
output,
1290+
"
12891291
let {local_name};
1290-
");
1292+
"
1293+
);
12911294
uwriteln!(bind_exports, "
12921295
{local_name} = {imports_object}.{export_name};
12931296
if (typeof {local_name} !== 'function')

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::path::Path;
21
use anyhow::{bail, Context, Result};
2+
use std::path::Path;
33

44
pub mod bindgen;
55
pub mod splice;
66
pub mod stub_wasi;
77

8-
use wit_parser::{PackageId, Resolve};
98
use crate::wit::{CoreFn, CoreTy};
9+
use wit_parser::{PackageId, Resolve};
1010

1111
pub mod wit {
1212
wit_bindgen::generate!({
@@ -85,4 +85,3 @@ fn parse_wit(path: &Path) -> Result<(Resolve, PackageId)> {
8585
};
8686
Ok((resolve, id))
8787
}
88-

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

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
use crate::bindgen::BindingItem;
2+
use crate::wit::{CoreFn, CoreTy, SpliceResult};
3+
use crate::{bindgen, map_core_fn, parse_wit, splice};
14
use anyhow::Result;
2-
use wasm_encoder::{Encode, Section};
3-
use std::path::PathBuf;
45
use orca_wasm::ir::function::{FunctionBuilder, FunctionModifier};
56
use orca_wasm::ir::id::{ExportsID, FunctionID, LocalID};
67
use orca_wasm::ir::module::Module;
78
use orca_wasm::ir::types::{BlockType, ElementItems, InstrumentationMode};
89
use orca_wasm::module_builder::AddLocal;
910
use orca_wasm::opcode::{Inject, InjectAt};
1011
use orca_wasm::{DataType, Opcode};
12+
use std::path::PathBuf;
13+
use wasm_encoder::{Encode, Section};
1114
use wasmparser::ExternalKind;
1215
use wasmparser::MemArg;
1316
use wasmparser::Operator;
1417
use wit_component::metadata::{decode, Bindgen};
1518
use wit_component::StringEncoding;
1619
use wit_parser::Resolve;
17-
use crate::{bindgen, map_core_fn, parse_wit, splice};
18-
use crate::bindgen::BindingItem;
19-
use crate::wit::{CoreFn, CoreTy, SpliceResult};
2020

2121
// Returns
2222
// pub struct SpliceResult {
@@ -53,14 +53,14 @@ pub fn splice_bindings(
5353

5454
// merge the engine world with the target world, retaining the engine producers
5555
let (engine_world, producers) = if let Ok((
56-
_,
57-
Bindgen {
58-
resolve: mut engine_resolve,
59-
world: engine_world,
60-
metadata: _,
61-
producers,
62-
},
63-
)) = decode(&engine)
56+
_,
57+
Bindgen {
58+
resolve: mut engine_resolve,
59+
world: engine_world,
60+
metadata: _,
61+
producers,
62+
},
63+
)) = decode(&engine)
6464
{
6565
// we disable the engine run and incoming handler as we recreate these exports
6666
// when needed, so remove these from the world before initiating the merge
@@ -104,23 +104,16 @@ pub fn splice_bindings(
104104
unreachable!();
105105
};
106106

107-
let componentized = bindgen::componentize_bindgen(
108-
&resolve,
109-
world,
110-
)
111-
.map_err(|err| err.to_string())?;
107+
let componentized =
108+
bindgen::componentize_bindgen(&resolve, world).map_err(|err| err.to_string())?;
112109

113110
resolve
114111
.merge_worlds(engine_world, world)
115112
.expect("unable to merge with engine world");
116113

117-
let encoded = wit_component::metadata::encode(
118-
&resolve,
119-
world,
120-
StringEncoding::UTF8,
121-
producers.as_ref(),
122-
)
123-
.map_err(|e| e.to_string())?;
114+
let encoded =
115+
wit_component::metadata::encode(&resolve, world, StringEncoding::UTF8, producers.as_ref())
116+
.map_err(|e| e.to_string())?;
124117

125118
let section = wasm_encoder::CustomSection {
126119
name: "component-type".into(),
@@ -254,9 +247,6 @@ pub fn splice_bindings(
254247
));
255248
}
256249

257-
// println!("{:?}", &componentized.imports);
258-
// println!("{:?}", &componentized.resource_imports);
259-
// println!("{:?}", &exports);
260250
let mut wasm =
261251
splice::splice(engine, imports, exports, debug).map_err(|e| format!("{:?}", e))?;
262252

@@ -271,27 +261,27 @@ pub fn splice_bindings(
271261
.iter()
272262
.map(
273263
|(
274-
_,
275-
BindingItem {
276-
binding_name, func, ..
277-
},
278-
)| { (binding_name.to_string(), map_core_fn(&func)) },
264+
_,
265+
BindingItem {
266+
binding_name, func, ..
267+
},
268+
)| { (binding_name.to_string(), map_core_fn(&func)) },
279269
)
280270
.collect(),
281271
imports: componentized
282272
.imports
283273
.iter()
284274
.map(
285275
|(
286-
specifier,
287-
BindingItem {
288-
name,
289-
iface,
290-
func,
291-
resource,
292-
..
293-
},
294-
)| {
276+
specifier,
277+
BindingItem {
278+
name,
279+
iface,
280+
func,
281+
resource,
282+
..
283+
},
284+
)| {
295285
(
296286
if *iface {
297287
specifier.to_string()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::parse_wit;
2+
use crate::wit::Features;
13
use anyhow::{bail, Result};
24
use orca_wasm::ir::function::FunctionBuilder;
35
use orca_wasm::ir::id::{FunctionID, LocalID};
@@ -12,8 +14,6 @@ use std::{
1214
};
1315
use wasmparser::{MemArg, TypeRef};
1416
use wit_parser::Resolve;
15-
use crate::parse_wit;
16-
use crate::wit::Features;
1717

1818
const WASI_VERSIONS: [&str; 4] = ["0.2.0", "0.2.1", "0.2.2", "0.2.3"];
1919

crates/splicer-component/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use spidermonkey_embedding_splicer::{splice, wit};
2-
use spidermonkey_embedding_splicer::wit::{export, Features, Guest, SpliceResult};
31
use spidermonkey_embedding_splicer::stub_wasi::stub_wasi;
2+
use spidermonkey_embedding_splicer::wit::{export, Features, Guest, SpliceResult};
3+
use spidermonkey_embedding_splicer::{splice, wit};
44

55
struct SpidermonkeyEmbeddingSplicerComponent;
66

0 commit comments

Comments
 (0)