Skip to content
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

[NativeAOT-LLVM] Add the WasmComponentTypeWit item group #2859

Draft
wants to merge 3 commits into
base: feature/NativeAOT-LLVM
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/using-nativeaot/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Another large contributor to the size is globalization support (ICU data and cod

Additionally, NativeAOT-LLVM supports the following properties:
- `WasmHtmlTemplate`: specifies path to the HTML template within which the WASM application will be embedded. An example of a minimal template can be found in the Emscripten repo: https://github.com/emscripten-core/emscripten/blob/main/src/shell_minimal.html
And item groups:
- `WasmComponentTypeWit`: WIT files that will be passed to the linker to define the imports and exports ('world') of the application as a component.

## WebAssembly native libraries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ The .NET Foundation licenses this file to you under the MIT license.
</ItemGroup>

<ItemGroup>
<_WasiComponentImports Include="$(IlcFrameworkNativePath)*.wit" />
<WasmComponentTypeWit Include="$(IlcFrameworkNativePath)*.wit" />

<NativeLibrary Include="$(IlcFrameworkNativePath)libSystem.Native.a" />
<NativeLibrary Include="$(IlcFrameworkNativePath)libSystem.Native.TimeZoneData.a" Condition="'$(InvariantTimezone)' != 'true'" />
Expand All @@ -566,7 +566,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<CustomLinkerArg Include="@(NativeObjects->'&quot;%(Identity)&quot;'->Replace(&quot;\&quot;, &quot;/&quot;))" />
<!-- The canary function should be last in the linked output. But adding it to Native[Library|Object] runs into https://github.com/dotnet/msbuild/issues/5937. -->
<CustomLinkerArg Include="&quot;$(IlcSdkPath.Replace('\', '/'))libStackTraceIpCanary.o&quot;" Condition="'$(_targetOS)' == 'browser'" />
<CustomLinkerArg Include="@(_WasiComponentImports->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" />
<CustomLinkerArg Include="@(WasmComponentTypeWit->'-Wl,--component-type,&quot;%(FullPath)&quot;')" />
<CustomLinkerArg Include="-o &quot;$(NativeBinary.Replace(&quot;\&quot;, &quot;/&quot;))&quot;" />
<CustomLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="-g3" />
<CustomLinkerArg Condition="'$(NativeDebugSymbols)' != 'true'" Include="-Wl,--strip-all" />
Expand Down
38 changes: 7 additions & 31 deletions src/tests/nativeaot/SmokeTests/SharedLibrary/SharedLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,16 @@ public static int DoCheckSimpleGCCollect()
}

[UnmanagedCallersOnly(EntryPoint = "test-http")]
public static unsafe void wasmExportTestHttp(int p0)
public static unsafe void TestHttp(int port)
{
TestHttp((((ushort)p0)));
}

public static void TestHttp(ushort port)
{
var stopwatch = new Stopwatch();
stopwatch.Start();

var task = TestHttpAsync(port);
while (!task.IsCompleted)
{
WasiEventLoop.DispatchWasiEventLoop();
}
var exception = task.Exception;
if (exception is not null)
{
throw exception;
}
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "PollWasiEventLoopUntilResolvedVoid")]
static extern void PollWasiEventLoopUntilResolvedVoid(Thread t, Task task);

Stopwatch stopwatch = Stopwatch.StartNew();
PollWasiEventLoopUntilResolvedVoid(null, TestHttpAsync((ushort)port));
stopwatch.Stop();
// Verify that `WasiEventLoop.DispatchWasiEventLoop` returned

// Verify that `PollWasiEventLoopUntilResolvedVoid` returned
// promptly once the main task finished, even if there were other
// tasks (e.g. the default 100 second HttpClient timeout) still in
// progress.
Expand Down Expand Up @@ -239,15 +226,4 @@ private static async Task TestHttpAsync(ushort port)
Trace.Assert(stopwatch.ElapsedMilliseconds < 1000);
}
}

internal static class WasiEventLoop
{
internal static void DispatchWasiEventLoop()
{
CallDispatchWasiEventLoop((Thread)null!);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "DispatchWasiEventLoop")]
static extern void CallDispatchWasiEventLoop(Thread t);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<!-- Unable to compile a project with the Library output type for apple mobile devices -->
<CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>

<!-- https://github.com/dotnet/runtimelab/issues/2648 -->
<CLRTestTargetUnsupported Condition="'$(TargetOS)' == 'wasi'">true</CLRTestTargetUnsupported>

<!-- Regression test for https://github.com/dotnet/runtime/issues/105330: make sure the UnmanagedCallersOnly are completely unreferenced,
not even from stack trace mapping data -->
<StackTraceSupport>false</StackTraceSupport>
Expand Down Expand Up @@ -66,6 +63,6 @@ cp SharedLibraryDriver$(NativeExtension) native/SharedLibrary$(NativeExtension)

<ItemGroup Condition="'$(WasiReactorTestUsingNodeJS)' == 'true'">
<Content Include="SharedLibraryDriver.mjs" CopyToOutputDirectory="PreserveNewest" />
<CustomLinkerArg Include="-Wl,--component-type,&quot;$(MSBuildProjectDirectory.Replace(&quot;\&quot;, &quot;/&quot;))/wit/world.wit&quot;" />
<WasmComponentTypeWit Include="wit/world.wit" />
</ItemGroup>
</Project>
Loading