Skip to content

Commit

Permalink
Workaround MVIDs from dotnet/linker
Browse files Browse the repository at this point in the history
Context: dotnet/runtime#45649
Context: dotnet/linker#2203

We are getting unique MVIDs per architecture output from the linker.

To workaround this problem, I used the "size" of the files instead. This works for now, but is not 100% correct. I think it would be fine for .NET 7 Android apps to use this for now in main. (hopefully temporary)
  • Loading branch information
jonathanpeppers committed Mar 31, 2022
1 parent f1ead79 commit 59a2630
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,16 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
{
// Group by assembly file name
foreach (var group in InputAssemblies.Where (Filter).GroupBy (a => Path.GetFileName (a.ItemSpec))) {
// Get the unique list of MVIDs
var mvids = new HashSet<Guid> ();
// HACK: Use file size instead of MVID, revert this later!
// see: https://github.com/dotnet/runtime/issues/45649
// see: https://github.com/dotnet/linker/issues/2203
var fileSizes = new HashSet<long> ();
bool? frameworkAssembly = null, hasMonoAndroidReference = null;
foreach (var assembly in group) {
using var pe = new PEReader (File.OpenRead (assembly.ItemSpec));
using var stream = File.OpenRead (assembly.ItemSpec);
using var pe = new PEReader (stream);
var reader = pe.GetMetadataReader ();
var module = reader.GetModuleDefinition ();
var mvid = reader.GetGuid (module.Mvid);
mvids.Add (mvid);
fileSizes.Add (stream.Length);

// Calculate %(FrameworkAssembly) and %(HasMonoAndroidReference) for the first
if (frameworkAssembly == null) {
Expand All @@ -144,7 +145,7 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
assembly.SetMetadata ("HasMonoAndroidReference", hasMonoAndroidReference.ToString ());
}
// If we end up with more than 1 unique mvid, we need *all* assemblies
if (mvids.Count > 1) {
if (fileSizes.Count > 1) {
foreach (var assembly in group) {
var symbol = GetOrCreateSymbolItem (symbols, assembly);
SetDestinationSubDirectory (assembly, group.Key, symbol, isDuplicate: true);
Expand Down

0 comments on commit 59a2630

Please sign in to comment.