Skip to content

Commit 26eccca

Browse files
committed
Updated orca_wasm into wirm latest version
1 parent 811dcf8 commit 26eccca

File tree

6 files changed

+255
-63
lines changed

6 files changed

+255
-63
lines changed

Cargo.lock

Lines changed: 90 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ too_many_arguments = 'allow'
1414
anyhow = { version = "1.0.95", default-features = false }
1515
heck = { version = "0.5", default-features = false }
1616
js-component-bindgen = { version = "1.11.0" }
17-
orca-wasm = { version = "0.9.2", default-features = false }
17+
wirm = { version = "2.1.0", features = ["parallel"] }
1818
rand = { version = "0.8", default-features = false }
19+
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
1920
wasm-encoder = { version = "0.227.1", features = [ "component-model", "std" ] }
20-
wasmparser = { version = "0.227.1", features = ["features",
21+
wasmparser = { version = "0.239.0", features = ["features",
2122
"component-model",
2223
"hash-collections",
2324
"serde",

crates/spidermonkey-embedding-splicer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ anyhow = { workspace = true }
1616
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
1717
heck = { workspace = true }
1818
js-component-bindgen = { workspace = true, features = [ "transpile-bindgen" ] }
19-
orca-wasm = { workspace = true }
19+
wirm = { workspace = true }
2020
rand = { workspace = true }
21+
serde_json = { workspace = true }
2122
wasm-encoder = { workspace = true }
2223
wasmparser = { workspace = true }
2324
wit-bindgen = { workspace = true }

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

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::str::FromStr;
55
use anyhow::{Context, Result};
66
use clap::{Parser, Subcommand};
77

8-
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
8+
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::{
9+
CoreFn, CoreTy, Feature,
10+
};
911
use spidermonkey_embedding_splicer::{splice, stub_wasi};
1012

1113
#[derive(Parser, Debug)]
@@ -139,8 +141,112 @@ fn main() -> Result<()> {
139141
out_dir.join("initializer.js").display()
140142
)
141143
})?;
144+
145+
// Write exports and imports as JSON (manual serialization)
146+
let exports_json = serialize_exports(&result.exports);
147+
fs::write(out_dir.join("exports.json"), exports_json).with_context(|| {
148+
format!(
149+
"Failed to write exports file: {}",
150+
out_dir.join("exports.json").display()
151+
)
152+
})?;
153+
154+
let imports_json = serialize_imports(&result.imports);
155+
fs::write(out_dir.join("imports.json"), imports_json).with_context(|| {
156+
format!(
157+
"Failed to write imports file: {}",
158+
out_dir.join("imports.json").display()
159+
)
160+
})?;
161+
162+
println!(
163+
"Successfully generated bindings and saved to {}",
164+
out_dir.display()
165+
);
142166
}
143167
}
144168

145169
Ok(())
146170
}
171+
172+
/// Manually serialize exports to JSON
173+
fn serialize_exports(exports: &[(String, CoreFn)]) -> String {
174+
let mut result = String::from("[\n");
175+
for (i, (name, core_fn)) in exports.iter().enumerate() {
176+
if i > 0 {
177+
result.push_str(",\n");
178+
}
179+
result.push_str(" [\"");
180+
result.push_str(&name.replace('\\', "\\\\").replace('"', "\\\""));
181+
result.push_str("\", ");
182+
result.push_str(&serialize_core_fn(core_fn));
183+
result.push(']');
184+
}
185+
result.push_str("\n]");
186+
result
187+
}
188+
189+
/// Manually serialize imports to JSON
190+
fn serialize_imports(imports: &[(String, String, u32)]) -> String {
191+
let mut result = String::from("[\n");
192+
for (i, (specifier, name, arg_count)) in imports.iter().enumerate() {
193+
if i > 0 {
194+
result.push_str(",\n");
195+
}
196+
result.push_str(" [\"");
197+
result.push_str(&specifier.replace('\\', "\\\\").replace('"', "\\\""));
198+
result.push_str("\", \"");
199+
result.push_str(&name.replace('\\', "\\\\").replace('"', "\\\""));
200+
result.push_str("\", ");
201+
result.push_str(&arg_count.to_string());
202+
result.push(']');
203+
}
204+
result.push_str("\n]");
205+
result
206+
}
207+
208+
/// Manually serialize CoreFn to JSON
209+
fn serialize_core_fn(core_fn: &CoreFn) -> String {
210+
let mut result = String::from("{");
211+
212+
// params
213+
result.push_str("\"params\": [");
214+
for (i, param) in core_fn.params.iter().enumerate() {
215+
if i > 0 {
216+
result.push_str(", ");
217+
}
218+
result.push_str(&serialize_core_ty(param));
219+
}
220+
result.push_str("], ");
221+
222+
// ret
223+
result.push_str("\"ret\": ");
224+
if let Some(ref ret) = core_fn.ret {
225+
result.push_str(&serialize_core_ty(ret));
226+
} else {
227+
result.push_str("null");
228+
}
229+
result.push_str(", ");
230+
231+
// retptr
232+
result.push_str(&format!("\"retptr\": {}, ", core_fn.retptr));
233+
234+
// retsize
235+
result.push_str(&format!("\"retsize\": {}, ", core_fn.retsize));
236+
237+
// paramptr
238+
result.push_str(&format!("\"paramptr\": {}", core_fn.paramptr));
239+
240+
result.push('}');
241+
result
242+
}
243+
244+
/// Manually serialize CoreTy to JSON
245+
fn serialize_core_ty(core_ty: &CoreTy) -> String {
246+
match core_ty {
247+
CoreTy::I32 => "\"i32\"".to_string(),
248+
CoreTy::I64 => "\"i64\"".to_string(),
249+
CoreTy::F32 => "\"f32\"".to_string(),
250+
CoreTy::F64 => "\"f64\"".to_string(),
251+
}
252+
}

0 commit comments

Comments
 (0)