Repository navigation
[browser][coreclr] Fix stale R2R prune deleting fresh images with unnormalized intermediate paths - #137229
Conversation
_WasmCoreClrPruneStalePerAppR2R globs the normalized _WasmPublishR2RDir and excludes the images crossgen2 emitted, taken from %(OutputR2RImage). That metadata keeps any '..' segments from IntermediateOutputPath (for example an ArtifactsPath of $(MSBuildThisFileDirectory)../artifacts), and Exclude compares the strings literally, so nothing was excluded and the target deleted the fresh images. Non-composite publishes then shipped plain IL; composite publishes failed with "No file exists for the asset". Exclude by %(FullPath) instead, and add a Wasm.Build.Tests regression test that publishes with an IntermediateOutputPath containing '..'. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the intermediate-path normalization fix and its regression coverage.
No open issues 🎉
What changed in this PR
This PR fixes CoreCLR browser-wasm publishing when intermediate paths contain .. segments, preventing stale-image cleanup from deleting freshly generated ReadyToRun images.
Changes:
- Uses normalized
FullPathmetadata to exclude current images from stale-file deletion. - Adds regression coverage for composite and non-composite publishing with an unnormalized intermediate path.
| File | Description |
|---|---|
src/mono/wasm/Wasm.Build.Tests/ReadyToRunTests.cs |
Adds a parameterized regression test verifying ReadyToRun images survive publishing. |
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets |
Normalizes exclusion paths and documents why normalization is necessary. |
Review effort: Balanced
|
/ba-g Failures are unrelated. The Windows CoreCLR browser-wasm work item Note This comment was generated with the assistance of GitHub Copilot. |
…ILLink (#137394) `ReadyToRunTests.PublishWithUnnormalizedIntermediatePathKeepsReadyToRunImages` (added in #137229) fails on every run in the CoreCLR no-workload WBT lane on Windows (for example, builds 1675602, 1675474 and 1676088): ``` Did not expect to find any .dll in ...\App\bin\Release\net12.0\publish but found ...\publish\BlazorBasicTestApp.dll, ...\publish\Microsoft.AspNetCore.Components.dll, ... ``` ## Cause `_WasmFeedReadyToRunCompileList` adds the trimmed closure again from the glob `$(IntermediateLinkDir)*.dll`. ILLink adds the same files as `$(IntermediateLinkDir)<name>`. A glob rewrites an unnormalized directory: it collapses `//`, and on Windows it flips `/` to `\`. The Helix binlog shows both spellings of each assembly: ``` App/obj/../obj/Release/net12.0\linked\Microsoft.AspNetCore.Components.Web.dll (ILLink) App\obj\..\obj\Release\net12.0\linked\Microsoft.AspNetCore.Components.Web.dll (glob) ``` `ComputeWasmPublishAssets` treats the two as duplicates, but `ResolvedFileToPublish Remove="@(_PublishResolvedFilesToRemove)"` removes only ILLink's spelling. The glob copy is then copied loose into the publish root. Composite publishes fail the same way. On Unix, MSBuild already rewrites ILLink's `linked\` property value, so the two spellings match and Linux CI passes. ## Fix Pass the glob results through the same `$(IntermediateLinkDir)%(Filename)%(Extension)` transform that ILLink uses, so both items are spelled identically. With a normalized path, the result is the same string as before. The test now also sets `IntermediateLinkDir` to `$(IntermediateOutputPath)$(TargetFramework)/linked/`, with `//` in `IntermediateOutputPath`. Because the value contains no backslash, MSBuild keeps the `//` on Unix, so the bug also reproduces on Linux and macOS, not only on Windows. ## Testing Validated on osx-arm64 after `./build.sh -s clr+libs+packs -os browser -c Release /p:BuildCrossgen2HostPackForWorkloadTesting=true`, running: ``` ./dotnet.sh build src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release -t:Test -p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:TestUsingWorkloads=false -p:XUnitMethodName=Wasm.Build.Tests.ReadyToRunTests.PublishWithUnnormalizedIntermediatePathKeepsReadyToRunImages ``` - Without the targets fix: Total 2, Failed 2, with the same message as CI. - With the fix: Total 2, Failed 0. - Whole `ReadyToRunTests` class with the fix (`-p:XUnitClassName=Wasm.Build.Tests.ReadyToRunTests`): Total 31, Failed 2. - The two failures are `PublishRunAllPages(Release, trimmed: True)` and `PublishRunAllPagesComposite(Release, trimmed: True, nativeRelink: False)`. Both report "Duplicate assemblies staged" after the incremental second publish. - Without the fix, `PublishRunAllPages(Release, trimmed: True)` fails the same way locally, and both pass on Linux CI, so these failures predate this change on macOS. The code comments were shortened after this validation; the code is the same. > [!NOTE] > This PR description was generated with the assistance of GitHub Copilot. --------- Co-authored-by: Copilot App <[email protected]>
#137360) This makes `ReadyToRunTests.PublishCrossgen2ArgumentsReflectWasmDebugInfoProperties` (added in #136506) much cheaper while keeping its coverage. ## Why The Windows Helix work item `WBT-NoWorkload-CLR-Wasm.Build.Tests` keeps hitting its 90-minute timeout. #137291 removed `-v:diag` from this test, but that only shrank the logs. On #137291's own CI (Helix job `96967939-699a-48d4-a0d9-ab808c96a280`) the work item still ran 1h34m and timed out with exit -3. In the last passing slow run (Helix job `a5e1304b-0299-470a-a3ce-9a2289a5b925`), this test's 12 cases took **1464 s**. Each case runs a full per-app or composite ReadyToRun publish (~120 s), just to read back `Crossgen2ExtraCommandLineArgs`. The flags under test (`--wasm-debug-info=*`, `--strip-inlining-info`, `--strip-debug-info`, `--opt-cross-module:*`) are all set in static `PropertyGroup`s, in `Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets` and `Microsoft.NET.CrossGen.targets`. `RunReadyToRunCompiler` receives `$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)`, and none of the targets touch these flags. In a CI binlog of the old test (Release, per-app, `DebuggerSupport=true`), the evaluated property was `;--wasm-debug-info=none;--opt-cross-module:*`. The task received `;--wasm-debug-info=none;--opt-cross-module:*;`, the same value plus the empty underscore property. ## Change - `PublishCrossgen2ArgumentsReflectWasmDebugInfoProperties` now runs `dotnet msbuild -t:Restore` and then `dotnet msbuild -getProperty:PublishReadyToRunCrossgen2ExtraArgs`, both with `-p:_IsPublishing=true` and the same project properties and `-p:` arguments, writing a binlog for each step. Restore has to be a separate invocation: MSBuild skips `-restore` when `-getProperty` runs without a target, and the WebAssembly SDK pack that sets these arguments is imported from the test's restored packages. - The 12-case matrix is unchanged. - Composite cases still pass the Crossgen2 SDK override props and targets, so both import orders are still covered. - Each case's cost drops from a full R2R publish (~120 s) to a restore plus an evaluation. The restore took ~8.7 s inside the old publishes. - `PublishRunAllPagesCore` now reads its existing publish binlog and asserts the same flags on the `RunReadyToRunCompiler` task. That covers per-app Debug, per-app Release (trimmed, untrimmed, native relink), and composite Release, so we still prove crossgen2 receives the flags, without extra publishes. Expected savings: about 20 minutes on the Windows no-workload CLR work item. That's an estimate from the timings above, not a measurement. ## Validation - `./dotnet.sh build src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release -p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:InstallWorkloadForTesting=false`: **passed** (0 warnings, 0 errors). - Repo SDK, scratch project: `dotnet msbuild -restore -getProperty:NuGetPackageRoot` produced no `obj/` and an empty value. Running `dotnet msbuild -t:Restore` first, then `dotnet msbuild -getProperty:NuGetPackageRoot -getProperty:Foo`, **returned the restored value**, and stdout contained only the JSON result. - CI on the first commit (build 1675766): - All 12 evaluation cases failed on Linux and Windows with an empty value, because restore never ran. The second commit fixes that. - The new `RunReadyToRunCompiler` assertions in `PublishRunAllPages`, `PublishRunAllPagesComposite` and `PublishRunAllPagesNativeRelink` passed on both platforms. - On Windows, `WBT-NoWorkload-CLR` finished in **1h16m**, under the 90-minute limit; the previous run timed out at 1h34m. The 12 cases took about 10 s total there. With the fix, expect roughly 2–3 more minutes for restore and evaluation. - `PublishWithUnnormalizedIntermediatePathKeepsReadyToRunImages` (Release, and Release composite) failed on Windows only: `AssertBundle` found loose `.dll` files in `publish/`. That test (#137229) doesn't use any code this PR changes, and it passed on Linux. - I did **not** run the WBT tests locally, because they need a browser-wasm CoreCLR build. The CI `WBT-NoWorkload-CLR` lanes are the real check. > [!NOTE] > This PR description was generated with GitHub Copilot. --------- Co-authored-by: Copilot App <[email protected]>
_WasmCoreClrPruneStalePerAppR2R(runsAfterTargets=_CreateR2RImages) globs$(_WasmPublishR2RDir)*.wasm;*.dlland excludes what crossgen2 just emitted, taken from%(OutputR2RImage)._WasmPublishR2RDiris normalized (NormalizeDirectory), butOutputR2RImagekeeps any..segments from$(IntermediateOutputPath).Excludecompares the strings literally, so when a project's intermediate path is unnormalized (for example,UseArtifactsOutput=truewith<ArtifactsPath>$(MSBuildThisFileDirectory)../artifacts</ArtifactsPath>), nothing is excluded and the target deletes the images it was meant to keep:error : No file exists for the asset at either location '.../R2R/<Entry>.r2r.wasm'. The component stubs survive because they're built from the normalized directory.This was found while publishing
richlander/dotnet-inspect'ssrc/DotnetInspect.Web.Fix
Exclude by
%(FullPath), which collapses..segments, so the comparison matches the normalized glob.I checked the other
OutputR2RImage-derived comparisons in the pack and inBrowserWasmApp.CoreCLR.targets. None has the same problem:ResolvedFileToPublish Removeoperations compare against the same SDK-provided strings on both sides.%(RootDir)%(Directory)checks are derived from the full path.Testing
I added
ReadyToRunTests.PublishWithUnnormalizedIntermediatePathKeepsReadyToRunImagesfor composite and non-composite publishes. It setsIntermediateOutputPathto$(MSBuildProjectDirectory)/obj/../obj/$(Configuration)/, which resolves to the default location but leaves a literal..in the path.Local run on osx-arm64, after
./build.sh -s clr+libs+packs -os browser -c Release /p:BuildCrossgen2HostPackForWorkloadTesting=true:Note
This PR was generated with the assistance of GitHub Copilot.