lqd · GitHub

Related to #29 is the issue of importing wasm functions from other wasm modules (or the environment, say, a JS function). What form should it take in our rust code ?

Some more info https://github.com/WebAssembly/design/blob/master/Modules.md#imports
Example https://github.com/WebAssembly/testsuite/blob/master/imports.wast#L2

Making it work similarly to the current FFI machinery would make sense, and this would look good I think:

#[link(name="spectest")]
extern {
    fn print(i: i32);
}

However, and this might be special treatment for the spectest module (probably @kripken can shed some light on this topic), it seems in this case — as seen in the linked example — the print function is overloaded. This might be a special case because exports are apparently required to have a unique name, IIUC meaning one might not be able to produce the same exports as the spectest module provides.

If this is to be supported — which is itself an interesting question, especially since printing is right now our "only" way to test — we might need to roll our own custom attribute à la:

extern {
    #[wasm_import(module="specttest", name="print")]
    fn print_i32(i: i32);
    #[wasm_import(module="specttest", name="print")]
    fn print_i64(i: i64);
}

There may be other attributes or language features more closely matching the semantics/requirements ? Maybe #[link_args] could be of use, etc.

@brson and @eholk what do you think ?

Read the original on github.com ↗