Fix XALNS7015: run FixAbstractMethodsStep before R2R in non-trimmed CoreCLR builds#11027
Draft
simonrozsival wants to merge 1 commit intomainfrom
Draft
Fix XALNS7015: run FixAbstractMethodsStep before R2R in non-trimmed CoreCLR builds#11027simonrozsival wants to merge 1 commit intomainfrom
simonrozsival wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the CoreCLR Release (non-trimmed) PublishReadyToRun=true build failure where FixAbstractMethodsStep tries to rewrite an already-R2R’d assembly and Mono.Cecil throws NotSupportedException for mixed-mode output.
Changes:
- Run
PostTrimmingPipelinebefore crossgen2/ReadyToRun for both trimmed and non-trimmedPublishReadyToRunbuilds, enablingFixAbstractMethodsonly in the non-trimmed path. - Update
PostTrimmingPipelineto optionally includeFixAbstractMethodsStepand mark processed assemblies as Android/user assemblies inStepContext. - Re-enable previously ignored CoreCLR test cases and add a unit regression test for
FixAbstractMethodsbehavior viaPostTrimmingPipeline.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/LinkerTests.cs | Adds a regression unit test validating PostTrimmingPipeline can inject a missing abstract-method stub. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs | Removes the CoreCLR non-trimmed ignore workaround now that the pipeline should run pre-R2R. |
| src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs | Adds FixAbstractMethods support and updates StepContext flags so FixAbstractMethodsStep can run. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.LlvmIr.targets | Extends _PostTrimmingPipeline to also run for non-trimmed R2R builds and wires FixAbstractMethods into the task call. |
...droid.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.LlvmIr.targets
Outdated
Show resolved
Hide resolved
...droid.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.LlvmIr.targets
Outdated
Show resolved
Hide resolved
Member
Author
|
Replying to the Copilot review comments — the implementation was reworked in commits 3-4, so all four comments are now outdated. Resolving them below. |
…CoreCLR builds In non-trimmed CoreCLR Release builds, PublishReadyToRun=true causes the inner build to compile IL assemblies to R2R images (via crossgen2) before _LinkAssembliesNoShrink runs. R2R assemblies have the ILONLY PE flag cleared, so when FixAbstractMethodsStep detects a missing abstract method and marks the assembly modified, SaveChangedAssemblyStep calls assembly.Write() via Mono.Cecil, which throws: NotSupportedException: Writing mixed-mode assemblies is not supported The fix restructures _LinkAssembliesNoShrink to run inside the inner build (BeforeTargets=_PrepareForReadyToRunCompilation) so assembly modifications happen before R2R compilation: - Xamarin.Android.Common.targets: Rewrite _LinkAssembliesNoShrink to run in the inner build. It copies assemblies to an intermediate directory (linked-noshrink/) instead of modifying in-place, since ResolvedFileToPublish items may point to shared locations (NuGet cache, runtime packs). After the task runs, ResolvedFileToPublish is updated to point to the intermediate copies. Abi metadata is computed via RuntimeIdentifierToAbi since _ResolveAndroidTooling doesn't run in the inner build. - Microsoft.Android.Sdk.AssemblyResolution.targets: In _PrepareAssemblies, populate _ResolvedAssemblies unconditionally from @(ResolvedAssemblies) instead of redirecting through the intermediate directory for non-trimmed builds. - Remove Assert.Ignore workarounds in BuildTest and LinkerTests for the CoreCLR Release non-trimmed case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5e65810 to
6469db8
Compare
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.
Summary
Fixes #11025
In non-trimmed CoreCLR Release builds,
PublishReadyToRun=truecauses the inner build to compile IL assemblies to R2R images (via crossgen2) before_LinkAssembliesNoShrinkruns. R2R assemblies have the ILONLY PE flag cleared, so whenFixAbstractMethodsStepdetects a missing abstract method and marks the assembly modified,SaveChangedAssemblyStepcallsassembly.Write()via Mono.Cecil, which throws:Changes
Fix: move
_LinkAssembliesNoShrinkto run before R2R compilation in the inner buildThe previous
_LinkAssembliesNoShrinktarget ran in the outer build using@(ResolvedAssemblies)and copied modified assemblies to an intermediate directory. This happened too late — the inner build had already produced R2R images by that point.The fix restructures
_LinkAssembliesNoShrinkto run inside the inner build (BeforeTargets="_PrepareForReadyToRunCompilation"):Xamarin.Android.Common.targets: Rewrite_LinkAssembliesNoShrinkto run in the inner build when trimming is disabled. It operates on@(ResolvedFileToPublish)(available in the inner build) instead of@(ResolvedAssemblies)(outer build only). Assemblies are copied to an intermediate directory (linked-noshrink/) rather than modified in-place, sinceResolvedFileToPublishitems may point to shared locations (NuGet cache, runtime packs). After the task runs,ResolvedFileToPublishis updated so R2R and publish consume the modified copies. ABI metadata is computed viaRuntimeIdentifierToAbisince_ResolveAndroidToolingdoes not run in the inner build.Microsoft.Android.Sdk.AssemblyResolution.targets: In_PrepareAssemblies, populate_ResolvedAssembliesetc. unconditionally from@(ResolvedAssemblies)(no longer redirecting through the intermediate directory for non-trimmed builds).Tests
Assert.Ignoreworkarounds inBuildTest.SimilarAndroidXAssemblyNamesandLinkerTests.AndroidAddKeepAlivesfor the CoreCLR Release non-trimmed case — these scenarios now pass.Related