diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index a4c538743c2..9fa75da013d 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1106,7 +1106,7 @@ In such setup, during runtime, AOT images are loaded but marked as unusuable as they are compiled with `full` compiler switch and the code fallsback to interpreter. Dedup AOT image is specially handled by the AOT runtime and it is not allowed to have it marked as unusuable. --> - <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true' And '$(RuntimeIdentifier)' != 'maccatalyst-x64'">true + <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true' And '$(TargetArchitectures)' == 'ARM64'">true <_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 98925418cdd..e886797aa0c 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -1958,19 +1958,58 @@ bool FindAOTedAssemblyFile (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.iOS, "ios-arm64;", "-all")] - [TestCase (ApplePlatform.iOS, "ios-arm64;", "")] + [TestCase (ApplePlatform.iOS, "ios-arm64", "-all,System.Private.CoreLib")] + [TestCase (ApplePlatform.iOS, "ios-arm64", "all,-System.Private.CoreLib")] + [TestCase (ApplePlatform.iOS, "ios-arm64", "")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64", "-all,System.Private.CoreLib")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64", "all,-System.Private.CoreLib")] + [TestCase (ApplePlatform.TVOS, "tvos-arm64", "")] + public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) + { + var project = "MySimpleApp"; + Configuration.IgnoreIfIgnoredPlatform (platform); + Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers); + + var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); + Clean (project_path); + var properties = GetDefaultProperties (runtimeIdentifiers); + properties ["MtouchInterpreter"] = $"\"{mtouchInterpreter}\""; + + DotNet.AssertBuild (project_path, properties); + + var objDir = GetObjDir (project_path, platform, runtimeIdentifiers); + Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: {runtimeIdentifiers}"); + } + + [Test] + [TestCase (ApplePlatform.iOS, "iossimulator-x64", "-all,System.Private.CoreLib")] + [TestCase (ApplePlatform.iOS, "iossimulator-x64", "all,-System.Private.CoreLib")] + [TestCase (ApplePlatform.iOS, "iossimulator-x64", "")] + [TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "-all,System.Private.CoreLib")] + [TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "all,-System.Private.CoreLib")] + [TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "")] + public void DedupDisabledTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) + { + var project = "MySimpleApp"; + Configuration.IgnoreIfIgnoredPlatform (platform); + Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers); + + var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath); + Clean (project_path); + var properties = GetDefaultProperties (runtimeIdentifiers); + properties ["MtouchInterpreter"] = $"\"{mtouchInterpreter}\""; + + DotNet.AssertBuild (project_path, properties); + + var objDir = GetObjDir (project_path, platform, runtimeIdentifiers); + Assert.False (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), $"Dedup optimization should not be enabled for AOT compilation on: {platform} with RID: {runtimeIdentifiers}"); + } + + [Test] // [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")] - [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "-all")] - [TestCase (ApplePlatform.TVOS, "tvos-arm64;", "")] - public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) + public void DedupUniversalAppTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter) { var project = "MySimpleApp"; Configuration.IgnoreIfIgnoredPlatform (platform); @@ -1984,15 +2023,11 @@ public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers, DotNet.AssertBuild (project_path, properties); var objDir = GetObjDir (project_path, platform, runtimeIdentifiers); - if (platform == ApplePlatform.MacCatalyst) { - var objDirMacCatalystArm64 = Path.Combine (objDir, "maccatalyst-arm64"); - Assert.True (FindAOTedAssemblyFile (objDirMacCatalystArm64, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: maccatalyst-arm64"); + var objDirMacCatalystArm64 = Path.Combine (objDir, "maccatalyst-arm64"); + Assert.True (FindAOTedAssemblyFile (objDirMacCatalystArm64, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: maccatalyst-arm64"); - var objDirMacCatalystx64 = Path.Combine (objDir, "maccatalyst-x64"); - Assert.False (FindAOTedAssemblyFile (objDirMacCatalystx64, "aot-instances.dll"), $"Dedup optimization should not be enabled for AOT compilation on: {platform} with RID: maccatalyst-x64"); - } else { - Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: {runtimeIdentifiers}"); - } + var objDirMacCatalystx64 = Path.Combine (objDir, "maccatalyst-x64"); + Assert.False (FindAOTedAssemblyFile (objDirMacCatalystx64, "aot-instances.dll"), $"Dedup optimization should not be enabled for AOT compilation on: {platform} with RID: maccatalyst-x64"); var appExecutable = GetNativeExecutable (platform, appPath);