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

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

Merged
merged 7 commits into from
Feb 12, 2025

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Feb 5, 2025

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 jonathanpeppers force-pushed the dev/peppers/microsoft.android.nativeaot branch 2 times, most recently from 6532402 to cc63af6 Compare February 6, 2025 17:47
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/microsoft.android.nativeaot branch from cc63af6 to 4edc889 Compare February 6, 2025 20:26
@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/microsoft.android.nativeaot branch from 4edc889 to de37e06 Compare February 7, 2025 16:30
@jonathanpeppers
Copy link
Member Author

Affected tests look green:

image

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

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
Member

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
Member Author

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.

@jonpryor
Copy link
Member

jonpryor commented Feb 11, 2025

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# equivalent
	void 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 jonathanpeppers force-pushed the dev/peppers/microsoft.android.nativeaot branch from 00edfbd to d989734 Compare February 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 main Feb 12, 2025
25 of 58 checks passed
@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)
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.

3 participants