-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for #[wasm_import_module] #52090
Copy link
Copy link
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCO-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a tracking issue for the
#[wasm_import_module]attribute and thewasm_import_modulefeature. This attribute is applied toextern { ... }blocks like so:The WebAssembly specification requires that all imported values from the host environment have a two-level namespace:
Additionally only globals (like static variables), functions, memories, and tables can be imported. The
extern { ... }language block is used to import globals and functions, memories and tables cannot currently be manually imported.Each field of the wasm import needs to be configurable by Rust as both fields have semantic meaning. Typically the first field of the import is the "module" interpreted as an ES module, and the second field is what to import from that module.
Currently LLVM and LLD will default imports to the "env" module. This means that if you compile this code:
it will generate a wasm file that imports the function "foo" from the module "env". By using
#[wasm_import_module]we can customize what happens here:This attribute must be of the form
#[wasm_import_module = "string"], no other forms are accepted. It can only be attached to anexternblock. All items in the block are considered to come from the same module. Through the usage of#[link_name]we can then configure both fields of WebAssembly imports arbitrarily:The
#[wasm_import_module]is accepted on non-wasm platforms but has no effect, it is simply an ignored attribute.Helpful links:
Open questions and TODO
#[link(wasm_import_module = "...")]?cc rustwasm/team#82