Skip to content

Add MIBC profile generator for InitializeComponent methods#34837

Open
jkoritzinsky wants to merge 6 commits intomainfrom
feature/mibc-profile-generator
Open

Add MIBC profile generator for InitializeComponent methods#34837
jkoritzinsky wants to merge 6 commits intomainfrom
feature/mibc-profile-generator

Conversation

@jkoritzinsky
Copy link
Copy Markdown
Member

@jkoritzinsky jkoritzinsky commented Apr 6, 2026

Summary

Adds a build tool that generates MIBC (Managed Instrumented Binary Code) profile files listing all InitializeComponent* methods from compiled MAUI assemblies. These files do not have any actual profile data, but they can be consumed by crossgen2 for partial compilation. Also add MSBuild targets to enable partial R2R for just XAML-generated code when the .NET for iOS SDK is enabling their partial R2R support.

What's included

MibcProfileGenerator tool (src/Controls/src/Build.Tasks/MibcProfileGenerator/)

A standalone .NET console app that:

  • Reads one or more input assemblies using \System.Reflection.Metadata\
  • Discovers all XAML-generated method variants:
    • InitializeComponent — primary entry point
    • InitializeComponentRuntime — runtime XAML inflation
    • InitializeComponentXamlC — XamlC IL-compiled path
    • InitializeComponentSourceGen — source generator compiled path
  • Emits a valid MIBC PE assembly following the format from dotnet/runtime's MibcEmitter.cs
  • Supports both compressed (.mibc) and uncompressed (.dll) output
  • Handles nested types, multiple assemblies, and proper metadata references
  • Validated with dotnet-pgo dump

MSBuild integration

  • New opt-in target _MauiGenerateMibcProfile in Microsoft.Maui.Controls.targets
  • Runs after _SelectUserAssemblies so it can see all user assemblies that may have XAML in the application.
  • Incremental build support via Inputs/Outputs

Packaging

  • Tool is packaged alongside existing build tasks in the NuGet package
  • Local dev support via _CopyToBuildTasksDir target

Usage

Enabled in .NET for iOS Debug builds when targeting CoreCLR.

Supersedes #34660 so CI can run

jkoritzinsky and others added 4 commits March 31, 2026 11:53
Add a build tool that scans compiled MAUI assemblies for all
InitializeComponent* methods (InitializeComponent, InitializeComponentRuntime,
InitializeComponentXamlC, InitializeComponentSourceGen) and produces a MIBC
profile file consumable by crossgen2 and the .NET AOT compiler for PGO.

The tool is integrated into the MSBuild pipeline via the
_MauiGenerateMibcProfile target, which runs after XamlC and is opt-in
via the MauiGenerateMibcProfile property. The generated file is exposed
as the @(MauiMibcProfile) MSBuild item for downstream consumption.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add explicit ret instructions to group and AssemblyDictionary IL methods
- Fix nested type namespace resolution (walk to outermost declaring type)
- Include deps.json in NuGet package and local dev copy
- Fix comment to match actual property/item names
- Fix indentation to use tabs consistently in targets file

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cios repo and use item groups from dotnet/sdk#53635 to enable partial generation
Copilot AI review requested due to automatic review settings April 6, 2026 22:21
@jkoritzinsky jkoritzinsky changed the title Feature/mibc profile generator Add MIBC profile generator for InitializeComponent methods Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34837

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34837"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an MSBuild-integrated tool to generate MIBC profile files containing MAUI InitializeComponent* methods, enabling partial ReadyToRun (R2R) compilation for XAML-generated code paths (notably for CoreCLR Debug scenarios).

Changes:

  • Introduces MibcProfileGenerator, a console tool that scans assemblies via System.Reflection.Metadata and emits a MIBC PE (optionally compressed).
  • Adds an opt-in MSBuild target (_MauiGenerateMibcProfile) to generate the profile and wire it into PublishReadyToRun* items.
  • Packages the tool alongside existing build tasks and hooks it into the build tasks project/pack output.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets Adds _MauiGenerateMibcProfile target and R2R/PGO item wiring.
src/Controls/src/Build.Tasks/MibcProfileGenerator/Program.cs New implementation for discovering InitializeComponent* methods and emitting MIBC output.
src/Controls/src/Build.Tasks/MibcProfileGenerator/MibcProfileGenerator.csproj New net10.0 tool project and local dev copy target.
src/Controls/src/Build.Tasks/Controls.Build.Tasks.csproj References/packaging updates to include the tool in the build tasks NuGet output.

Comment thread src/Controls/src/Build.Tasks/MibcProfileGenerator/Program.cs
Comment thread src/Controls/src/Build.Tasks/MibcProfileGenerator/Program.cs Outdated
Comment thread src/Controls/src/Build.Tasks/MibcProfileGenerator/Program.cs Outdated
jkoritzinsky and others added 2 commits April 6, 2026 15:39
- Fix MVID write ordering: write GUID before Serialize() so it's included in output
- Key assembly references by full identity (name+version+pkt) not just simple name
- Add MauiXaml condition to skip non-XAML projects
- Fix comment: 'method names' not 'method name prefixes' (exact matching)
- Fix comment: describe actual enabling mechanism (FilterReadyToRunAssemblies)
- Fix indentation in targets file ItemGroup (tabs not spaces)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add response file (@file) support to MibcProfileGenerator tool
- Restructure targets into wrapper + write-rsp + run-tool pattern
- Use WriteOnlyWhenDifferent for incremental build correctness
- Pass all PublishReadyToRunExclude assemblies to the generator
- Move all excluded assemblies to partial R2R after generation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants