From 8c9e544b0d4c21562321d3dd4f46a65889e89c90 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 26 Oct 2026 21:08:54 +0100 Subject: [PATCH 1/2] [wasm][coreclr] Default browser R2R publishing to composite Preserve per-assembly opt-outs across consumer and in-tree builds, including nested sample publishes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 519ad6c4-3702-45c6-bb99-0e2ad8573d04 --- .../testing/libraries/testing-wasm.md | 28 +++++++++++-------- src/mono/browser/build/WasmApp.InTree.props | 2 ++ ...bAssembly.Browser.CoreCLR.Defaults.targets | 14 ++++++++++ ...ET.Sdk.WebAssembly.Browser.CoreCLR.targets | 6 ++-- ...icrosoft.NET.Sdk.WebAssembly.Browser.props | 3 ++ src/mono/sample/wasm/Directory.Build.props | 1 + src/mono/sample/wasm/Directory.Build.targets | 1 + .../Wasm.Build.Tests/NativeLibraryTests.cs | 2 +- .../wasm/Wasm.Build.Tests/ReadyToRunTests.cs | 3 +- 9 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets diff --git a/docs/workflow/testing/libraries/testing-wasm.md b/docs/workflow/testing/libraries/testing-wasm.md index 557a85c7c7d27f..6969c5e83600e2 100644 --- a/docs/workflow/testing/libraries/testing-wasm.md +++ b/docs/workflow/testing/libraries/testing-wasm.md @@ -194,26 +194,30 @@ stale staged assets can otherwise cause assembly-loading failures before tests s The `LibraryTestsCoreCLR_R2R` CI jobs use the same configuration and archive the published tests for execution on Helix. The existing interpreter jobs remain separate. -To run a library suite with a single composite ReadyToRun image instead of per-assembly -images, add `PublishReadyToRunComposite=true`: +CoreCLR browser ReadyToRun tests publish a single composite image +(`.r2r.wasm`) by default. It is staged into `wwwroot/_framework` beside +the component WebCIL stubs and listed in the boot config. + +To run a library suite with per-assembly ReadyToRun images instead, add +`PublishReadyToRunComposite=false`: ```bash XHARNESS_COMMAND=test-browser ./build.sh libs.tests -test -os browser -c Release \ --projects $PWD/src/libraries/System.Memory/tests/System.Memory.Tests.csproj \ - /p:RuntimeFlavor=CoreCLR /p:TestWasmReadyToRun=true /p:PublishReadyToRunComposite=true \ + /p:RuntimeFlavor=CoreCLR /p:TestWasmReadyToRun=true /p:PublishReadyToRunComposite=false \ /p:EnableAggressiveTrimming=true /p:Scenario=WasmTestOnChrome /p:InstallChromeForTests=true ``` -The composite image (`.r2r.wasm`) is staged into `wwwroot/_framework` beside -the component WebCIL stubs and listed in the boot config. As with other mode switches, clean -the project-specific `bin` and `obj` outputs when switching between composite and per-assembly -images. +As with other mode switches, clean the project-specific `bin` and `obj` outputs when +switching between composite and per-assembly images. -For CoreCLR browser applications, set `PublishReadyToRun=true` and -`PublishReadyToRunComposite=true` to publish a single composite ReadyToRun image and -component WebCIL stubs instead of per-assembly images. Publishing requires a wasm-capable -crossgen2 and WebCIL enabled; the composite is loaded before the runtime starts. -`ReadyToRunTests.PublishRunAllPagesComposite` exercises trimmed, untrimmed, and +For CoreCLR browser applications, ReadyToRun remains opt-in: set +`PublishReadyToRun=true` to publish a single composite ReadyToRun image and component +WebCIL stubs. Set `PublishReadyToRunComposite=false` to retain per-assembly images. +Publishing requires a wasm-capable crossgen2. Composite publishing additionally requires +ReadyToRun SDK tasks that support wasm composite output naming and WebCIL enabled; +the composite is loaded before the runtime starts. +`ReadyToRunTests.PublishRunAllPagesComposite` exercises the default mode with trimmed, untrimmed, and native-relinked publishes in a browser, including asset fingerprinting when `USE_FINGERPRINTING_FOR_TESTS=true`. diff --git a/src/mono/browser/build/WasmApp.InTree.props b/src/mono/browser/build/WasmApp.InTree.props index 2eb17ec0c0f94c..4634f534918b3e 100644 --- a/src/mono/browser/build/WasmApp.InTree.props +++ b/src/mono/browser/build/WasmApp.InTree.props @@ -17,6 +17,8 @@ false + + true false diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets new file mode 100644 index 00000000000000..57b8aeaea309d3 --- /dev/null +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets @@ -0,0 +1,14 @@ + + + + true + + diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets index 3c08f87116f957..ff459ebc3a15a2 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets @@ -21,8 +21,6 @@ Copyright (c) .NET Foundation. All rights reserved. wasm - - false $(PublishReadyToRunCrossgen2ExtraArgs);--opt-cross-module:* @@ -56,7 +54,7 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'$(PublishReadyToRun)' == 'true'" BeforeTargets="_WasmCoreClrSelectR2RDirectories;_ResolveWasmOutputs"> + Text="PublishReadyToRunComposite for CoreCLR browser-wasm requires WebCIL-in-Wasm assemblies; enable WasmEnableWebcil. To opt out of composite mode, set PublishReadyToRunComposite=false." /> @@ -77,7 +75,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmCompositeOwnerEntry Include="@(_ReadyToRunCompileList->WithMetadataValue('CreateCompositeImage', 'true'))" /> + Text="PublishReadyToRunComposite for CoreCLR browser-wasm requires ReadyToRun SDK tasks that name the composite image '<entry>.r2r.wasm', but they planned '$([System.IO.Path]::GetFileName('%(_WasmCompositeOwnerEntry.OutputR2RImage)'))'. Use an SDK with wasm ReadyToRun output naming (dotnet/sdk#56395), or set Crossgen2SdkOverridePropsPath and Crossgen2SdkOverrideTargetsPath to the dotnet/runtime Crossgen2Tasks. To opt out of composite mode, set PublishReadyToRunComposite=false." /> + $(BeforeMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets - true false diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets deleted file mode 100644 index 57b8aeaea309d3..00000000000000 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets +++ /dev/null @@ -1,14 +0,0 @@ - - - - true - - diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props index 2fcdc42126407b..3b44a521a85a16 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props @@ -24,6 +24,8 @@ Copyright (c) .NET Foundation. All rights reserved. false + true + partial full @@ -38,9 +40,6 @@ Copyright (c) .NET Foundation. All rights reserved. $(StaticWebAssetsAdditionalPublishPropertiesToRemove);NoBuild;RuntimeIdentifier true true - - - $(BeforeMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.Defaults.targets