Visitar URL original
Invoke RunReadyToRunCompiler task for CoreLib crossgen instead of raw Exec by sbomer · Pull Request #135397 · dotnet/runtime · GitHub
Skip to content

Invoke RunReadyToRunCompiler task for CoreLib crossgen instead of raw Exec - #135397

Merged
sbomer merged 6 commits into
dotnet:mainfrom
sbomer:crossgen-corelib-task
Oct 8, 2026
Merged

sbomer merged 6 commits into
dotnet:mainfrom
sbomer:crossgen-corelib-task

Conversation

@sbomer

@sbomer sbomer commented Oct 8, 2026

Copy link
Copy Markdown
Member

Converts src/coreclr/crossgen-corelib.proj's crossgen2 invocation from a hand-built <Exec> command line to the shared RunReadyToRunCompiler MSBuild task (the same task the SDK uses for PublishReadyToRun), for both the non-composite and composite (Apple-mobile) cases.

The non-composite path was validated by diffing the task's logged command line against the original <Exec> command line — byte-identical. The composite path reuses the exact mechanism (CreateCompositeImage/ReadyToRunCompositeBuildReferences/ReadyToRunCompositeBuildInput) that PrepareForReadyToRunCompilation.cs/Microsoft.NET.CrossGen.targets already use for real composite publishing, but could not be built/tested locally (no macOS/iOS toolchain available).

Note

This content was created with assistance from AI.

sbomer and others added 4 commits October 7, 2026 17:54
… Exec

crossgen-corelib.proj previously bypassed both the dotnet/runtime and
dotnet/sdk copies of RunReadyToRunCompiler entirely, invoking crossgen2
directly via <Exec>. Route the non-composite case through the task so
CoreLib compilation uses the same code path as every other crossgen2
invocation in the SDK/repo. Flags without a dedicated task parameter
are passed through via Crossgen2ExtraCommandLineArgs, mirroring the
SDK's own escape hatch for extra args. ShowCompilerWarnings is forced
on since the task otherwise demotes "warning:" lines that <Exec> used
to surface as build warnings.

The Apple mobile composite case keeps the original <Exec> invocation,
since the task's composite parameters model a structurally different
multi-assembly build than CoreLib's single-assembly --composite usage.

Validated for linux-x64 Release: building clr.nativecorelib with the
new task-based target produces System.Private.CoreLib.dll and
.ni.r2rmap byte-for-byte identical to a freshly rebuilt <Exec>-based
baseline, reproducibly across repeated builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
--target-allows-runtime-code-generation, --embed-pgo-data,
--verify-type-and-field-layout, and --enable-cached-interface-dispatch-support
were duplicated verbatim (same flag text and same conditions) between the
composite <Exec> command-string path and the non-composite
RunReadyToRunCompiler task-parameter path. Factor them into a single
_CoreLibCrossgen2CommonExtraArgs item group computed once and consumed by
both: space-joined into the <Exec> command for composite builds, and
included in Crossgen2ExtraCommandLineArgs for the task invocation.

Verified behavior-preserving: the non-composite path's logged
RunReadyToRunCompiler invocation is textually identical before and after
this change, and a direct, repeated crossgen2 invocation with fixed inputs
confirms the tool itself produces byte-identical output for identical
arguments (regardless of flag order), so reordering within the shared
item group does not change results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Route the Apple-mobile composite path through RunReadyToRunCompiler
instead of a raw <Exec>, using the task's existing CreateCompositeImage/
ReadyToRunCompositeBuildReferences/ReadyToRunCompositeBuildInput
parameters - the same mechanism the SDK's own
PrepareForReadyToRunCompilation already uses for composite publishing in
production. This removes the remaining duplication between the two
paths, leaving a single task invocation for both.

Validated on Linux (non-composite): the generated RunReadyToRunCompiler
command line is byte-for-byte identical before and after this change.
The Apple-mobile composite path could not be built locally (no macOS/iOS
toolchain available) and relies on code-level review instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
- Remove comments that restated what the code already shows, or that
  would go stale if the referenced code changed.
- Remove a comment claiming a false in-file "convention" precedent for
  TasksConfiguration.
- Remove two Message elements that duplicated logging RunReadyToRunCompiler
  (a ToolTask) already performs itself.
- Restore the pre-existing "wasm: enable cross-module inlining/optimization"
  comment that was inadvertently dropped when that line was converted to
  item-group form.
- Tie the remaining CompilationEntry composite comment to the equivalent
  pattern in PrepareForReadyToRunCompilation.cs.

Assisted-by: Claude:claude-sonnet-5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

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

Task configuration mismatching can break mixed-configuration builds, and the unrelated WebAssembly argument changes behavior.

2 open findings
What changed in this PR

Replaces CoreLib’s hand-built crossgen2 command with the shared RunReadyToRunCompiler task.

Changes:

  • Adds and loads Crossgen2Tasks.
  • Maps existing crossgen2 options and composite inputs to task parameters.
  • Adds a WebAssembly-specific codegen option.
File Description
src/​coreclr/​crossgen-corelib.proj Migrates CoreLib crossgen2 invocation to the shared task.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread src/coreclr/crossgen-corelib.proj Outdated
Comment thread src/coreclr/crossgen-corelib.proj Outdated
sbomer and others added 2 commits October 8, 2026 08:51
Qualify the invocation to match the local task registration rather than the SDK short-name task, which forces non-composite Wasm compilation into composite mode.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6c955c02-ee60-478e-8eaf-4222723f5886
Build the new task reference in TasksConfiguration to match the loaded assembly, and remove the obsolete Wasm codegen option introduced by the conversion.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6c955c02-ee60-478e-8eaf-4222723f5886

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.

🔵 Needs a closer look

The Apple-mobile composite path changes critical build behavior without platform validation.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@sbomer

sbomer commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@jkoritzinsky @davidwrighton I'm planning to make some changes to the crossgen task (for caching) and this should ensure that we exercise the task path for corelib.

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to mourn that we no longer print out the command line for R2Ring System.Private.CoreLib.dll as part of the build log, but I can learn to live with that if it reduces build costs.

@jkotas

jkotas commented Oct 8, 2026

Copy link
Copy Markdown
Member

I'm going to mourn that we no longer print out the command line for R2Ring System.Private.CoreLib.dll as part of the build log, but I can learn to live with that if it reduces build costs.

Can the task print that?

@davidwrighton

Copy link
Copy Markdown
Member

Its in the binlog, so we do log it... just only at higher verbosity levels which makes sense for the customer scenarios. I suppose we could add a flag to the task to make it log to a lower verbosity level.

@jkotas

jkotas commented Oct 8, 2026

Copy link
Copy Markdown
Member

just only at higher verbosity levels

Ok, that's good enough.

@sbomer
sbomer merged commit 3c40b2b into dotnet:main Oct 8, 2026
113 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants