Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge WASM Files #223

Open
al3xfischer opened this issue Dec 21, 2021 · 1 comment
Open

Merge WASM Files #223

al3xfischer opened this issue Dec 21, 2021 · 1 comment
Labels
question Further information is requested

Comments

@al3xfischer
Copy link

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(())
}
@al3xfischer al3xfischer added the question Further information is requested label Dec 21, 2021
@deltanedas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants