walrus
walrus copied to clipboard
Merge WASM Files
Summary
Is there any API to add a function from an other module?
Additional Details
I'm trying to merge two WASM files.
In the first step, I want to merge the functions, but I'm not able to add the function from the module_b to the module_a.
As use can see below, I'm using module.funcs.add_local
but the method is expecting a LocalFunction
but I didn't find a way to extract the function as a LocalFunction
nor did I figure out a way to create it from the Function
.
I'm using add_local
because I didn't find any other method that allowed me to add a new function to a module.
Is there an API for my use case, or is this currently not supported? (Or am I missing something?.. )
Thanks in advance
use anyhow::Error;
use walrus::*;
fn main() -> Result<(), Error> {
let module_a = Module::from_file("fancy.wasm")?;
let module_b = Module::from_file("add.wasm")?;
// module_b constians only one func
let my_fancy_func = module_b.funcs.iter().next().unwrap();
// let module_a.funcs.add(my_fancy_func)
// mismachted types exepected struct 'LocalFunction', found 'walrus::Function'
module_a.funcs.add_local(*my_fancy_func);
Ok(())
}
i know this is year late but you can match on function.kind and you get FunctionKind::Local(LocalFunction)
the hard part is making sure all the local and what not play nice in the combined wasm which i have not yet managed