[release/9.0.1xx-preview7] Enable dedup only when targeting ARM64 mobile platforms (#20951)

## Description

Previous fix https://github.com/xamarin/xamarin-macios/pull/20941 did
not take into account that when we target non arm64 apple mobile
platforms we are using `MONO_AOT_MODE_INTERP_ONLY` which cannot use
dedup optimization as it discards AOT images during runtime (as noted
in: https://github.com/xamarin/xamarin-macios/pull/20945).

## Changes

- Enable dedup only when targeting ARM64
- Fix tests to cover builds for both ARM64 and X64 builds

Finally, the change was tested against MAUI iossimulator-x64 template
app
This commit is contained in:
Ivan Povazan 2024-07-30 13:14:34 +02:00 коммит произвёл GitHub
Родитель 4b65c7941d
Коммит 0eed6bd305
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 56 добавлений и 21 удалений

Просмотреть файл

@ -1098,7 +1098,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>
<_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true' And '$(TargetArchitectures)' == 'ARM64'">true</_IsDedupEnabled>
<_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll</_DedupAssembly>
<!-- default to 'static' for Mac Catalyst to work around https://github.com/xamarin/xamarin-macios/issues/14686 -->

Просмотреть файл

@ -2019,18 +2019,12 @@ namespace Xamarin.Tests {
}
[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.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all,System.Private.CoreLib")]
[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;", "")]
[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";
@ -2045,15 +2039,56 @@ namespace Xamarin.Tests {
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");
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");
} else {
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")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "all,-System.Private.CoreLib")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "")]
public void DedupUniversalAppTest (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);
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");
var appExecutable = GetNativeExecutable (platform, appPath);