Proposal to add WasmImportAttribute to control wasm module names by yowl · Pull Request #93823 · dotnet/runtime (original) (raw)
This PR proposes a new attribute to be used to control the Wasm import module and function names. In Wasm when a function is imported it can be specified as coming from a named module using this WAT
(import "hellowasi" "reverse" (func $reverse (type 4)))
The first use of this would be in the experimental NativeAOT-LLVM backend, but the desire is to have something that works for Mono and NativeAOT-LLVM. Something that we can use to proceed with Wasm Components and WIT binding via source gen for both Mono and NativeAOT-LLVM.
DllImportAttribute
has a Value
and EntryPoint
which can be used to define the names, but to preserve existing semantics including static linking for DllImport("*")
and DirectPInvoke
we cannot simply say that we should always create a Wasm import if the DllImport
Value
is not *
. The presence of this new WasmImport
will distinguish these use cases and the attribute has no properties.
Please see dotnet/runtimelab#2414 for how we got here and in particular, dotnet/runtimelab#2414 (comment).
Other issues and PRs of note on this subject:
dotnet/runtimelab#1390
dotnet/runtimelab#1845
dotnet/runtimelab#2410
dotnet/runtimelab#2383
It has been noted (dotnet/runtimelab#2414 (comment)) that WasmImport
is a potentially confusing name as the Import
suffix can infer it's use should be as an alternative to DllImport
but this is not the case, so some other alternatives that I could think of:
WasmDynamicLink
WasmImportLink
WasmModuleLink
LlvmWasmImport
(not good for Mono interpreter perhaps)WasmNamedModule
Thanks for reading.
cc @AaronRobinsonMSFT @dotnet/nativeaot-llvm @pavelsavara