Compare trimmable typemap APK contents#11346
Draft
simonrozsival wants to merge 6 commits into
Draft
Conversation
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>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens trimmable typemap validation and updates CoreCLR ILLink integration so generated typemap assemblies participate in trimming and typemap entry discovery.
Changes:
- Adds a Release CoreCLR APK comparison test between
llvm-irandtrimmabletypemap modes. - Parses assembly-store and DEX contents to compare managed/Java typemap-retained entries.
- Updates trimmable CoreCLR targets to mark generated typemap DLLs trimmable and pass them to ILLink.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs |
Adds APK profiling/comparison helpers and a new Release CoreCLR typemap retention test. |
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.CoreCLR.targets |
Updates ILLink inputs/arguments for generated trimmable typemap assemblies. |
Comment on lines
25
to
+28
| <Target Name="_ConfigureTrimmableTypeMapForLinker" | ||
| BeforeTargets="PrepareForILLink;_RunILLink" | ||
| DependsOnTargets="_GenerateTrimmableTypeMap"> | ||
| <ItemGroup> |
| <Target Name="_ConfigureTrimmableTypeMapForLinker" | ||
| BeforeTargets="PrepareForILLink;_RunILLink" | ||
| DependsOnTargets="_GenerateTrimmableTypeMap"> | ||
| <ItemGroup> |
|
|
||
| var javaName = fields [1].Trim (); | ||
| if (!IsTypemapHelperJavaType (javaName)) { | ||
| profile.CandidateJavaNames.Add (javaName); |
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>
Generate R8 keep rules for trimmable typemap builds from linked assemblies instead of the pre-link acw-map, and use a minimal Xamarin runtime keep list for this path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 44d8c10.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #11345.
This PR adds an end-to-end Release CoreCLR HelloWorld APK comparison between
_AndroidTypeMapImplementation=llvm-irandtrimmable, usingTrimMode=fullandAndroidLinkTool=r8. The test reads assembly-store contents, dex contents, generated Java sources, and typemap metadata, then asserts the trimmable path does not retain extra typemap-eligible managed or Java entries.It also fixes the trimmable CoreCLR linker/R8 integration:
*.TypeMap.dllassemblies to ILLink with--typemap-entry-assembly, because the actualTypeMapAttributeentries live there.Latest R8-backed comparison
Per-dex contents
Detailed counts
__md_methodsfilesRuntime.registerfilesRuntime.registerNativesfilesMinimal ProGuard experiment
A follow-up experiment reduced trimmable
classes.dexto 13,008 bytes / 20 classes, but device validation showed the APK did not run: launchingMainActivitycrashed withUnsatisfiedLinkErrorforMainActivity.nctor_0(). That experiment was reverted inadc8960d6, so this PR currently keeps the runtime-safe R8 configuration shown above.Typemap metadata checks
Generated typemap assemblies now show no duplicate
TypeMapAttributekeys. The_Mono.Android.TypeMap.dllunconditional count dropped from 332 to 13 after making framework ACWs conditional by default._TypemapComparison.TypeMap.dll_Microsoft.Android.TypeMaps.dll_Mono.Android.TypeMap.dll_Java.Interop.TypeMap.dll_Microsoft.Android.TypeMaps.dllalso has 3TypeMapAssemblyTargetAttributeentries. The earlier44number is not a typemap-entry count; it is the final packaged registered managed type count after filtering helper/runtime plumbing.Validation
dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj --no-restore --nologoMSBUILDDISABLENODEREUSE=1 dotnet build src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj --no-restore --no-dependencies --nologo -p:Configuration=Debug -nr:false -m:1 -p:BuildInParallel=falseMSBUILDDISABLENODEREUSE=1 ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter Name~ReleaseCoreClrTrimmableTypeMap_DoesNotKeepMoreTypemapPeersThanLlvmIr./dotnet-local.sh test bin/TestDebug/net11.0/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests.dll --nologogit diff --check