Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coreclr] Enable R2R builds #10007

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

ivanpovazan
Copy link
Member

@ivanpovazan ivanpovazan commented Apr 4, 2025

Description

ReadyToRun deployments are enabled when:

  1. <PublishReadyToRun>true</PublishReadyToRun> is added to the project file
  2. App is published via: dotnet publish

Once enabled, the SDK injects necessary build tasks to perform AOT compilation of assemblies after their trimming and creation of R2R images during app publish.

Problem

Currently, Android app build runs two assembly postprocessing build tasks (after R2R image generation): RewriteMarshalMethods and RemoveRegisterAttribute that are modifying assemblies with Mono.Cecil. However, altering R2R assemblies is not supported with Mono.Cecil and build fails via:

System.NotSupportedException: Writing mixed-mode assemblies is not supported
         at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
         at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
         at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
         at Mono.Cecil.ModuleDefinition.Write(WriterParameters parameters)
         at Mono.Cecil.ModuleDefinition.Write()
         at Mono.Cecil.AssemblyDefinition.Write()
         at Xamarin.Android.Tasks.RemoveRegisterAttribute.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/RemoveRegisterAtt
      ribute.cs:line 37
         at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.
      BaseTasks/AndroidTask.cs:line 25

Changes

To enable R2R builds, this PR:

  • disables running RewriteMarshalMethods and RemoveRegisterAttribute build tasks in ReadyToRun deployments
  • adds new unit tests for R2R builds
  • reenables unit tests for regular CoreCLR builds

Future work

Investigate running R2R image generation build task after RewriteMarshalMethods and RemoveRegisterAttribute so that R2R builds could also benefit from the performance improvements these build tasks bring.

@ivanpovazan ivanpovazan changed the title WIP: [coreclr] Enable R2R builds [coreclr] Enable R2R builds Apr 7, 2025
@ivanpovazan ivanpovazan marked this pull request as ready for review April 7, 2025 08:33
@ivanpovazan ivanpovazan requested a review from grendello April 8, 2025 10:53
@grendello
Copy link
Contributor

I think I'd rather wait with merging this PR until marshal methods can be used again. Maybe it's a simple matter of ordering? R2R should be called, like Mono AOT, after we're done modifying the assemblies.

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