Skip to content

Enable building a stubbed NativeAOT WASM CoreLib - #134210

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

jtschuster wants to merge 13 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
Comment thread src/coreclr/nativeaot/Directory.Build.props Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
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 Outdated
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

@am11 am11 Sep 20, 2026 •

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 can create additional PR upstream so overwriting doesn’t revert it, without dropping the changes here. It’s not exactly prohibited.

Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs Outdated
Copilot AI review requested due to automatic review settings September 22, 2026 22:27

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.

Copilot review overview

🟡 Changes recommended

The WASI TARGET_UNIX definition must be corrected, and the browser-specific source should be renamed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Low severity

Open (4)
Resolved since last review (2)

Comment thread src/coreclr/nativeaot/Directory.Build.props Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Copilot AI review requested due to automatic review settings September 23, 2026 18:20

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.

Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.wasm.cs Outdated
Comment thread src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 23, 2026 18:30

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.

Copilot review overview

🟡 Changes recommended

The WASM EH stub omits a required member, and WASM perf-tracing configuration remains inconsistent.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Low severity Clarify comment applies to all WASM targets, including WASI

src/​coreclr/​nativeaot/​Runtime.Base/​src/​System/​Runtime/​InternalCalls.cs:147

This guard applies to every TARGET_WASM build, including WASI, but the new comment limits the rationale to Browser-WASM. Since the surrounding project now explicitly enables both browser and WASI NativeAOT, the comment is inaccurate and can mislead future changes; describe the shared WASM limitation instead.

[!NOTE] This review comment was generated by GitHub Copilot.

Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/Directory.Build.props Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj Outdated
Comment on lines 58 to 59
<FeatureComWrappers>true</FeatureComWrappers>
<DefineConstants Condition="'$(FeatureComWrappers)' == 'true'">FEATURE_COMWRAPPERS;$(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.

CoreCLR disables FeatureComWrappers on non-Windows/non-Unix, this is the first such target.

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.

Also cc @dotnet/interop-contrib just in case - not sure if ComWrappers being disabled on Browser/WASI is intentional. We disable the tests with no tracking bug and the disablement was done in one of those "let's just bulk disable everything that doesn't work" PRs so not clear if this is intentional.

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.

not sure if ComWrappers being disabled on Browser/WASI is intentional

I see no reason to add support for ComWrappers on Browser/WASI at this point. If we get it "for free" that might be okay, but investigating COM scenarios on that platform sounds painful. I'm also suspicious of anyone using COM there for interop or API design. My guidance would be avoid enabling it for now since it is already disabled and if someone squeeks we can have the conversation.

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.

I would like to ifdef out and IL trim any COM code that still remains there.

- Use Unix implementations instead of separate wasm implementations for StackTrace.NativeAot.cs and FrozenObjectHeap.cs
- Remove useless Feature defines
- Disable ComWrappers support
- Don't define TARGET_UNIX for WASM and add || TARGET_WASM to TARGET_UNIX where necessary.
Copilot AI review requested due to automatic review settings September 24, 2026 20:23

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.

Copilot review overview

🟡 Changes recommended

Unresolved critical WASI ABI and COM-wrapper feature-definition issues block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity

Open (3)
Resolved since last review (1)

Comment on lines 104 to +106
<DefineConstants Condition="'$(TargetsUnix)'=='true'">TARGET_UNIX;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(TargetsBrowser)'=='true'">TARGET_BROWSER;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(TargetsWasi)'=='true'">TARGET_WASI;$(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.

I don't see us setting TARGET_UNIX on WASI with CoreCLR corelib. I assume we're just getting the lobotomized copilot review agent.

Comment on lines +46 to +48
<PropertyGroup Condition="'$(TargetsWasm)' == 'true'">
<FeatureThunkPool>false</FeatureThunkPool>
<FeatureComWrappers>false</FeatureComWrappers>
// StackFrameIterator
//

// Browser-WASM does not have the native register context required by this iterator.

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
// Browser-WASM does not have the native register context required by this iterator.
// WASM does not have the native register context required by this iterator.

internal static unsafe void FreeLibrary(IntPtr hModule)
{
#if !TARGET_UNIX
#if !(TARGET_UNIX || TARGET_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.

Suggested change
#if !(TARGET_UNIX || TARGET_WASM)
#if TARGET_WINDOWS

internal static unsafe void FreeLibrary(IntPtr hModule)
{
#if !TARGET_UNIX
#if !(TARGET_UNIX || TARGET_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.

The original already wasn't great but this is making it even worse.

Suggested change
#if !(TARGET_UNIX || TARGET_WASM)
#if TARGET_WINDOWS

Comment on lines 104 to +106
<DefineConstants Condition="'$(TargetsUnix)'=='true'">TARGET_UNIX;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(TargetsBrowser)'=='true'">TARGET_BROWSER;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(TargetsWasi)'=='true'">TARGET_WASI;$(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.

I don't see us setting TARGET_UNIX on WASI with CoreCLR corelib. I assume we're just getting the lobotomized copilot review agent.

This branch has not been deployed

No deployments
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.

7 participants