Skip to content

Enable wasm-tools workload for CoreCLR WASM targets#130380

Draft
lewing wants to merge 8 commits into
dotnet:mainfrom
lewing:lewing/coreclr-wasm-workload
Draft

Enable wasm-tools workload for CoreCLR WASM targets#130380
lewing wants to merge 8 commits into
dotnet:mainfrom
lewing:lewing/coreclr-wasm-workload

Conversation

@lewing

@lewing lewing commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Enables the existing wasm-tools workload to function with CoreCLR WASM targets, allowing native relinking and future AOT compilation via the same workload that Mono users already install.

Changes

SDK/Targets

  • Sdk.targets.in: Import BrowserWasmApp.CoreCLR.targets when RuntimeFlavor=CoreCLR
  • BrowserWasmApp.CoreCLR.targets: Guard native targets import for workload path; fix static asset ordering (_ComputeWasmBuildCandidates before native relink); fix satellite assembly handling during nested publish
  • WorkloadManifest.targets.in: Set WasmNativeWorkload=true for CoreCLR path when workload is installed
  • WebAssembly.Sdk.pkgproj: Include BrowserWasmApp.CoreCLR.targets in SDK package

Test Fix

  • PInvokeTableGeneratorTests.cs: Fix CoreCLR pinvoke table filename (callhelpers-pinvoke.cpp not pinvoke-table.cpp)

Architecture

Unlike Mono, CoreCLR does not need its own workload definition. The existing wasm-tools workload already contains the WebAssembly SDK and Emscripten packs that CoreCLR needs. The SDK targets detect RuntimeFlavor and import the correct .targets file. CoreCLR runtime packs are resolved by the SDK via KnownRuntimePack.

Related

Note

This PR was generated with the assistance of GitHub Copilot.

lewing and others added 6 commits July 8, 2026 16:42
Add a new 'wasm-tools-coreclr' workload that provides native relinking
support for CoreCLR browser-wasm projects without pulling in Mono
dependencies (MonoAOTCompiler, MonoTargets.Sdk, Mono runtime pack).

Unlike Mono, CoreCLR doesn't need its runtime pack bundled in the
workload — the SDK resolves it via the standard KnownRuntimePack
mechanism. The workload only provides:
- Build targets for native relinking (BrowserWasmApp.CoreCLR.targets)
- Emscripten SDK (shared via microsoft-net-sdk-emscripten)

Changes:
- Package BrowserWasmApp.CoreCLR.targets into WebAssembly.Sdk NuGet pack
- Add conditional import in Sdk.targets.in (UseMonoRuntime switches path)
- Add wasm-tools-coreclr workload to manifest (no Mono deps)
- Add CoreCLR import group in WorkloadManifest.targets.in
- Skip MonoAOTCompiler import when UseMonoRuntime=false

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guard the native.wasm.targets import with a condition so it only loads
when RepositoryEngineeringDir is set (in-tree builds). For the workload
path, inline the GenerateEmccExports target with the required exported
runtime methods and functions. Emscripten SDK acquisition is already
handled by EmSdkRepo.Defaults.props + the emscripten workload extension.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Include libminipal.a in browser-wasm CoreCLR runtime pack. It was
  excluded from LibrariesSharedFrameworkDir glob but unlike libz.a and
  libSystem.IO.Compression.Native.a it only exists in sharedFramework/
  (not the parent LibrariesNativeArtifactsPath), so the exclusion
  prevented it from shipping at all. libminipal.a is a distinct library
  from libcoreclrminipal.a and is needed by the emcc linker.

- Fix PInvokeTableGeneratorTests to use correct CoreCLR output filename
  callhelpers-pinvoke.cpp instead of pinvoke-table.cpp.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The _CoreCLRWasmNativeForBuild target must run before _ComputeWasmBuildCandidates
(not just _ResolveWasmOutputs) so the relinked dotnet.native.wasm replaces the
runtime pack version in the static web assets pipeline. Without this, the runtime
pack binary is served and user P/Invoke modules fail with DllNotFoundException.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
During nested publish, _GatherWasmFilesToPublish populates WasmAssembliesToBundle
from ResolvedFileToPublish (which includes app satellite assemblies). The CoreCLR
build pipeline was calling _GatherWasmFilesToBuild which overwrites this list with
build-time items that omit app satellites, causing ComputeWasmPublishAssets to fail.

Introduce _CoreCLRGatherWasmFiles wrapper that skips _GatherWasmFilesToBuild during
nested publish, preserving the publish-time assembly list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the exclusion of libminipal.a from the LibrariesSharedFrameworkDir
glob. The file is already included via CoreCLRSharedFrameworkDir (line 111),
so including it from both locations causes NU5118 duplicate file error
during nupkg creation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 21:43

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.

Pull request overview

This PR updates the WebAssembly SDK/workload targets so wasm-tools can be used with CoreCLR browser-wasm builds (selecting CoreCLR vs Mono via UseMonoRuntime), and adjusts CoreCLR-specific build target behavior for workload vs in-tree usage. It also fixes a Wasm.Build.Tests expectation to match the CoreCLR pinvoke table output filename.

Changes:

  • Route WebAssembly SDK target imports to BrowserWasmApp.CoreCLR.targets when UseMonoRuntime=false, and package that targets file in the WebAssembly SDK pack.
  • Update the mono toolchain workload manifest to avoid importing Mono-specific packs/tasks when UseMonoRuntime=false, and to import the WebAssembly SDK for CoreCLR browser-wasm.
  • Update CoreCLR browser-wasm targets to tolerate the workload (no in-tree native.wasm.targets), adjust target ordering, and avoid a nested-publish satellite assembly overwrite.
  • Fix CoreCLR pinvoke table filename in PInvokeTableGeneratorTests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mono/wasm/Wasm.Build.Tests/PInvokeTableGeneratorTests.cs Updates the CoreCLR pinvoke table filename expectation to callhelpers-pinvoke.cpp.
src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/WorkloadManifest.targets.in Gates Mono-only workload imports on UseMonoRuntime != false and adds a CoreCLR browser-wasm import group for the WebAssembly SDK.
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets.in Selects Mono vs CoreCLR browser targets based on UseMonoRuntime.
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj Packages BrowserWasmApp.CoreCLR.targets into the WebAssembly SDK.
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets Adds workload-safe guards and a fallback GenerateEmccExports, adjusts build/publish target ordering, and avoids nested-publish satellite assembly loss.

Comment on lines +78 to +83
<!-- Import shared native.wasm.targets for Emscripten SDK, ICU, exported functions/methods.
Only available in-tree (RepositoryEngineeringDir is set by the build system).
For the workload path we use EmSdkRepo.Defaults.props and inline the exported
functions/methods below. -->
<Import Project="$(RepositoryEngineeringDir)native.wasm.targets"
Condition="'$(RepositoryEngineeringDir)' != '' and Exists('$(RepositoryEngineeringDir)native.wasm.targets')" />
Move native.wasm.targets import after the fallback GenerateEmccExports
target so that when building in-tree, the authoritative definition in
eng/native.wasm.targets wins (MSBuild last-definition-wins). For the
workload path where native.wasm.targets is not available, the fallback
list in BrowserWasmApp.CoreCLR.targets is used instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 22:25

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Include the CoreCLR browser-wasm runtime pack in the wasm-tools
workload manifest so it gets bundled and downloaded together with
the other wasm-tools packs when the workload is installed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 22:34

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +92 to +97
<!-- Fallback exported runtime methods and functions for the emcc link step.
Used when the workload path is active and native.wasm.targets is not available.
When building in-tree, native.wasm.targets is imported AFTER this target (below)
and its GenerateEmccExports definition wins (MSBuild last-definition-wins). -->
<Target Name="GenerateEmccExports"
Condition="'$(TargetsBrowser)' == 'true'">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants