diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 93a15695362a..f068e1edb036 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1099,8 +1099,9 @@ <_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/ <_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/ - - <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(MtouchInterpreter)' == '' And '$(IsMacEnabled)' == 'true'">true + + + <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true'">true <_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index cd4001996a4c..8f2e04ac500b 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -1945,10 +1945,11 @@ public void RaisesAppDomainUnhandledExceptionEvent (ApplePlatform platform) } } - bool FindAssembly (string path, string dllName) + bool FindAOTedAssemblyFile (string path, string dllName) { - foreach (string file in Directory.GetFiles (path, "*.dll", SearchOption.AllDirectories)) { - if (Path.GetFileName (file).Equals (dllName, StringComparison.OrdinalIgnoreCase)) { + var aotedAssemblyFileName = $"{dllName}.o"; + foreach (string file in Directory.GetFiles (path, "*.o", SearchOption.AllDirectories)) { + if (Path.GetFileName (file).Equals (aotedAssemblyFileName, StringComparison.OrdinalIgnoreCase)) { return true; } } @@ -1959,11 +1960,17 @@ bool FindAssembly (string path, string dllName) [Test] [TestCase (ApplePlatform.iOS, "ios-arm64;", "-all,System.Private.CoreLib")] [TestCase (ApplePlatform.iOS, "ios-arm64;", "all,-System.Private.CoreLib")] - [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all,System.Private.CoreLib")] + [TestCase (ApplePlatform.iOS, "ios-arm64;", "-all")] + [TestCase (ApplePlatform.iOS, "ios-arm64;", "")] + // [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all,System.Private.CoreLib")] // Should be reenalbed once https://github.com/dotnet/runtime/issues/105510 gets fixed [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "all,-System.Private.CoreLib")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "")] [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "-all,System.Private.CoreLib")] [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "all,-System.Private.CoreLib")] - public void PartialAOTTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) + [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "-all")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "")] + public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform (platform); @@ -1976,7 +1983,8 @@ public void PartialAOTTest (ApplePlatform platform, string runtimeIdentifiers, s DotNet.AssertBuild (project_path, properties); - Assert.True (!FindAssembly (appPath, "aot-instances.dll"), "Dedup optimization shouldn't been enabled for partial AOT compilation"); + var objDir = GetObjDir (project_path, platform, runtimeIdentifiers); + Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), "Dedup optimization should be always enabled for AOT compilation"); var appExecutable = GetNativeExecutable (platform, appPath); diff --git a/tools/common/Application.cs b/tools/common/Application.cs index 1ac9e9f1e9b1..385773aa1cab 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -1544,7 +1544,7 @@ public void GetAotArguments (string filename, Abi abi, string outputDir, string bool enable_debug = app.EnableDebug; bool enable_debug_symbols = app.PackageManagedDebugSymbols; bool llvm_only = app.EnableLLVMOnlyBitCode; - bool interp = app.IsInterpreted (Assembly.GetIdentity (filename)); + bool interp = app.IsInterpreted (Assembly.GetIdentity (filename)) && !(isDedupAssembly.HasValue && isDedupAssembly.Value); bool interp_full = !interp && app.UseInterpreter; bool is32bit = (abi & Abi.Arch32Mask) > 0; string arch = abi.AsArchString (); diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index c10924904059..e5197378050b 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -774,15 +774,17 @@ public void CopyConfigToDirectory (string directory) } } + public bool IsDedupAssembly { get; set; } = false; + public bool IsInterpreted { get { - return App.IsInterpreted (Identity); + return IsDedupAssembly ? false : App.IsInterpreted (Identity); } } public bool IsAOTCompiled { get { - return App.IsAOTCompiled (Identity); + return IsDedupAssembly ? true : App.IsAOTCompiled (Identity); } } } diff --git a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs index 366c3b11a7bc..2365fc18cfd7 100644 --- a/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs +++ b/tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Mono.Cecil; using Mono.Linker; @@ -28,6 +29,7 @@ protected override void TryProcessAssembly (AssemblyDefinition assembly) case AssemblyAction.Save: var ad = Configuration.Target.AddAssembly (assembly); var assemblyFileName = Configuration.GetAssemblyFileName (assembly); + ad.IsDedupAssembly = Path.GetFileName (Configuration.DedupAssembly).Equals (Path.GetFileName (assemblyFileName), StringComparison.OrdinalIgnoreCase); ad.FullPath = assemblyFileName; break; case AssemblyAction.AddBypassNGen: // This should be turned into Save or Delete