-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wasm] Implement initial support for WasmImportLinkage in the AppBuilders #94615
Changes from 11 commits
1b28014
257df00
89598ad
84d4ded
b14aa80
ed51af9
22a1295
4f1ffaa
bf94e44
7ded5ea
b21c143
095d9bb
d74c814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
TOP=../../../../.. | ||
|
||
include ../wasi.mk | ||
|
||
ifneq ($(AOT),) | ||
override MSBUILD_ARGS+=/p:RunAOTCompilation=true | ||
endif | ||
|
||
ifneq ($(V),) | ||
DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug | ||
endif | ||
|
||
PROJECT_NAME=Wasi.Console.Sample.csproj | ||
|
||
run: run-console |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
public unsafe class Test | ||
{ | ||
[UnmanagedCallersOnly(EntryPoint = "ManagedFunc")] | ||
public static int MyExport(int number) | ||
{ | ||
// called from MyImport aka UnmanagedFunc | ||
Console.WriteLine($"MyExport({number}) -> 42"); | ||
return 42; | ||
} | ||
|
||
[DllImport("*", EntryPoint = "UnmanagedFunc")] | ||
public static extern void MyImport(); // calls ManagedFunc aka MyExport | ||
|
||
public unsafe static int Main(string[] args) | ||
{ | ||
Console.WriteLine($"main: {args.Length}"); | ||
// workaround to force the interpreter to initialize wasm_native_to_interp_ftndesc for MyExport | ||
if (args.Length > 10000) { | ||
((IntPtr)(delegate* unmanaged<int,int>)&MyExport).ToString(); | ||
} | ||
|
||
MyImport(); | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier> | ||
|
||
<TargetOs>wasi</TargetOs> | ||
<WasmBuildNative>true</WasmBuildNative> | ||
<WasmNativeStrip>false</WasmNativeStrip> | ||
<IsBrowserWasmProject>false</IsBrowserWasmProject> | ||
<WasmSingleFileBundle>true</WasmSingleFileBundle> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<NativeFileReference Include="local.c" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I understand correctly that all symbols in this sample are statically linked inside dotnet.wasm ? If so, should we also have sample that makes them external ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably need to happen in the tests rather than the sample, I'm pretty sure the smoke tests run the samples and the import wouldn't resolve. |
||
</ItemGroup> | ||
<Target Name="RunSample" DependsOnTargets="RunSampleWithWasmtime" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
|
||
int ManagedFunc(int number); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
|
||
void UnmanagedFunc() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did the mismatched names on purpose to demonstrate what setting EntryPoint does in both cases |
||
{ | ||
int ret = 0; | ||
printf("UnmanagedFunc calling ManagedFunc\n"); | ||
ret = ManagedFunc(123); | ||
printf("ManagedFunc returned %d\n", ret); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with Pavel that it might be good for the entrypoint and managed name to match, unless we are explicitly testing that you can make them not match and it will still work