Skip to content

Commit 3822f2b

Browse files
grendellojonpryorjonathanpeppers
authored
[CoreCLR] Another set of changes from #9572 (#9807)
Context: #9572 PR #9572 is quite large. Extract out a set of changes for easier review. Co-authored-by: Jonathan Pryor <[email protected]> Co-authored-by: Jonathan Peppers <[email protected]>
1 parent f45700f commit 3822f2b

36 files changed

+519
-191
lines changed

Configuration.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@
5656
<MicrosoftAndroidSdkPackName Condition="$([MSBuild]::IsOSPlatform('osx'))">Microsoft.Android.Sdk.Darwin</MicrosoftAndroidSdkPackName>
5757
</PropertyGroup>
5858
<PropertyGroup>
59+
<MicrosoftAndroidPacksRootDir>$(BuildOutputDirectory)lib\packs\</MicrosoftAndroidPacksRootDir>
5960
<AutoProvision Condition=" '$(AutoProvision)' == '' ">False</AutoProvision>
6061
<AutoProvisionUsesSudo Condition=" '$(AutoProvisionUsesSudo)' == '' ">False</AutoProvisionUsesSudo>
6162
<_XABinRelativeInstallPrefix>lib\xamarin.android</_XABinRelativeInstallPrefix>
6263
<XAInstallPrefix Condition=" '$(XAInstallPrefix)' == '' ">$(MSBuildThisFileDirectory)bin\$(Configuration)\$(_XABinRelativeInstallPrefix)\</XAInstallPrefix>
6364
<_MonoAndroidNETOutputRoot>$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\</_MonoAndroidNETOutputRoot>
6465
<_MonoAndroidNETDefaultOutDir>$(_MonoAndroidNETOutputRoot)$(AndroidApiLevel)\</_MonoAndroidNETDefaultOutDir>
65-
<MicrosoftAndroidRefPackDir>$(BuildOutputDirectory)lib\packs\Microsoft.Android.Ref.$(AndroidApiLevel)\$(AndroidPackVersion)\ref\$(DotNetTargetFramework)\</MicrosoftAndroidRefPackDir>
66-
<MicrosoftAndroidSdkPackDir>$(BuildOutputDirectory)lib\packs\$(MicrosoftAndroidSdkPackName)\$(AndroidPackVersion)\</MicrosoftAndroidSdkPackDir>
66+
<NativeRuntimeOutputRootDir>$(BuildOutputDirectory)lib\runtimes\</NativeRuntimeOutputRootDir>
67+
<MicrosoftAndroidRefPackDir>$(MicrosoftAndroidPacksRootDir)Microsoft.Android.Ref.$(AndroidApiLevel)\$(AndroidPackVersion)\ref\$(DotNetTargetFramework)\</MicrosoftAndroidRefPackDir>
68+
<MicrosoftAndroidSdkPackDir>$(MicrosoftAndroidPacksRootDir)$(MicrosoftAndroidSdkPackName)\$(AndroidPackVersion)\</MicrosoftAndroidSdkPackDir>
6769
<MicrosoftAndroidSdkOutDir>$(MicrosoftAndroidSdkPackDir)\tools\</MicrosoftAndroidSdkOutDir>
68-
<MicrosoftAndroidSdkAnalysisOutDir>$(BuildOutputDirectory)lib\packs\Microsoft.Android.Ref.$(AndroidLatestStableApiLevel)\$(AndroidPackVersion)\analyzers\dotnet\cs\</MicrosoftAndroidSdkAnalysisOutDir>
70+
<MicrosoftAndroidSdkAnalysisOutDir>$(MicrosoftAndroidPacksRootDir)Microsoft.Android.Ref.$(AndroidLatestStableApiLevel)\$(AndroidPackVersion)\analyzers\dotnet\cs\</MicrosoftAndroidSdkAnalysisOutDir>
6971
<MakeConcurrency Condition=" '$(MakeConcurrency)' == '' And '$(HostCpuCount)' != '' ">-j$(HostCpuCount)</MakeConcurrency>
7072
<ManagedRuntime Condition=" '$(ManagedRuntime)' == '' And '$(OS)' != 'Windows_NT' ">mono</ManagedRuntime>
7173
<ManagedRuntimeArgs Condition=" '$(ManagedRuntimeArgs)' == '' And '$(ManagedRuntime)' == 'mono' ">--debug=casts</ManagedRuntimeArgs>

build-tools/create-packs/Microsoft.Android.Runtime.proj

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ projects that use the Microsoft.Android framework in .NET 6+.
3131
DependsOnTargets="_GetLicense">
3232
<PropertyGroup>
3333
<FrameworkListFile Condition="'$(FrameworkListFile)' == ''">$(IntermediateOutputPath)$(AndroidRID)\RuntimeList.xml</FrameworkListFile>
34+
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">clr</_RuntimeFlavorDirName>
35+
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">mono</_RuntimeFlavorDirName>
3436
</PropertyGroup>
3537

3638
<ItemGroup>
@@ -45,12 +47,27 @@ projects that use the Microsoft.Android framework in .NET 6+.
4547
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Mono.Android.Export.dll" />
4648
</ItemGroup>
4749

50+
<ItemGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
51+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.debug.so" />
52+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libnet-android.release.so" />
53+
</ItemGroup>
54+
4855
<ItemGroup Condition=" '$(AndroidRuntime)' == 'Mono' ">
49-
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.debug.so" />
50-
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.release.so" />
51-
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-debug-app-helper.so" />
52-
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-native-tracing.so" />
53-
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libunwind_xamarin.a" />
56+
<_AndroidRuntimePackAssets Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libmono-android.debug.so" />
57+
<_AndroidRuntimePackAssets Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libmono-android.release.so" />
58+
<_AndroidRuntimePackAssets Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-debug-app-helper.so" />
59+
<_AndroidRuntimePackAssets Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libxamarin-native-tracing.so" />
60+
<_AndroidRuntimePackAssets Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libunwind_xamarin.a" />
61+
</ItemGroup>
62+
63+
<ItemGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
64+
<!-- TODO: the Exists() checks must go away once we build CoreCLR host for all the targets -->
65+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libc.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libc.so" />
66+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libdl.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libdl.so" />
67+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\liblog.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\liblog.so" />
68+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libm.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libm.so" />
69+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libz.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libz.so" />
70+
<_AndroidRuntimePackAssets Condition=" Exists('$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libarchive-dso-stub.so') " Include="$(NativeRuntimeOutputRootDir)$(_RuntimeFlavorDirName)\$(AndroidRID)\libarchive-dso-stub.so" />
5471
</ItemGroup>
5572

5673
<ItemGroup>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
namespace Android.Runtime;
4+
5+
enum DotNetRuntimeType
6+
{
7+
Unknown,
8+
MonoVM,
9+
CoreCLR,
10+
NativeAOT,
11+
}
12+
13+
// This looks weird, see comments in RuntimeTypeInternal.cs
14+
class DotNetRuntimeTypeConverter
15+
{
16+
// Values for the JnienvInitializeArgs.runtimeType field
17+
//
18+
// NOTE: Keep this in sync with managed side in src/native/common/include/managed-interface.hh
19+
const uint RuntimeTypeMonoVM = 0x0001;
20+
const uint RuntimeTypeCoreCLR = 0x0002;
21+
const uint RuntimeTypeNativeAOT = 0x0004;
22+
23+
public static DotNetRuntimeType Convert (uint runtimeType)
24+
{
25+
return runtimeType switch {
26+
RuntimeTypeMonoVM => DotNetRuntimeType.MonoVM,
27+
RuntimeTypeCoreCLR => DotNetRuntimeType.CoreCLR,
28+
RuntimeTypeNativeAOT => DotNetRuntimeType.NativeAOT,
29+
_ => throw new NotSupportedException ($"Internal error: unsupported runtime type {runtimeType:x}")
30+
};
31+
}
32+
}

src/Mono.Android/Android.Runtime/JNIEnvInit.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Android.Runtime
1313
static internal class JNIEnvInit
1414
{
1515
#pragma warning disable 0649
16-
// NOTE: Keep this in sync with the native side in src/native/monodroid/monodroid-glue-internal.hh
16+
// NOTE: Keep this in sync with the native side in src/native/common/include/managed-interface.hh
1717
internal struct JnienvInitializeArgs {
1818
public IntPtr javaVm;
1919
public IntPtr env;
@@ -32,6 +32,7 @@ internal struct JnienvInitializeArgs {
3232
public bool jniRemappingInUse;
3333
public bool marshalMethodsEnabled;
3434
public IntPtr grefGCUserPeerable;
35+
public uint runtimeType;
3536
}
3637
#pragma warning restore 0649
3738

@@ -48,6 +49,8 @@ internal struct JnienvInitializeArgs {
4849

4950
internal static JniRuntime? androidRuntime;
5051

52+
public static DotNetRuntimeType RuntimeType { get; private set; } = DotNetRuntimeType.Unknown;
53+
5154
[UnmanagedCallersOnly]
5255
static unsafe void RegisterJniNatives (IntPtr typeName_ptr, int typeName_len, IntPtr jniClass, IntPtr methods_ptr, int methods_len)
5356
{
@@ -87,6 +90,8 @@ internal static void InitializeJniRuntime (JniRuntime runtime)
8790
[UnmanagedCallersOnly]
8891
internal static unsafe void Initialize (JnienvInitializeArgs* args)
8992
{
93+
RuntimeType = DotNetRuntimeTypeConverter.Convert (args->runtimeType);
94+
9095
IntPtr total_timing_sequence = IntPtr.Zero;
9196
IntPtr partial_timing_sequence = IntPtr.Zero;
9297

src/Mono.Android/Mono.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
<Compile Include="Android.Runtime\BoundExceptionType.cs" />
222222
<Compile Include="Android.Runtime\CharSequence.cs" />
223223
<Compile Include="Android.Runtime\CPUArchitecture.cs" />
224+
<Compile Include="Android.Runtime\DotNetRuntimeType.cs" />
224225
<Compile Include="Android.Runtime\Extensions.cs" />
225226
<Compile Include="Android.Runtime\GeneratedEnumAttribute.cs" />
226227
<Compile Include="Android.Runtime\IJavaObject.cs" />

src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,16 @@ void SaveResource (string resource, string filename, string destDir, Func<string
480480

481481
void WriteTypeMappings (NativeCodeGenState state)
482482
{
483+
if (androidRuntime == Xamarin.Android.Tasks.AndroidRuntime.NativeAOT) {
484+
// NativeAOT typemaps are generated in `Microsoft.Android.Sdk.ILLink.TypeMappingStep`
485+
return;
486+
}
487+
if (androidRuntime == Xamarin.Android.Tasks.AndroidRuntime.CoreCLR) {
488+
// TODO: CoreCLR typemaps will be emitted later
489+
return;
490+
}
483491
Log.LogDebugMessage ($"Generating type maps for architecture '{state.TargetArch}'");
484-
var tmg = new TypeMapGenerator (Log, state);
492+
var tmg = new TypeMapGenerator (Log, state, androidRuntime);
485493
if (!tmg.Generate (Debug, SkipJniAddNativeMethodRegistrationAttributeScan, TypemapOutputDirectory, GenerateNativeAssembly)) {
486494
throw new XamarinAndroidException (4308, Properties.Resources.XA4308);
487495
}

src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigNativeAssemblyGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public override string GetComment (object data, string fieldName)
3939
}
4040
}
4141

42+
// Disable "Field 'X' is never assigned to, and will always have its default value Y"
43+
// Classes below are used in native code generation, thus all the fields must be present
44+
// but they aren't always assigned values (which is fine).
45+
#pragma warning disable CS0649
46+
4247
// Order of fields and their type must correspond *exactly* (with exception of the
4348
// ignored managed members) to that in
4449
// src/monodroid/jni/xamarin-app.hh DSOCacheEntry structure
@@ -147,6 +152,7 @@ sealed class XamarinAndroidBundledAssembly
147152
[NativeAssembler (UsesDataProvider = true), NativePointer (PointsToPreAllocatedBuffer = true)]
148153
public string name;
149154
}
155+
#pragma warning restore CS0649
150156

151157
// Keep in sync with FORMAT_TAG in src/monodroid/jni/xamarin-app.hh
152158
const ulong FORMAT_TAG = 0x00025E6972616D58; // 'Xmari^XY' where XY is the format version

src/Xamarin.Android.Build.Tasks/Utilities/AssemblyStoreGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ string Generate (string baseOutputDirectory, AndroidTargetArch arch, List<Assemb
115115
// We'll start writing to the stream after we seek to the position just after the header, index, descriptors and name data.
116116
ulong curPos = assemblyDataStart;
117117

118+
Directory.CreateDirectory (Path.GetDirectoryName (storePath));
118119
using var fs = File.Open (storePath, FileMode.Create, FileAccess.Write, FileShare.Read);
119120
fs.Seek ((long)curPos, SeekOrigin.Begin);
120121

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrGenerator.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ void WriteStructureValue (GeneratorWriteContext context, StructureInstance? inst
781781

782782
for (int i = 0; i < info.Members.Count; i++) {
783783
StructureMemberInfo smi = info.Members[i];
784+
if (!smi.IsSupportedForTarget (context.Target)) {
785+
continue;
786+
}
784787

785788
context.Output.Write (context.CurrentIndent);
786789
WriteType (context, instance, smi, out _);
@@ -810,7 +813,7 @@ void WriteStructureValue (GeneratorWriteContext context, StructureInstance? inst
810813
var sb = new StringBuilder (" ");
811814
sb.Append (MapManagedTypeToNative (context, smi));
812815
sb.Append (' ');
813-
sb.Append (smi.Info.Name);
816+
sb.Append (smi.MappedName);
814817
comment = sb.ToString ();
815818
}
816819
WriteCommentLine (context, comment);
@@ -848,6 +851,7 @@ void WriteArrayEntries (GeneratorWriteContext context, LlvmIrVariable variable,
848851
bool ignoreComments = stride > 1;
849852
string? prevItemComment = null;
850853
ulong counter = 0;
854+
bool writeStringInComment = !ignoreComments && (elementType == typeof(string) || elementType == typeof(StringHolder));
851855

852856
if (entries != null) {
853857
foreach (object entry in entries) {
@@ -871,7 +875,13 @@ void WriteArrayEntries (GeneratorWriteContext context, LlvmIrVariable variable,
871875
}
872876

873877
if (writeIndices && String.IsNullOrEmpty (prevItemComment)) {
874-
prevItemComment = $" {counter}";
878+
string stringComment = String.Empty;
879+
if (writeStringInComment) {
880+
var holder = StringHolder.AsHolder (entry);
881+
stringComment = $" ('{holder.Data}')";
882+
}
883+
884+
prevItemComment = $" {counter}{stringComment}";
875885
}
876886
}
877887

@@ -1098,6 +1108,10 @@ void WriteStructureDeclaration (GeneratorWriteContext context, StructureInfo si)
10981108
context.IncreaseIndent ();
10991109
for (int i = 0; i < si.Members.Count; i++) {
11001110
StructureMemberInfo info = si.Members[i];
1111+
if (!info.IsSupportedForTarget (context.Target)) {
1112+
continue;
1113+
}
1114+
11011115
string nativeType = MapManagedTypeToNative (info.MemberType);
11021116

11031117
// TODO: nativeType can be an array, update to indicate that (and get the size)
@@ -1108,7 +1122,7 @@ void WriteStructureDeclaration (GeneratorWriteContext context, StructureInfo si)
11081122
arraySize = String.Empty;
11091123
}
11101124

1111-
var comment = $" {nativeType} {info.Info.Name}{arraySize}";
1125+
var comment = $" {nativeType} {info.MappedName}{arraySize}";
11121126
WriteStructureDeclarationField (info.IRType, comment, i == si.Members.Count - 1);
11131127
}
11141128
context.DecreaseIndent ();

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/MemberInfoUtilities.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ public static LlvmIrStringEncoding GetStringEncoding (this MemberInfo mi, LlvmIr
5656
return attr.IsUTF16 ? LlvmIrStringEncoding.Unicode : DefaultStringEncoding;
5757
}
5858

59+
public static string? GetOverriddenName (this MemberInfo mi, LlvmIrTypeCache cache)
60+
{
61+
var attr = cache.GetNativeAssemblerAttribute (mi);
62+
return attr != null ? attr.MemberName : null;
63+
}
64+
65+
public static NativeAssemblerValidTarget GetValidTarget (this MemberInfo mi, LlvmIrTypeCache cache)
66+
{
67+
var attr = cache.GetNativeAssemblerAttribute (mi);
68+
return attr != null ? attr.ValidTarget : NativeAssemblerValidTarget.Any;
69+
}
70+
5971
public static bool ShouldBeIgnored (this MemberInfo mi, LlvmIrTypeCache cache)
6072
{
6173
var attr = cache.GetNativeAssemblerAttribute (mi);

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/NativeAssemblerAttribute.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
namespace Xamarin.Android.Tasks
44
{
5+
enum NativeAssemblerValidTarget
6+
{
7+
Any,
8+
ThirtyTwoBit,
9+
SixtyFourBit,
10+
}
11+
512
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
613
class NativeAssemblerAttribute : Attribute
714
{
@@ -41,6 +48,22 @@ class NativeAssemblerAttribute : Attribute
4148
/// the native assembly file.
4249
/// </summary>
4350
public bool IsUTF16 { get; set; }
51+
52+
/// <summary>
53+
/// Allows choosing that a structure/class field/property will be considered only for the target of
54+
/// specific bitness. Mainly useful when dealing with hash fields.
55+
/// </summary>
56+
public NativeAssemblerValidTarget ValidTarget { get; set; } = NativeAssemblerValidTarget.Any;
57+
58+
/// <summary>
59+
/// Allows overriding of the field name when mapping the structure. This is purely cosmetic, but allows to avoid
60+
/// confusion when dealing with fields/properties that have a different size for 32-bit and 64-bit targets. In such
61+
/// case the structure being mapped will have a separate member per bitness, with the members requiring different names
62+
/// while in reality they have the same name in the native world, regardless of bitness.
63+
///
64+
/// This field is only considered only when <see cref="ValidTarget" /> is not set to <see cref="NativeAssemblerValidTarget.Any"/>
65+
/// </summary>
66+
public string? MemberName { get; set; }
4467
}
4568

4669
[AttributeUsage (AttributeTargets.Class, Inherited = true)]

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/StructureMemberInfo.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ sealed class StructureMemberInfo
2727
public bool IsInlineArray { get; }
2828
public bool NeedsPadding { get; }
2929

30+
/// <summary>
31+
/// Some fields/properties may override their name for presentation purposes, <see cref="NativeAssemblerAttribute.MemberName" />.
32+
/// In such instances, this property will return the overridden/mapped name, otherwise it returns <see cref="Info.Name"/>.
33+
/// This property should be used only for "presentation" purposes - for instance when generating comments which refer to
34+
/// native field names.
35+
/// </summary>
36+
public string MappedName {
37+
get {
38+
string? name = Info.GetOverriddenName (typeCache);
39+
return String.IsNullOrEmpty (name) ? Info.Name : name;
40+
}
41+
}
42+
43+
readonly LlvmIrTypeCache typeCache;
44+
3045
public StructureMemberInfo (MemberInfo mi, LlvmIrModule module, LlvmIrTypeCache cache)
3146
{
3247
Info = mi;
48+
typeCache = cache;
3349

3450
MemberType = mi switch {
3551
FieldInfo fi => fi.FieldType,
@@ -97,6 +113,17 @@ public StructureMemberInfo (MemberInfo mi, LlvmIrModule module, LlvmIrTypeCache
97113
}
98114
}
99115

116+
public bool IsSupportedForTarget (LlvmIrModuleTarget target)
117+
{
118+
NativeAssemblerValidTarget validTarget = Info.GetValidTarget (typeCache);
119+
return validTarget switch {
120+
NativeAssemblerValidTarget.Any => true,
121+
NativeAssemblerValidTarget.ThirtyTwoBit => !target.Is64Bit,
122+
NativeAssemblerValidTarget.SixtyFourBit => target.Is64Bit,
123+
_ => throw new NotSupportedException ($"Internal error: unsupported native assembler valid target value: {validTarget}")
124+
};
125+
}
126+
100127
public object? GetValue (object instance)
101128
{
102129
if (Info is FieldInfo fi) {

src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,13 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L
673673

674674
IList<string> AddMonoRuntimeProviders (XElement app)
675675
{
676-
if (AndroidRuntime == AndroidRuntime.CoreCLR) {
677-
//TODO: implement provider logic for CoreCLR
678-
return [];
679-
}
676+
(string packageName, string className) = AndroidRuntime switch {
677+
AndroidRuntime.MonoVM => ("mono", "MonoRuntimeProvider"),
678+
AndroidRuntime.CoreCLR => ("mono", "MonoRuntimeProvider"),
679+
AndroidRuntime.NativeAOT => ("net.dot.jni.nativeaot", "NativeAotRuntimeProvider"),
680+
_ => throw new NotSupportedException ($"Internal error: unsupported runtime type: {AndroidRuntime}")
681+
};
680682

681-
bool isMonoVM = AndroidRuntime == AndroidRuntime.MonoVM;
682-
string packageName = isMonoVM ? "mono" : "net.dot.jni.nativeaot";
683-
string className = isMonoVM ? "MonoRuntimeProvider" : "NativeAotRuntimeProvider";
684683
app.Add (CreateMonoRuntimeProvider ($"{packageName}.{className}", null, --AppInitOrder));
685684

686685
var providerNames = new List<string> ();

src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.Basic.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public static string ArchToAbi (AndroidTargetArch arch)
149149
}
150150

151151
public static bool IsValidAbi (string abi) => AbiToRidMap.ContainsKey (abi);
152+
public static bool IsValidRID (string rid) => RidToAbiMap.ContainsKey (rid);
152153

153154
public static string? CultureInvariantToString (object? obj)
154155
{
@@ -228,6 +229,7 @@ public static ulong GetMangledAssemblyNameSizeOverhead ()
228229
}
229230

230231
public static byte[] Utf8StringToBytes (string str) => Encoding.UTF8.GetBytes (str);
232+
public static byte[] Utf16StringToBytes (string str) => Encoding.Unicode.GetBytes (str);
231233

232234
public static ulong GetXxHash (string str, bool is64Bit) => GetXxHash (Utf8StringToBytes (str), is64Bit);
233235

0 commit comments

Comments
 (0)