Skip to content

Commit

Permalink
Merge branch 'main' into dev/grendel/blobs-in-lib
Browse files Browse the repository at this point in the history
* main:
  [monodroid] typemaps may need to load assemblies (#8625)
  Bump $(AndroidNetPreviousVersion) to 34.0.79 (#8693)
  Bump to xamarin/java.interop/main@07c73009 (#8681)
  Bump to dotnet/installer@1c496970b7 9.0.100-preview.2.24078.1 (#8685)
  • Loading branch information
grendello committed Feb 5, 2024
2 parents d706ffe + 06b1d7f commit 2a67bee
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<DebugType Condition=" '$(DebugType)' == '' ">portable</DebugType>
<Deterministic Condition=" '$(Deterministic)' == '' ">True</Deterministic>
<LangVersion Condition=" '$(LangVersion)' == '' ">latest</LangVersion>
<AndroidNetPreviousVersion Condition=" '$(AndroidNetPreviousVersion)' == '' ">34.0.56</AndroidNetPreviousVersion>
<AndroidNetPreviousVersion Condition=" '$(AndroidNetPreviousVersion)' == '' ">34.0.79</AndroidNetPreviousVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(HostOS)' == '' ">
<HostOS Condition="$([MSBuild]::IsOSPlatform('windows'))">Windows</HostOS>
Expand Down
16 changes: 8 additions & 8 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="9.0.100-preview.2.24073.12">
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="9.0.100-preview.2.24078.1">
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>5680e93cb251d7741e19f2d759f04141e9d95a93</Sha>
<Sha>1c496970b7479284364bc7eaf5c30e59f1cdb2ec</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="9.0.0-preview.2.24072.10" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="9.0.0-preview.2.24076.4" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>e3547f1d3ac768a14a0598abf7868641ecf0c9d7</Sha>
<Sha>bcc1d3d6f00fbcea3f454b2e35bceeaa51e604b1</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Ref" Version="9.0.0-preview.2.24072.10" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Dependency Name="Microsoft.NETCore.App.Ref" Version="9.0.0-preview.2.24076.4" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>e3547f1d3ac768a14a0598abf7868641ecf0c9d7</Sha>
<Sha>bcc1d3d6f00fbcea3f454b2e35bceeaa51e604b1</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport" Version="9.0.0-alpha.1.24068.1" CoherentParentDependency="Microsoft.NETCore.App.Ref">
<Dependency Name="Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport" Version="9.0.0-alpha.1.24072.1" CoherentParentDependency="Microsoft.NETCore.App.Ref">
<Uri>https://github.com/dotnet/emsdk</Uri>
<Sha>fd99e59a43cfd6fe323c98ff267b620a67e71e67</Sha>
<Sha>ae7c93e25ae596594b3b22d64115f374a3595912</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.Cecil" Version="0.11.4-alpha.24065.1" CoherentParentDependency="Microsoft.NET.ILLink.Tasks">
<Uri>https://github.com/dotnet/cecil</Uri>
Expand Down
8 changes: 4 additions & 4 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project>
<!--Package versions-->
<PropertyGroup>
<MicrosoftDotnetSdkInternalPackageVersion>9.0.100-preview.2.24073.12</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>9.0.0-preview.2.24072.10</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>9.0.0-preview.2.24072.10</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftDotnetSdkInternalPackageVersion>9.0.100-preview.2.24078.1</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>9.0.0-preview.2.24076.4</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>9.0.0-preview.2.24076.4</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftDotNetApiCompatPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetApiCompatPackageVersion>
<MicrosoftDotNetBuildTasksFeedPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetBuildTasksFeedPackageVersion>
<MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion>9.0.0-alpha.1.24068.1</MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion>
<MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion>9.0.0-alpha.1.24072.1</MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion>
<MicrosoftNETWorkloadEmscriptenPackageVersion>$(MicrosoftNETWorkloadEmscriptenCurrentManifest90100TransportVersion)</MicrosoftNETWorkloadEmscriptenPackageVersion>
<MicrosoftTemplateEngineTasksPackageVersion>7.0.100-rc.1.22410.7</MicrosoftTemplateEngineTasksPackageVersion>
<MicrosoftDotNetCecilPackageVersion>0.11.4-alpha.24065.1</MicrosoftDotNetCecilPackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion external/Java.Interop
24 changes: 17 additions & 7 deletions src/Mono.Android/Java.Interop/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership
{
Type? type = null;
IntPtr class_ptr = JNIEnv.GetObjectClass (handle);
string class_name = GetClassName (class_ptr);
string? class_name = GetClassName (class_ptr);
lock (TypeManagerMapDictionaries.AccessLock) {
while (class_ptr != IntPtr.Zero && !TypeManagerMapDictionaries.JniToManaged.TryGetValue (class_name, out type)) {

Expand All @@ -279,23 +279,33 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership

IntPtr super_class_ptr = JNIEnv.GetSuperclass (class_ptr);
JNIEnv.DeleteLocalRef (class_ptr);
class_name = null;
class_ptr = super_class_ptr;
class_name = GetClassName (class_ptr);
if (class_ptr != IntPtr.Zero) {
class_name = GetClassName (class_ptr);
}
}
}

JNIEnv.DeleteLocalRef (class_ptr);
if (class_ptr != IntPtr.Zero) {
JNIEnv.DeleteLocalRef (class_ptr);
class_ptr = IntPtr.Zero;
}

if (targetType != null &&
(type == null ||
!targetType.IsAssignableFrom (type))) {
type = targetType;
}

if (type == null) {
class_name = JNIEnv.GetClassNameFromInstance (handle);
JNIEnv.DeleteRef (handle, transfer);
throw new NotSupportedException (
FormattableString.Invariant ($"Internal error finding wrapper class for '{JNIEnv.GetClassNameFromInstance (handle)}'. (Where is the Java.Lang.Object wrapper?!)"),
FormattableString.Invariant ($"Internal error finding wrapper class for '{class_name}'. (Where is the Java.Lang.Object wrapper?!)"),
CreateJavaLocationException ());
}

if (targetType != null && !targetType.IsAssignableFrom (type))
type = targetType;

if (type.IsInterface || type.IsAbstract) {
var invokerType = JavaObjectExtensions.GetInvokerType (type);
if (invokerType == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void GenerateCompressedAssemblySources ()

void Generate (Dictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>> dict)
{
var composer = new CompressedAssembliesNativeAssemblyGenerator (dict);
var composer = new CompressedAssembliesNativeAssemblyGenerator (Log, dict);
LLVMIR.LlvmIrModule compressedAssemblies = composer.Construct ();

foreach (string abi in SupportedAbis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override bool RunTask ()

void GenerateEmpty ()
{
Generate (new JniRemappingAssemblyGenerator (), typeReplacementsCount: 0);
Generate (new JniRemappingAssemblyGenerator (Log), typeReplacementsCount: 0);
}

void Generate ()
Expand All @@ -74,7 +74,7 @@ void Generate ()
}
}

Generate (new JniRemappingAssemblyGenerator (typeReplacements, methodReplacements), typeReplacements.Count);
Generate (new JniRemappingAssemblyGenerator (Log, typeReplacements, methodReplacements), typeReplacements.Count);
}

void Generate (JniRemappingAssemblyGenerator jniRemappingComposer, int typeReplacementsCount)
Expand Down
4 changes: 4 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/JavaCompileToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ private void GenerateResponseFile ()
file.Replace (@"\", @"\\").Normalize (NormalizationForm.FormC)));
}
}
Log.LogDebugMessage ($"javac response file contents: {TemporarySourceListFile}");
foreach (var line in File.ReadLines (TemporarySourceListFile)) {
Log.LogDebugMessage ($" {line}");
}
}
}
}
18 changes: 9 additions & 9 deletions src/Xamarin.Android.Build.Tasks/Tasks/R8.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Collections.Generic;
Expand Down Expand Up @@ -82,16 +83,15 @@ protected override CommandLineBuilder GetCommandLineBuilder ()

if (EnableShrinking) {
if (!string.IsNullOrEmpty (AcwMapFile)) {
var acwLines = File.ReadAllLines (AcwMapFile);
var acwMap = MonoAndroidHelper.LoadMapFile (BuildEngine4, Path.GetFullPath (AcwMapFile), StringComparer.OrdinalIgnoreCase);
var javaTypes = new List<string> (acwMap.Values.Count);
foreach (var v in acwMap.Values) {
javaTypes.Add (v);
}
javaTypes.Sort (StringComparer.Ordinal);
using (var appcfg = File.CreateText (ProguardGeneratedApplicationConfiguration)) {
for (int i = 0; i + 2 < acwLines.Length; i += 3) {
try {
var line = acwLines [i + 2];
var java = line.Substring (line.IndexOf (';') + 1);
appcfg.WriteLine ("-keep class " + java + " { *; }");
} catch {
// skip invalid lines
}
foreach (var java in javaTypes) {
appcfg.WriteLine ($"-keep class {java} {{ *; }}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Java.Interop.Tools.TypeNameMappings;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Android.Build.Tasks;
using Xamarin.Android.Tasks.LLVMIR;

namespace Xamarin.Android.Tasks
Expand Down Expand Up @@ -153,7 +154,6 @@ sealed class XamarinAndroidBundledAssembly

SortedDictionary <string, string>? environmentVariables;
SortedDictionary <string, string>? systemProperties;
TaskLoggingHelper log;
StructureInstance? application_config;
List<StructureInstance<DSOCacheEntry>>? dsoCache;
List<StructureInstance<XamarinAndroidBundledAssembly>>? xamarinAndroidBundledAssemblies;
Expand Down Expand Up @@ -190,6 +190,7 @@ sealed class XamarinAndroidBundledAssembly
public bool MarshalMethodsEnabled { get; set; }

public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
: base (log)
{
if (environmentVariables != null) {
this.environmentVariables = new SortedDictionary<string, string> (environmentVariables, StringComparer.Ordinal);
Expand All @@ -198,8 +199,6 @@ public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> env
if (systemProperties != null) {
this.systemProperties = new SortedDictionary<string, string> (systemProperties, StringComparer.Ordinal);
}

this.log = log;
}

protected override void Construct (LlvmIrModule module)
Expand Down Expand Up @@ -353,7 +352,7 @@ List<StructureInstance<DSOCacheEntry>> InitDSOCache ()
continue;
}

dsos.Add ((name, $"dsoName{dsos.Count.ToString (CultureInfo.InvariantCulture)}", ELFHelper.IsEmptyAOTLibrary (log, item.ItemSpec)));
dsos.Add ((name, $"dsoName{dsos.Count.ToString (CultureInfo.InvariantCulture)}", ELFHelper.IsEmptyAOTLibrary (Log, item.ItemSpec)));
}

var dsoCache = new List<StructureInstance<DSOCacheEntry>> ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;

using Microsoft.Build.Utilities;

using Xamarin.Android.Tasks.LLVMIR;
using Xamarin.Android.Tools;

Expand Down Expand Up @@ -74,7 +76,8 @@ sealed class CompressedAssemblies
StructureInfo compressedAssembliesStructureInfo;
Dictionary<AndroidTargetArch, List<StructureInstance<CompressedAssemblyDescriptor>>> archData = new Dictionary<AndroidTargetArch, List<StructureInstance<CompressedAssemblyDescriptor>>> ();

public CompressedAssembliesNativeAssemblyGenerator (IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>? archAssemblies)
public CompressedAssembliesNativeAssemblyGenerator (TaskLoggingHelper log, IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>? archAssemblies)
: base (log)
{
this.archAssemblies = archAssemblies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Text;

using Microsoft.Build.Utilities;

using Xamarin.Android.Tasks.LLVMIR;

namespace Xamarin.Android.Tasks
Expand Down Expand Up @@ -190,10 +192,12 @@ sealed class JniRemappingTypeReplacementEntry

public int ReplacementMethodIndexEntryCount { get; private set; } = 0;

public JniRemappingAssemblyGenerator ()
public JniRemappingAssemblyGenerator (TaskLoggingHelper log)
: base (log)
{}

public JniRemappingAssemblyGenerator (List<JniRemappingTypeReplacement> typeReplacements, List<JniRemappingMethodReplacement> methodReplacements)
public JniRemappingAssemblyGenerator (TaskLoggingHelper log, List<JniRemappingTypeReplacement> typeReplacements, List<JniRemappingMethodReplacement> methodReplacements)
: base (log)
{
this.typeReplacementsInput = typeReplacements ?? throw new ArgumentNullException (nameof (typeReplacements));
this.methodReplacementsInput = methodReplacements ?? throw new ArgumentNullException (nameof (methodReplacements));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;

using Microsoft.Build.Utilities;

using Xamarin.Android.Tools;

namespace Xamarin.Android.Tasks.LLVMIR
Expand All @@ -9,6 +11,13 @@ abstract class LlvmIrComposer
{
bool constructed;

protected readonly TaskLoggingHelper Log;

protected LlvmIrComposer (TaskLoggingHelper log)
{
this.Log = log ?? throw new ArgumentNullException (nameof (log));
}

protected abstract void Construct (LlvmIrModule module);

public LlvmIrModule Construct ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public MarshalMethodAssemblyIndexValuePlaceholder (MarshalMethodInfo mmi, Assemb

readonly ICollection<string> uniqueAssemblyNames;
readonly int numberOfAssembliesInApk;
readonly TaskLoggingHelper logger;

StructureInfo marshalMethodsManagedClassStructureInfo;
StructureInfo marshalMethodNameStructureInfo;
Expand All @@ -244,7 +243,8 @@ public MarshalMethodAssemblyIndexValuePlaceholder (MarshalMethodInfo mmi, Assemb
/// <summary>
/// Constructor to be used ONLY when marshal methods are DISABLED
/// </summary>
public MarshalMethodsNativeAssemblyGenerator (AndroidTargetArch targetArch, int numberOfAssembliesInApk, ICollection<string> uniqueAssemblyNames)
public MarshalMethodsNativeAssemblyGenerator (TaskLoggingHelper log, AndroidTargetArch targetArch, int numberOfAssembliesInApk, ICollection<string> uniqueAssemblyNames)
: base (log)
{
this.targetArch = targetArch;
this.numberOfAssembliesInApk = numberOfAssembliesInApk;
Expand All @@ -256,9 +256,9 @@ public MarshalMethodsNativeAssemblyGenerator (AndroidTargetArch targetArch, int
/// <summary>
/// Constructor to be used ONLY when marshal methods are ENABLED
/// </summary>
public MarshalMethodsNativeAssemblyGenerator (TaskLoggingHelper logger, int numberOfAssembliesInApk, ICollection<string> uniqueAssemblyNames, NativeCodeGenState codeGenState)
public MarshalMethodsNativeAssemblyGenerator (TaskLoggingHelper log, int numberOfAssembliesInApk, ICollection<string> uniqueAssemblyNames, NativeCodeGenState codeGenState)
: base (log)
{
this.logger = logger ?? throw new ArgumentNullException (nameof (logger));
this.numberOfAssembliesInApk = numberOfAssembliesInApk;
this.uniqueAssemblyNames = uniqueAssemblyNames ?? throw new ArgumentNullException (nameof (uniqueAssemblyNames));
this.codeGenState = codeGenState ?? throw new ArgumentNullException (nameof (codeGenState));
Expand Down Expand Up @@ -308,7 +308,7 @@ void Init ()
foreach (IList<MarshalMethodEntry> entryList in marshalMethods.Values) {
bool useFullNativeSignature = entryList.Count > 1;
foreach (MarshalMethodEntry entry in entryList) {
logger.LogDebugMessage ($"MM: processing {entry.DeclaringType.FullName} {entry.NativeCallback.FullName}");
Log.LogDebugMessage ($"MM: processing {entry.DeclaringType.FullName} {entry.NativeCallback.FullName}");
ProcessAndAddMethod (allMethods, entry, useFullNativeSignature, seenClasses, overloadedNativeSymbolNames);
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ void Init ()

foreach (MarshalMethodInfo method in allMethods) {
if (seenNativeSymbols.Contains (method.NativeSymbolName)) {
logger.LogDebugMessage ($"Removed MM duplicate '{method.NativeSymbolName}' (implemented: {method.Method.ImplementedMethod.FullName}; registered: {method.Method.RegisteredMethod.FullName}");
Log.LogDebugMessage ($"Removed MM duplicate '{method.NativeSymbolName}' (implemented: {method.Method.ImplementedMethod.FullName}; registered: {method.Method.RegisteredMethod.FullName}");
continue;
}

Expand Down Expand Up @@ -658,7 +658,7 @@ void AddMarshalMethods (LlvmIrModule module, AssemblyCacheState acs, LlvmIrVaria

void AddMarshalMethod (LlvmIrModule module, MarshalMethodInfo method, ulong asmId, MarshalMethodsWriteState writeState)
{
logger.LogDebugMessage ($"MM: generating code for {method.Method.DeclaringType.FullName} {method.Method.NativeCallback.FullName}");
Log.LogDebugMessage ($"MM: generating code for {method.Method.DeclaringType.FullName} {method.Method.NativeCallback.FullName}");
CecilMethodDefinition nativeCallback = method.Method.NativeCallback;
string backingFieldName = $"native_cb_{method.Method.JniMethodName}_{asmId}_{method.ClassCacheIndex}_{nativeCallback.MetadataToken.ToUInt32():x}";

Expand Down
29 changes: 27 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Utilities/NativeTypeMappingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Collections.Generic;
using System.Linq;

using Microsoft.Build.Utilities;
using Microsoft.Android.Build.Tasks;

namespace Xamarin.Android.Tasks
{
class NativeTypeMappingData
Expand All @@ -12,7 +15,7 @@ class NativeTypeMappingData
public uint MapModuleCount { get; }
public uint JavaTypeCount { get; }

public NativeTypeMappingData (TypeMapGenerator.ModuleReleaseData[] modules)
public NativeTypeMappingData (TaskLoggingHelper log, TypeMapGenerator.ModuleReleaseData[] modules)
{
Modules = modules ?? throw new ArgumentNullException (nameof (modules));

Expand All @@ -21,15 +24,37 @@ public NativeTypeMappingData (TypeMapGenerator.ModuleReleaseData[] modules)
var tempJavaTypes = new Dictionary<string, TypeMapGenerator.TypeMapReleaseEntry> (StringComparer.Ordinal);
var moduleComparer = new TypeMapGenerator.ModuleUUIDArrayComparer ();

TypeMapGenerator.ModuleReleaseData? monoAndroid = null;
foreach (TypeMapGenerator.ModuleReleaseData data in modules) {
if (data.AssemblyName == "Mono.Android") {
monoAndroid = data;
break;
}
}

if (monoAndroid != null) {
ProcessModule (monoAndroid);
}

foreach (TypeMapGenerator.ModuleReleaseData data in modules) {
if (data.AssemblyName == "Mono.Android") {
continue;
}
ProcessModule (data);
};

void ProcessModule (TypeMapGenerator.ModuleReleaseData data)
{
int moduleIndex = Array.BinarySearch (modules, data, moduleComparer);
if (moduleIndex < 0)
throw new InvalidOperationException ($"Unable to map module with MVID {data.Mvid} to array index");

foreach (TypeMapGenerator.TypeMapReleaseEntry entry in data.Types) {
entry.ModuleIndex = moduleIndex;
if (tempJavaTypes.ContainsKey (entry.JavaName))
if (tempJavaTypes.ContainsKey (entry.JavaName)) {
log.LogDebugMessage ($"Skipping typemap entry for `{entry.ManagedTypeName}, {data.AssemblyName}`; `{entry.JavaName}` is already mapped.");
continue;
}
tempJavaTypes.Add (entry.JavaName, entry);
}
}
Expand Down
Loading

0 comments on commit 2a67bee

Please sign in to comment.