Skip to content

Track additional ReadyToRun compiler outputs for incremental builds - #57255

Merged
davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:r2r-additional-outputs
Nov 23, 2026
Merged

davidwrighton merged 1 commit into
dotnet:mainfrom
davidwrighton:r2r-additional-outputs

Conversation

@davidwrighton

@davidwrighton davidwrighton commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

_CreateR2RImages currently lists only OutputR2RImage and OutputPDBImage as outputs. A composite compilation also writes one rewritten component file per input (PE/Mach-O component assemblies, or .wasm component stubs). If one of those files is deleted or becomes stale, the target is still considered up to date. Publish then fails, or it copies an outdated component.

This PR adds an AdditionalOutputs metadata contract to _ReadyToRunCompileList:

  • AdditionalOutputs is a semicolon-separated list of files the compiler produces besides OutputR2RImage and OutputPDBImage. _CreateR2RImages now uses Outputs="%(OutputR2RImage);%(OutputPDBImage);%(AdditionalOutputs)". Batching splits the list, so incrementality stays per entry: deleting or aging a single extra output recompiles only that entry.
  • PrepareForReadyToRunCompilation fills it in for the composite entry from the same component paths it already uses to build ReadyToRunFilesToPublish, so the outputs and the published files come from one source of truth.
  • Extension point: targets that change which files crossgen2 emits, typically through extra compiler arguments, can update the metadata after _PrepareForReadyToRunCompilation. Planned crossgen2 output-layout changes then only need a metadata update in the task or in the extending targets, not a new target or a workaround. For example:
<_ReadyToRunCompileList Update="@(_ReadyToRunCompileList)" Condition="'%(CreateCompositeImage)' == 'true'"
                        AdditionalOutputs="$(_MyBundlePath)" />

Motivation

dotnet/runtime#137713 makes crossgen2 bundle composite WebCIL components into a single <app>.components.wasm file for browser CoreCLR. That file was not a tracked output, so the runtime targets temporarily deleted the composite owner image to force a recompile when the bundle was missing. That workaround has now been removed; this PR models the extra output directly. The review comment at dotnet/runtime#137713 (comment) asked for the output to be modeled properly in the SDK instead.

Merge sequencing

  1. This PR (dotnet/sdk). The change is additive. Existing targets that do not set the metadata behave as before, while composite publishes also track their component files.
  2. dotnet/runtime. Port the same task and target change to src/tasks/Crossgen2Tasks, which must stay equivalent to the SDK copy, and set AdditionalOutputs to the bundle path in Browser.CoreCLR.targets. Remove the owner-image invalidation workaround. These runtime changes do not need to wait for the SDK version to flow into runtime's global.json: the in-tree path uses the shim.
  3. SDK flow. Once the updated SDK reaches runtime's pinned SDK version, the explicit stock-SDK test path will also honor AdditionalOutputs. Until then, that opt-in path will not rebuild solely because a bundle is missing; the bundle has not shipped, so this temporary gap is accepted. Do not retain or restore the owner-deletion workaround for this transition.

No capability flag is needed. Older SDKs ignore AdditionalOutputs; newer SDKs use it for incremental tracking.

Validation

  • ./build.sh: succeeded.
  • ./.dotnet/dotnet scripts/RunTests.cs -- --project test/Microsoft.NET.Build.Tasks.Tests/Microsoft.NET.Build.Tasks.Tests.csproj --filter "FullyQualifiedName~GivenAPrepareForReadyToRunCompilation": passed, 5/5. This includes new AdditionalOutputs assertions for Mach-O and wasm composite planning.
  • ./.dotnet/dotnet scripts/RunTests.cs -- --project test/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj --filter "FullyQualifiedName~It_recompiles_composite_image_when_a_component_output_is_missing|FullyQualifiedName~It_recompiles_readytorun_images_when_crossgen2_arguments_change|FullyQualifiedName~It_can_publish_readytorun_composite_with_subdirectory_relative_path": passed, 3/3. The new test deletes a composite component and confirms the next publish recompiles it.

The suite ran before a final cleanup that removed only an unused private property; it was not re-run after that change. The new publish test has not been confirmed to fail without the target change.

Note

This PR description was drafted with GitHub Copilot.

Add AdditionalOutputs metadata to _ReadyToRunCompileList entries listing files
crossgen2 writes besides OutputR2RImage and OutputPDBImage, and include it in
the _CreateR2RImages Outputs. Composite entries list their rewritten component
files, so a missing or stale component recompiles the composite image.
Targets that change the set of files crossgen2 emits can update the metadata.

Co-authored-by: Copilot <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

When composite roots are configured, unrooted assembly changes can leave stale published components, and incremental tests for those changes and overridden outputs are missing.

2 open issues
What changed in this PR

This PR extends the SDK’s ReadyToRun output tracking so missing or outdated composite component files can trigger recompilation. It also provides an extension point for the browser component bundle planned in dotnet/runtime#137713.

Changes:

  • Adds AdditionalOutputs metadata to compiler planning and MSBuild incremental output checks.
  • Derives composite output paths from the files already selected for publishing.
  • Adds task-level metadata assertions and a publish regression test for a deleted component.
File Description
test/​Microsoft.NET.Publish.Tests/​GivenThatWeWantToPublishReadyToRun.cs Tests recompilation after deleting a composite component.
test/​Microsoft.NET.Build.Tasks.Tests/​GivenAPrepareForReadyToRunCompilation.cs Checks additional output paths for Mach-O and WebAssembly composites.
src/​Tasks/​Microsoft.NET.Build.Tasks/​targets/​Microsoft.NET.CrossGen.targets Tracks additional compiler outputs and documents metadata overrides.
src/​Tasks/​Microsoft.NET.Build.Tasks/​PrepareForReadyToRunCompilation.cs Populates composite entries with component output paths.
src/​Tasks/​Common/​MetadataKeys.cs Defines the AdditionalOutputs metadata key.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 5493fb09 Deployed Nov 23, 2026 by davidwrighton via pat_pool #15703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants