Skip to content

Merge WASM Files #223

Closed
Closed
@al3xfischer

Description

@al3xfischer

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(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions