Enable wasm-tools workload for CoreCLR WASM targets#130380
Draft
lewing wants to merge 8 commits into
Draft
Conversation
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>
Contributor
There was a problem hiding this comment.
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.targetswhenUseMonoRuntime=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 CoreCLRbrowser-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>
3 tasks
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>
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'"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enables the existing
wasm-toolsworkload 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
BrowserWasmApp.CoreCLR.targetswhenRuntimeFlavor=CoreCLR_ComputeWasmBuildCandidatesbefore native relink); fix satellite assembly handling during nested publishWasmNativeWorkload=truefor CoreCLR path when workload is installedBrowserWasmApp.CoreCLR.targetsin SDK packageTest Fix
callhelpers-pinvoke.cppnotpinvoke-table.cpp)Architecture
Unlike Mono, CoreCLR does not need its own workload definition. The existing
wasm-toolsworkload already contains the WebAssembly SDK and Emscripten packs that CoreCLR needs. The SDK targets detectRuntimeFlavorand import the correct.targetsfile. CoreCLR runtime packs are resolved by the SDK viaKnownRuntimePack.Related
Note
This PR was generated with the assistance of GitHub Copilot.