-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NativeAOT] introduce
Microsoft.Android.Runtime.NativeAOT.dll
(#9760)
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)); // … }
- Loading branch information
1 parent
7acf328
commit 70bd636
Showing
23 changed files
with
593 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="@string/app_name" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"> | ||
<!-- Temporary, to eventually be included in .NET Android infrastructure --> | ||
<provider | ||
android:name="net.dot.jni.nativeaot.NativeAotRuntimeProvider" | ||
android:exported="false" | ||
android:initOrder="1999999999" | ||
android:authorities="net.dot.jni.nativeaot.NativeAotRuntimeProvider.__init__" | ||
/> | ||
</application> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
</manifest> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System.Runtime.Versioning; | ||
|
||
// NOTE: silences the CA1416 analyzer about supported Android APIs | ||
[assembly: TargetPlatformAttribute("Android35.0")] | ||
[assembly: SupportedOSPlatformAttribute("Android21.0")] |
98 changes: 98 additions & 0 deletions
98
src/Microsoft.Android.Runtime.NativeAOT/Java.Interop/JreRuntime.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Originally from: https://github.com/dotnet/java-interop/blob/dd3c1d0514addfe379f050627b3e97493e985da6/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using Microsoft.Android.Runtime; | ||
|
||
namespace Java.Interop { | ||
|
||
struct JavaVMInitArgs { | ||
#pragma warning disable CS0649 // Field is never assigned to; | ||
public JniVersion version; /* use JNI_VERSION_1_2 or later */ | ||
|
||
public int nOptions; | ||
public IntPtr /* JavaVMOption[] */ options; | ||
public byte ignoreUnrecognized; | ||
#pragma warning restore CS0649 | ||
} | ||
|
||
class NativeAotRuntimeOptions : JniRuntime.CreationOptions { | ||
|
||
public bool IgnoreUnrecognizedOptions {get; set;} | ||
|
||
public TextWriter? JniGlobalReferenceLogWriter {get; set;} | ||
public TextWriter? JniLocalReferenceLogWriter {get; set;} | ||
|
||
public NativeAotRuntimeOptions () | ||
{ | ||
JniVersion = JniVersion.v1_2; | ||
} | ||
|
||
public JreRuntime CreateJreVM () | ||
{ | ||
return new JreRuntime (this); | ||
} | ||
} | ||
|
||
class JreRuntime : JniRuntime | ||
{ | ||
static JreRuntime () | ||
{ | ||
} | ||
|
||
static NativeAotRuntimeOptions CreateJreVM (NativeAotRuntimeOptions builder) | ||
{ | ||
if (builder == null) | ||
throw new ArgumentNullException ("builder"); | ||
if (builder.InvocationPointer == IntPtr.Zero && | ||
builder.EnvironmentPointer == IntPtr.Zero && | ||
string.IsNullOrEmpty (builder.JvmLibraryPath)) | ||
throw new InvalidOperationException ($"Member `{nameof (NativeAotRuntimeOptions)}.{nameof (NativeAotRuntimeOptions.JvmLibraryPath)}` must be set."); | ||
|
||
#if NET | ||
builder.TypeManager ??= new NativeAotTypeManager (); | ||
#endif // NET | ||
|
||
builder.ValueManager ??= new NativeAotValueManager (builder.TypeManager); | ||
builder.ObjectReferenceManager ??= new ManagedObjectReferenceManager (builder.JniGlobalReferenceLogWriter, builder.JniLocalReferenceLogWriter); | ||
|
||
if (builder.InvocationPointer != IntPtr.Zero || builder.EnvironmentPointer != IntPtr.Zero) | ||
return builder; | ||
|
||
throw new NotImplementedException (); | ||
} | ||
|
||
[UnconditionalSuppressMessage ("Trimming", "IL3000", Justification = "We check for a null Assembly.Location value!")] | ||
internal static string? GetAssemblyLocation (Assembly assembly) | ||
{ | ||
var location = assembly.Location; | ||
if (!string.IsNullOrEmpty (location)) | ||
return location; | ||
return null; | ||
} | ||
|
||
internal protected JreRuntime (NativeAotRuntimeOptions builder) | ||
: base (CreateJreVM (builder)) | ||
{ | ||
} | ||
|
||
public override string? GetCurrentManagedThreadName () | ||
{ | ||
return Thread.CurrentThread.Name; | ||
} | ||
|
||
public override string GetCurrentManagedThreadStackTrace (int skipFrames, bool fNeedFileInfo) | ||
{ | ||
return new StackTrace (skipFrames, fNeedFileInfo) | ||
.ToString (); | ||
} | ||
} | ||
} |
Oops, something went wrong.