-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Background and motivation
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 WasmImportLinkage 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
Proposed PR #93823
API Proposal
namespace System.Runtime.InteropServices;
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public sealed class WasmImportLinkageAttribute : Attribute
{
public WasmImportLinkageAttribute() { }
}API Usage
[WasmImportLinkage]
[DllImport("library")]
static extern void Func();Alternative Designs
It has been noted (dotnet/runtimelab#2414 (comment)) that the original WasmImport suggestion was 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:
WasmDynamicLinkAttribute
WasmImportLinkageAttribute - Updated this proposal
WasmModuleLinkAttribute
LlvmWasmImportAttribute (not good for Mono interpreter perhaps)
WasmNamedModuleAttribute
Risks
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status