Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Apr 21, 2025

Context: #10062

One issue with our desire to move around LLVM Marshal Method build code so that it can work with Ready2Run is that our current implementation relies on holding Cecil AssemblyDefinition objects open in global state across multiple targets. While these objects are open, no other process can access our assemblies, making it harder to reorder targets and tasks.

As a first step towards refactoring this process, let's move the data into a DTO that does not require Cecil. Additionally, this makes it clear what data is actually consumed by <GeneratePackageManagerJava> rather than "entire assemblies" so we can focus on how to properly obtain and persist the data.

This still relies on BuildEngine4.RegisterTaskObject to store the data, but a likely future step would be to persist it to a file instead.

@jpobst jpobst force-pushed the dev/jpobst/marshal-method-task-object branch from 54c9784 to ed7e870 Compare April 22, 2025 20:08
@jpobst jpobst force-pushed the dev/jpobst/marshal-method-task-object branch from ed7e870 to dfec04a Compare April 22, 2025 22:33
@jpobst jpobst marked this pull request as ready for review April 23, 2025 18:30
@jpobst jpobst requested review from Copilot and jonpryor April 23, 2025 18:30
Copy link

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 pull request refactors the way marshal method data is stored by converting the Cecil-dependent NativeCodeGenState into Cecil‐less DTOs, improving task decoupling and assembly access.

  • Updated various classes and method signatures in MarshalMethodsNativeAssemblyGenerator.cs to work with the new DTO types.
  • Introduced MarshalMethodCecilAdapter.cs to convert Cecil objects into DTOs and updated related build task registrations in GeneratePackageManagerJava.cs and GenerateMainAndroidManifest.cs.
  • Defined a new task constant in GenerateJavaStubs.cs to support the DTO-based state transfer.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs Updated method signatures and type references to use DTO types instead of Cecil objects.
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodCecilAdapter.cs Added adapter methods to create DTOs; note issues with dictionary initializers.
src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs Modified retrieval and usage of NativeCodeGenState to use the new DTO type.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateMainAndroidManifest.cs Transferred and disposed the Cecil-dependent state appropriately after conversion.
src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs Added a new task key to facilitate registration of the DTO-based state.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me as the first step.

My comments aren't super important, especially if some of that code will be different in future PRs.

Co-authored-by: Jonathan Peppers <[email protected]>
@jpobst jpobst force-pushed the dev/jpobst/marshal-method-task-object branch from e06feb7 to dd1d12b Compare April 23, 2025 19:30
@jpobst jpobst merged commit 20cd062 into main Apr 23, 2025
55 of 59 checks passed
@jpobst jpobst deleted the dev/jpobst/marshal-method-task-object branch April 23, 2025 20:38
@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants