Skip to content

[nativeaot] introduce Microsoft.Android.Runtime.NativeAOT.dll - #9760

Merged
jonpryor merged 7 commits into
mainfrom
dev/peppers/microsoft.android.nativeaot
Feb 12, 2025
Merged

[nativeaot] introduce Microsoft.Android.Runtime.NativeAOT.dll#9760
jonpryor merged 7 commits into
mainfrom
dev/peppers/microsoft.android.nativeaot

Conversation

@jonathanpeppers

@jonathanpeppersjonathanpeppers commented Feb 5, 2025

Copy link
Copy Markdown
Member

This moves:

  • C# code from samples/NativeAOT to a new assembly, Microsoft.Android.Runtime.NativeAOT.dll.

  • Java code from samples/NativeAOT to Xamarin.Android.Build.Tasks, to be generated at build time.

  • C# code from Java.Interop.Environment.csproj has been trimmed down and moved to Microsoft.Android.Runtime.NativeAOT.dll as well.

  • A new TypeMappingStep implements the simplest MVP for a "typemap", replacing the NativeAotTypeManager.InitializeTypeMappings() method.

@jonathanpeppers
jonathanpeppersforce-pushed the dev/peppers/microsoft.android.nativeaot branch 2 times, most recently from 6532402 to cc63af6CompareFebruary 6, 2025 17:47
Comment threadsrc/Microsoft.Android.Sdk.ILLink/TypeMappingStep.cs
@jonathanpeppers
jonathanpeppersforce-pushed the dev/peppers/microsoft.android.nativeaot branch from cc63af6 to 4edc889CompareFebruary 6, 2025 20:26
Comment threadsrc/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Outdated
@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers
jonathanpeppersforce-pushed the dev/peppers/microsoft.android.nativeaot branch from 4edc889 to de37e06CompareFebruary 7, 2025 16:30
@jonathanpeppers

Copy link
Copy Markdown
MemberAuthor

Affected tests look green:

image

@jonathanpeppers
jonathanpeppers marked this pull request as ready for review February 7, 2025 18:58
@jonathanpeppers

Copy link
Copy Markdown
MemberAuthor

There are some APK test failures, but look network-related:

System.AggregateException : AggregateException_ctor_DefaultMessage (net_http_message_not_success_statuscode_reason, 403, Forbidden) (net_http_message_not_success_statuscode_reason, 403, Forbidden)

public NativeAotTypeManager ()
{
AndroidLog.Print (AndroidLogLevel.Info, "NativeAotTypeManager", $"# jonp: NativeAotTypeManager()");
InitializeTypeMappings ();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This likewise should be in the static constructor.

Alternatively, TypeMappings should be an instance field.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I made it an instance field, as I think it makes more sense for the instance of the *TypeManager to hold its typemap.

Comment threadsrc/Microsoft.Android.Runtime.NativeAOT/Java.Interop/JreRuntime.cs Outdated
@jonpryor

jonpryor commented Feb 11, 2025

Copy link
Copy Markdown
Contributor

Draft commit message:

This moves:
* C# code from `samples/NativeAOT` to a new assembly,
`Microsoft.Android.Runtime.NativeAOT.dll`.
* Java code from `samples/NativeAOT` to
`Xamarin.Android.Build.Tasks`, to be generated at build time.
* C# code from `Java.Interop.Environment.csproj` has been trimmed
down, copied into `Microsoft.Android.Runtime.NativeAOT.dll`.
* Minimum Viable Product™ "typemap" implementation.
* Change namespace to `Microsoft.Android.Runtime`## Minimum Viable Product™ typemaps
A quick-and-dirty -- and totally unoptimized -- typemap implementation
has been added as a new `TypeMappingStep` into
`Microsoft.Android.Sdk.ILLink`.
Given this initial starting point within `NativeAotTypeManager`:
partial class NativeAotTypeManager { IDictionary<string, Type> TypeMappings = new Dictionary<string, Type>(StringComparer.Ordinal); NativeAotTypeManager () {	InitializeTypeMappings (); } void InitializeTypeMappings () { throw new InvalidOperationException ("Should be replaced at build time!"); }}
then at build time `TypeMappingStep` will *replace* the body of
`NativeAotTypeManager.InitializeTypeMappings()` with repeated
`IDictionary<string, Type>.Add()` calls for each type which survived
linking:
// Cecil-generated code, C# equivalentvoid InitializeTypeMappings (){ TypeMappings.Add ("java/lang/Object", typeof (Java.Lang.Object)); TypeMappings.Add ("android/app/Application", typeof (Android.App.Application)); // …}

This moves:
* C# code from `samples/NativeAOT` to a new assembly,
`Microsoft.Android.Runtime.NativeAOT.dll`.
* Java code from `samples/NativeAOT` to `Xamarin.Android.Build.Tasks`,
to be generated at build time.
* C# code from `Java.Interop.Environment.csproj` has been trimmed down
and moved to `Microsoft.Android.Runtime.NativeAOT.dll` as well.
Remove some unused code as well
@jonathanpeppers
jonathanpeppersforce-pushed the dev/peppers/microsoft.android.nativeaot branch from 00edfbd to d989734CompareFebruary 11, 2025 19:12
@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers

This comment was marked as outdated.

Requires `Ldarg_0` on stack, then `Ldfld` instead of `Ldsfld`.
This will be of interest if/when we start investigating alternate
typemap initialization ideas.
@jonpryor
jonpryor merged commit 70bd636 into mainFeb 12, 2025
@jonpryor
jonpryor deleted the dev/peppers/microsoft.android.nativeaot branch February 12, 2025 15:23
grendello added a commit that referenced this pull request Feb 13, 2025
* main:
[Mono.Android-Tests] Remove obsolete `.shproj` file. (#9758)
[NativeAOT] introduce `Microsoft.Android.Runtime.NativeAOT.dll` (#9760)
@jonathanpeppersjonathanpeppers mentioned this pull request Feb 20, 2025
20 tasks
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Mar 15, 2025
Sign up for freeto 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

@jonathanpeppers@jonpryor@dellis1972