Skip to content

Commit

Permalink
fix engine imports in treeshaking list
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed Jul 15, 2024
1 parent 7c5cb0e commit 6bdbcef
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crates/spidermonkey-embedding-splicer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,25 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent {
},
)) = decode(&engine)
{
// merge the imports from the engine with the imports from the guest content.
for (k, _) in &engine_resolve.worlds[engine_world].imports {
guest_imports.push(engine_resolve.name_world_key(k));
{
// Componentize the Starlingmonkey engine so that we can pull in the imports that are actually used.
let bytes = include_bytes!("../../../StarlingMonkey/host-apis/wasi-0.2.0/preview1-adapter-release/wasi_snapshot_preview1.wasm");
let component = wit_component::ComponentEncoder::default()
.adapter("wasi_snapshot_preview1", bytes)
.map_err(|e| e.to_string())?
.module(&engine)
.map_err(|e| e.to_string())?
.encode()
.map_err(|e| e.to_string())?;
let decoded = wit_component::decode(&component).unwrap();
let resolve = decoded.resolve();
let packages = decoded.package();
let world_id = resolve.select_world(packages, None).unwrap();
let world = &resolve.worlds[world_id];
// merge the imports actually used by the engine with the imports from the guest content.
for (import_key, _) in world.imports.iter() {
guest_imports.push(resolve.name_world_key(import_key));
}
}

// we disable the engine run and incoming handler as we recreate these exports
Expand Down

0 comments on commit 6bdbcef

Please sign in to comment.