Skip to content

[TrimmableTypeMap] Remove post-trim generation pass#11604

Open
simonrozsival wants to merge 1 commit into
mainfrom
android-remove-second-generatetrimmabletypemap
Open

[TrimmableTypeMap] Remove post-trim generation pass#11604
simonrozsival wants to merge 1 commit into
mainfrom
android-remove-second-generatetrimmabletypemap

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented Jun 8, 2026

Summary

This PR partially backs out #11499, but intentionally keeps the part that fixed single-RID CoreCLR packaging.

#11499 mixed two separate changes:

Area from #11499 / follow-up cleanup What this PR does
CoreCLR post-trim _GeneratePostTrimTrimmableTypeMapJavaSources target Removes it
Second GenerateTrimmableTypeMap invocation after ILLink Removes it
Task/generator switches used only by that second pass (JavaSourceInputDirectory, GenerateTypeMapAssemblies=false, CleanJavaSourceOutputDirectory, generateTypeMapAssemblies) Removes them
typemap/linked-java Java source copy/filtering path Removes it
XA4254/XA4255 docs/resources for the deleted Java copy path Removes them
R8/acw-map post-trim assertions from the regression test Removes/defer them to the separate R8 follow-up
Single-RID linked typemap assemblies added to ResolvedFileToPublish Keeps it
ReadyToRun typemap assemblies replacing linked typemap assemblies for publish Keeps it
Regression coverage that the APK packages linked/R2R typemap assemblies Keeps it
Stale typemap/java/**/*.java outputs after the post-trim pass removal Reconciles stale generated Java sources when the whole-world typemap generation target reruns, deletes matching stale android/src copies, and includes typemap/ in intermediate clean

The conceptual fix is: the trimmable typemap should be generated once before trimming and then reused. Running GenerateTrimmableTypeMap again after trimming invalidates the cache and defeats the point of the trimmable typemap design.

The Java-source cleanup is intentionally scoped to the current whole-world generator model: when _GenerateTrimmableTypeMap runs, the task has the full current desired Java source set, so files under typemap/java that were not emitted by that pass are stale and can be deleted. No-op incremental builds where _GenerateTrimmableTypeMap is skipped do not clean that directory.

The future per-assembly incremental split is tracked separately by #11494; that design will need a more explicit Java-output ownership/reconciliation model before this can become partial per assembly.

Are single-RID builds still fixed?

Yes. The single-RID fix from #11499 is still present: _AddTrimmableTypeMapToResolvedFileToPublish adds linked typemap assemblies to the publish pipeline, and _UseReadyToRunTrimmableTypeMapAssembliesForPublish swaps in R2R typemap assemblies when applicable.

The retained regression test builds a trimmable CoreCLR single-RID APK (RuntimeIdentifier=android-arm64, TrimMode=full, AndroidLinkTool=r8) and verifies the APK packages the linked/R2R typemap assemblies instead of stale pre-link typemap assemblies.

Validation

Previous validation:

  • make prepare
  • ./dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj -c Debug -v:minimal
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter "Name=ReleaseCoreClrTrimmableTypeMap_SingleRuntimeIdentifier_PackagesLinkedOrReadyToRunTypeMapAssemblies"

Latest cleanup update:

  • git diff --check
  • Added regression coverage:
    • Execute_DeletesStaleGeneratedJavaSources
    • Build_WithTrimmableTypeMap_DeletesStaleGeneratedJavaSourcesAndCopies

Note: local make all still fails in unrelated Java.Interop CMake setup because clang++ cannot link libc++ (ld: library 'c++' not found).

Generate the trimmable typemap once before trimming and reuse the generated Java sources instead of running GenerateTrimmableTypeMap again after ILLink. Keep the linked/R2R typemap assembly packaging path from the previous fix, and remove diagnostics that only supported the deleted post-trim Java copy path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@simonrozsival simonrozsival marked this pull request as ready for review June 8, 2026 11:16
Copilot AI review requested due to automatic review settings June 8, 2026 11:16
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 removes the “post-trim” TrimmableTypeMap Java generation/copy pass (and its associated task switches + error codes/docs), returning to a single pre-trim typemap generation model while keeping the previously-added single-RID CoreCLR packaging fix and its regression coverage.

Changes:

  • Removed the CoreCLR post-trim _GeneratePostTrimTrimmableTypeMapJavaSources target and the second typemap generation pass after ILLink.
  • Simplified GenerateTrimmableTypeMap + TrimmableTypeMapGenerator by removing the “copy from input dir”/“skip assembly generation” modes and associated XA4254/XA4255 resources + docs.
  • Updated the regression test to focus on verifying the APK packages the linked/R2R typemap assemblies (dropping the post-trim R8/acw-map assertions).
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs Removes post-trim R8/acw-map assertions from the single-RID trimmable CoreCLR packaging regression test.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs Removes post-trim copy/clean switches and always writes typemap assemblies + Java sources in a single mode.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Removes XA4254/XA4255 resource strings tied to the deleted post-trim Java copy path.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Removes the generated accessors for XA4254/XA4255.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.targets Removes linked-java path plumbing; always uses the pre-trim typemap Java output directory for stub copying.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.Trimmable.CoreCLR.targets Deletes the post-trim typemap Java generation target that ran after ILLink.
src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs Removes the optional “skip typemap assemblies” mode; generator always produces typemap assemblies.
Documentation/docs-mobile/messages/xa4254.md Deletes docs for XA4254, now that the code path is removed.
Documentation/docs-mobile/messages/xa4255.md Deletes docs for XA4255, now that the code path is removed.
Documentation/docs-mobile/messages/index.md Removes XA4254/XA4255 from the error code index.

Copilot's findings

Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported
  • Files reviewed: 9/10 changed files
  • Comments generated: 1

Comment on lines 120 to 121
Directory.CreateDirectory (OutputDirectory);
if (CleanJavaSourceOutputDirectory && Directory.Exists (JavaSourceOutputDirectory)) {
Directory.Delete (JavaSourceOutputDirectory, recursive: true);
}
Directory.CreateDirectory (JavaSourceOutputDirectory);
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