Skip to content

Enable building a stubbed NativeAOT WASM CoreLib - #134210

Open
jtschuster wants to merge 7 commits into
dotnet:mainfrom
jtschuster:nativeaot-wasm-runtime-pack
Open

jtschuster wants to merge 7 commits into
dotnet:mainfrom
jtschuster:nativeaot-wasm-runtime-pack

Conversation

@jtschuster

Copy link
Copy Markdown
Member

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.

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
@jtschuster jtschuster added this to the 12.0.0 milestone Sep 18, 2026
@jtschuster
jtschuster requested a review from agocke September 18, 2026 18:33
@jtschuster jtschuster self-assigned this Sep 18, 2026
Copilot AI lite review requested due to automatic review settings September 18, 2026 18:33
@jtschuster jtschuster added the arch-wasm WebAssembly architecture label Sep 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs Outdated
Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs Outdated
// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And never will...

Comment on lines +81 to +83
<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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mirror regular CoreCLR CoreLib setup where possible. For example, this one should mirror:

<!-- single thread -->
<FeaturePortableTimer Condition="'$(WasmEnableThreads)' != 'true'">false</FeaturePortableTimer>
<FeaturePortableThreadPool Condition="'$(WasmEnableThreads)' != 'true'">false</FeaturePortableThreadPool>

<DefineConstants>SYSTEM_PRIVATE_CORELIB;$(DefineConstants)</DefineConstants>
<SkipCommonResourcesIncludes>true</SkipCommonResourcesIncludes>
<FeatureNativeAot>true</FeatureNativeAot>
<RuntimeFlavor>CoreCLR</RuntimeFlavor>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings September 18, 2026 21:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread eng/Subsets.props
Comment on lines +605 to +607
<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" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should drop "Browser" from all changes in this PR. I think all changes would be correct for WASI too.

Comment on lines 5 to 6
<_NativeAotSupportedOS Condition="
'$(TargetOS)' != 'browser' and
'$(TargetOS)' != 'haiku' and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid feedback

Comment on lines +124 to +125
// Browser-WASM omits the native EH enumerator and StackFrameIterator implementation.
#if !TARGET_WASM
Comment on lines +318 to +320
<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'">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test.CoreLib is excluded for now - this should not be needed.

}

[RuntimeExport("RhpThrowEx")]
[MethodImpl(MethodImplOptions.NoInlining)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why NoInlining?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-NativeAOT-coreclr

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants