Enable building a stubbed NativeAOT WASM CoreLib - #134210
jtschuster wants to merge 7 commits into
Conversation
Enable the managed NativeAOT CoreLib build for single-threaded browser WASM and provide shape-compatible stubs for runtime functionality that is not implemented yet. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6cdcf8df-1e43-462e-b0a7-b4cea297b576
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6cdcf8df-1e43-462e-b0a7-b4cea297b576
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6cdcf8df-1e43-462e-b0a7-b4cea297b576
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
🟡 Changes recommended
The WASM exception helpers have an ABI mismatch and are missing the required RhpThrowExact export.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds browser-WASM NativeAOT CoreLib stubs and build configuration to unblock compilation while exception handling, stack unwinding, GC, and dynamic thunks remain unsupported.
Changes:
- Adds WASM-specific source selection and platform definitions.
- Stubs thunk allocation, stack tracing, frozen-object memory, and exception handling.
- Removes unsupported native WASM imports and exports placeholder EH helpers.
File summaries
| File | Summary |
|---|---|
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/ThunkPool.NotSupported.cs |
Stubs dynamic thunk operations. |
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.NativeAot.Browser.cs |
Disables browser-WASM stack traces. |
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj |
Selects WASM-specific implementations. |
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/FrozenObjectHeapManager.Wasm.cs |
Stubs virtual memory operations. |
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs |
Omits native stack-trace exports on WASM. |
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs |
Omits unsupported EH and stack-walking imports. |
src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs |
Adds placeholder exception-handling exports. |
src/coreclr/nativeaot/Directory.Build.props |
Adds WASM platform definitions. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 2
- Review effort level: Lite
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // NativeAOT browser-WASM does not currently provide executable thunk allocation. |
| <DefineConstants>TARGET_32BIT;$(DefineConstants)</DefineConstants> | ||
| <!-- WASI support is outside the scope of the NativeAOT managed platform stubs. --> | ||
| <DefineConstants Condition="'$(TargetsBrowser)' == 'true'">TARGET_WASM;$(DefineConstants)</DefineConstants> |
There was a problem hiding this comment.
| <DefineConstants>TARGET_32BIT;$(DefineConstants)</DefineConstants> | |
| <!-- WASI support is outside the scope of the NativeAOT managed platform stubs. --> | |
| <DefineConstants Condition="'$(TargetsBrowser)' == 'true'">TARGET_WASM;$(DefineConstants)</DefineConstants> | |
| <DefineConstants>TARGET_32BIT;TARGET_WASM;$(DefineConstants)</DefineConstants> |
Is there a problem with doing the right thing?
| <FeaturePortableThreadPool>true</FeaturePortableThreadPool> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <FeaturePortableTimer>true</FeaturePortableTimer> |
There was a problem hiding this comment.
We should mirror regular CoreCLR CoreLib setup where possible. For example, this one should mirror:
runtime/src/coreclr/clr.featuredefines.props
Lines 25 to 27 in f881b48
| <DefineConstants>SYSTEM_PRIVATE_CORELIB;$(DefineConstants)</DefineConstants> | ||
| <SkipCommonResourcesIncludes>true</SkipCommonResourcesIncludes> | ||
| <FeatureNativeAot>true</FeatureNativeAot> | ||
| <RuntimeFlavor>CoreCLR</RuntimeFlavor> |
There was a problem hiding this comment.
I had been using I had been using dotnet build src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj , and Subsets.props sets the RuntimeFlavor to Mono when targeting browser if a clr subset is not selected. I can fix up clr.nativeaotlibs and use that instead.
There was a problem hiding this comment.
🟡 Changes recommended
Critical WASI build inconsistencies remain, and the NativeAOT support change belongs in the Arcade-managed source.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 10/11 changed files
- Comments generated: 4
- Review effort level: Lite
| <ItemGroup Condition="$(_subset.Contains('+clr.nativeaotlibs+')) and '$(TargetsBrowser)' == 'true' and '$(TargetsWasm)' == 'true'"> | ||
| <!-- Test.CoreLib fails to build with the stubbed out nativeaot corelib --> | ||
| <ProjectToBuild Remove="$(CoreClrProjectRoot)nativeaot\Test.CoreLib\src\Test.CoreLib.csproj" /> |
There was a problem hiding this comment.
We should drop "Browser" from all changes in this PR. I think all changes would be correct for WASI too.
| <_NativeAotSupportedOS Condition=" | ||
| '$(TargetOS)' != 'browser' and | ||
| '$(TargetOS)' != 'haiku' and |
| // Browser-WASM omits the native EH enumerator and StackFrameIterator implementation. | ||
| #if !TARGET_WASM |
| <ItemGroup Condition="'$(_TargetsBrowserWasm)' == 'true'"> | ||
| <Compile Include="System\Diagnostics\StackTrace.NativeAot.Browser.cs" /> | ||
| </ItemGroup> |
| </Compile> | ||
| </ItemGroup> | ||
| <ItemGroup Condition="'$(InPlaceRuntime)' == 'true'"> | ||
| <ItemGroup Condition="'$(InPlaceRuntime)' == 'true' and '$(TargetOS)' == 'browser' and '$(TargetArchitecture)' == 'wasm'"> |
There was a problem hiding this comment.
Test.CoreLib is excluded for now - this should not be needed.
| } | ||
|
|
||
| [RuntimeExport("RhpThrowEx")] | ||
| [MethodImpl(MethodImplOptions.NoInlining)] |
Building the repro project requires a number of helper methods in CoreLib, but stack unwinding, GC, and EH designs haven't been determined, so in the meantime we could just stub all of these out. This will enable ilc to at compile a WASM module (or at least moves one blocker), though it won't link or run yet.