diff options
author | Jasper-Bekkers <bekkers@gmail.com> | 2019-12-10 16:12:16 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-12-11 01:48:01 +0100 |
commit | 09f6c1d921a987ec2b20e0033d1bbbb36b0e22ef (patch) | |
tree | 94b7f1cb955ee63baccfee3beb66f686f9a5e50b /src/codegen/mod.rs | |
parent | 7d61f36a5bfcfe2ea533f5edcae8bb6991683432 (diff) |
Add support for wasm_import_module
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d9ac4aa0..b1612c70 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3611,10 +3611,22 @@ impl CodeGenerator for Function { attributes.push(attributes::link_name(link_name)); } + // Unfortunately this can't piggyback on the `attributes` list because + // the #[link(wasm_import_module)] needs to happen before the `extern "C"` block. + // it doesn't get picked up properly otherwise + let wasm_link_attribute = + ctx.options().wasm_import_module_name.as_ref().map(|name| { + quote! { + #[link(wasm_import_module = #name)] + } + }); + let ident = ctx.rust_ident(canonical_name); - let tokens = quote!( extern #abi { - #(#attributes)* - pub fn #ident ( #( #args ),* ) #ret; + let tokens = quote!( + #wasm_link_attribute + extern #abi { + #(#attributes)* + pub fn #ident ( #( #args ),* ) #ret; }); result.push(tokens); } |