Skip to content

[TrimmableTypeMap] Fix trimmable typemap single-RID release builds#11499

Open
simonrozsival wants to merge 9 commits into
dev/simonrozsival/trimmable-framework-rootsfrom
dev/simonrozsival/trimmable-single-rid-build
Open

[TrimmableTypeMap] Fix trimmable typemap single-RID release builds#11499
simonrozsival wants to merge 9 commits into
dev/simonrozsival/trimmable-framework-rootsfrom
dev/simonrozsival/trimmable-single-rid-build

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented May 26, 2026

Splits the single-RID build fix out of #11346.

This PR is stacked on #11498 and includes the post-trim trimmable typemap scan/R8 input fixes plus coded task errors.

simonrozsival and others added 8 commits May 26, 2026 06:58
Add a Release CoreCLR HelloWorld comparison test that builds llvm-ir and trimmable typemap APKs, prints managed and dex diagnostics, and asserts the trimmable typemap does not retain extra typemap-eligible managed or Java entries.

Pass all generated typemap assemblies to ILLink as typemap entry assemblies and mark them trimmable so conditional typemap entries are honored.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Generate proguard keep rules for the CoreCLR trimmable typemap path from the linked assemblies, matching the llvm-ir path, and make the APK comparison test use R8 so dex contents are actually shrunk.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Limit --typemap-entry-assembly arguments to generated per-assembly *.TypeMap.dll assemblies that contain TypeMapAttribute entries, instead of treating the root typemap loader assembly as an entry assembly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep SDK framework ACWs conditional unless they are explicitly rooted, and pass framework assembly names through trimmable typemap generation. This allows Mono.Android implementor entries to be trimmed while preserving app ACWs and scanner-rooted components.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Emit array typemap sentinels when dynamic code support is explicitly disabled so CoreCLR trimmable typemap builds can use the no-dynamic-code array path. Keep DynamicCodeSupport enabled by default and cover the explicit opt-out path in tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the APK comparison test scaffolding from this split branch while keeping the DynamicCodeSupport coverage for trimmable typemaps.
Scan linked assemblies after ILLink to filter generated Java wrappers and acw-map inputs before R8, while packaging only linked typemap assemblies for single-RID builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 26, 2026 05:04
@simonrozsival simonrozsival changed the title Fix trimmable typemap single-RID release builds [TrimmableTypeMap] Fix trimmable typemap single-RID release builds May 26, 2026
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

This PR fixes CoreCLR Release builds using the trimmable typemap when building with a single RuntimeIdentifier, ensuring that packaging/R8 inputs are based on the linked (post-ILLink) view of the app rather than unlinked typemap artifacts. It also adds dedicated XA42xx coded errors and documentation for new failure modes, plus a regression test covering the single-RID scenario.

Changes:

  • Add a Release CoreCLR single-RID regression test to ensure unlinked typemap assemblies are not packaged and post-trim R8 inputs exclude dead framework implementors.
  • Extend GenerateTrimmableTypeMap to optionally skip typemap assembly generation, clean Java output directories safely, and copy Java sources from a pre-trim directory (with XA4254/XA4255 errors).
  • Update trimmable typemap MSBuild targets to support post-trim Java/acw-map regeneration and to locate linked typemap DLLs for both single- and multi-RID layouts.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs Adds end-to-end Release CoreCLR single-RID test and APK/DEX assertions.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs Adds post-trim Java source copy mode, output cleanup, and XA4254/XA4255 errors.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds XA4254/XA4255 messages.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Regenerates strongly-typed resources for XA4254/XA4255.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets Introduces post-trim Java output/stamp properties for CoreCLR PublishTrimmed flows.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.CoreCLR.targets Adds post-trim typemap scan target and fixes linked typemap DLL discovery for single-RID builds.
src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs Allows skipping typemap assembly generation while still producing peer scan results/Java source lists.
Documentation/docs-mobile/messages/xa4254.md Documents XA4254.
Documentation/docs-mobile/messages/xa4255.md Documents XA4255.
Documentation/docs-mobile/messages/xa4253.md Fixes code block formatting.
Documentation/docs-mobile/messages/index.md Adds XA4254/XA4255 entries to the message index.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

Comment on lines +28 to +32
<_TypeMapJavaStubsSourceDirectory Condition=" '$(_TypeMapJavaStubsSourceDirectory)' == '' and '$(_AndroidRuntime)' == 'CoreCLR' and '$(PublishTrimmed)' == 'true' ">$(_PostTrimTypeMapJavaOutputDirectory)</_TypeMapJavaStubsSourceDirectory>
<_TypeMapJavaStubsSourceDirectory Condition=" '$(_TypeMapJavaStubsSourceDirectory)' == '' ">$(_TypeMapJavaOutputDirectory)</_TypeMapJavaStubsSourceDirectory>
<_PostTrimTrimmableTypeMapJavaStamp>$(_TypeMapBaseOutputDir)stamp/_GeneratePostTrimTrimmableTypeMapJavaSources.stamp</_PostTrimTrimmableTypeMapJavaStamp>
<_TrimmableJavaSourceStamp Condition=" '$(_TrimmableJavaSourceStamp)' == '' and '$(_AndroidRuntime)' == 'CoreCLR' and '$(PublishTrimmed)' == 'true' ">$(_PostTrimTrimmableTypeMapJavaStamp)</_TrimmableJavaSourceStamp>
<_TrimmableJavaSourceStamp Condition=" '$(_TrimmableJavaSourceStamp)' == '' ">$(_TypeMapOutputDirectory)$(_TypeMapAssemblyName).dll</_TrimmableJavaSourceStamp>
@simonrozsival simonrozsival added copilot `copilot-cli` or other AIs were used to author this trimmable-type-map labels May 26, 2026
Copy Java stubs from the selected typemap source directory so CoreCLR trimmed builds use the post-link source set instead of stale pre-trim Java files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival

This comment was marked as low quality.

@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-framework-roots branch from ac57cc4 to 2c25481 Compare May 27, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants