From 9e47fc7dc317d2672a04eea297e7f3b1a8568b43 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Fri, 1 Mar 2024 06:10:10 +0100 Subject: [PATCH 1/5] ILCompiler: support publishing using a non-portable ILCompiler build. --- ...soft.DotNet.ILCompiler.SingleEntry.targets | 6 ++++ .../tools/aot/ILCompiler/ILCompiler.csproj | 4 +-- .../aot/crossgen2/crossgen2_publish.csproj | 2 -- .../ILCompilerRIDs.props | 1 + .../Microsoft.NETCore.App.Crossgen2.sfxproj | 4 +-- .../ResolveReadyToRunCompilers.cs | 36 ++++++++++++++++--- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets index 3a9c4d0153a7b1..62f159c5dc5268 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets @@ -4,7 +4,11 @@ <_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')))) + <_targetsNonPortableSdkRid>false + <_targetsNonPortableSdkRid Condition="'$(RuntimeIdentifier)' == '$(NETCoreSdkRuntimeIdentifier)' and '$(RuntimeIdentifier)' != '$(NETCoreSdkPortableRuntimeIdentifier)'">true + <_originalTargetOS>$(RuntimeIdentifier.SubString(0, $(RuntimeIdentifier.LastIndexOf('-')))) + <_originalTargetOS Condition="'$(_targetsNonPortableSdkRid)' == 'true'">$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')))) <_originalTargetOS Condition="$(_originalTargetOS.Contains('.'))">$(_originalTargetOS.SubString(0, $(_originalTargetOS.IndexOf('.')))) <_originalTargetOS Condition="$(_originalTargetOS.StartsWith('win'))">win @@ -17,7 +21,9 @@ <_targetArchitecture>$(RuntimeIdentifier.SubString($([MSBuild]::Add($(RuntimeIdentifier.LastIndexOf('-')), 1)))) <_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler + <_hostPackageName Condition="'$(_targetsNonPortableSdkRid)' == 'true'">runtime.$(RuntimeIdentifier).Microsoft.DotNet.ILCompiler <_targetPackageName>runtime.$(_originalTargetOS)-$(_targetArchitecture).Microsoft.DotNet.ILCompiler + <_targetPackageName Condition="'$(_targetsNonPortableSdkRid)' == 'true'">runtime.$(RuntimeIdentifier).Microsoft.DotNet.ILCompiler <_targetOS>$(_originalTargetOS) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index bea5a3d9dd80a4..9498ac3066c42b 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -10,8 +10,6 @@ $(RuntimeBinDir)ilc-published/ - - false false false @@ -26,7 +24,7 @@ <_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')))) <_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1)))) <_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant) - <_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler + <_hostPackageName>runtime.$(ToolsRID).Microsoft.DotNet.ILCompiler diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj index 522561c9c8a366..984ca91f13a7dd 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj +++ b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj @@ -7,8 +7,6 @@ - - false false false diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props index ffec11de57b317..4930993e9f3874 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props @@ -14,5 +14,6 @@ + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj index c3fd9eab49047f..f2bf8d9b233b63 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj @@ -21,8 +21,6 @@ false false - - false @@ -43,7 +41,7 @@ KeepMetadata="REMOVE_ALL" /> - diff --git a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs index ced9becf153a77..a4e3e5361a0c2e 100644 --- a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs +++ b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs @@ -9,6 +9,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using NuGet.RuntimeModel; using NuGet.Versioning; namespace Microsoft.NET.Build.Tasks @@ -111,8 +112,9 @@ private bool ValidateCrossgenSupport() return false; } - if (!ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) || - !ExtractTargetPlatformAndArchitecture(_hostRuntimeIdentifier, out string hostPlatform, out _) || + RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); + if (!ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) || + !ExtractTargetPlatformAndArchitecture(runtimeGraph, _hostRuntimeIdentifier, out string hostPlatform, out _) || _targetPlatform != hostPlatform || !GetCrossgenComponentsPaths()) { @@ -142,7 +144,8 @@ private bool ValidateCrossgen2Support() } bool version5 = crossgen2PackVersion.Major < 6; - bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); + RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); + bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); // Normalize target OS for crossgen invocation string targetOS = (_targetPlatform == "win") ? "windows" : @@ -202,7 +205,7 @@ private static ITaskItem GetNETCoreAppPack(ITaskItem[] packs, string metadataKey .Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)); } - private static bool ExtractTargetPlatformAndArchitecture(string runtimeIdentifier, out string platform, out Architecture architecture) + private static bool ExtractTargetPlatformAndArchitecture(RuntimeGraph runtimeGraph, string runtimeIdentifier, out string platform, out Architecture architecture) { platform = null; architecture = default; @@ -234,7 +237,30 @@ private static bool ExtractTargetPlatformAndArchitecture(string runtimeIdentifie return false; } - platform = runtimeIdentifier.Substring(0, separator).ToLowerInvariant(); + string[] supportedRIDsList = [ + $"linux-{architectureStr}", + $"win-{architectureStr}", + $"osx-{architectureStr}", + $"freebsd-{architectureStr}", + $"maccatalyst-{architectureStr}", + $"iossimulator-{architectureStr}", + $"ios-{architectureStr}", + $"tvossimulator-{architectureStr}", + $"tvos-{architectureStr}" + ]; + + string platformRid = NuGetUtils.GetBestMatchingRid( + runtimeGraph, + runtimeIdentifier, + supportedRIDsList, + out _); + + if (platformRid == null) + { + return false; + } + + platform = platformRid.Substring(0, platformRid.LastIndexOf('-')).ToLowerInvariant(); return true; } From f1ac55b45808d585bd8a171149162581dcd7d87d Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 4 Mar 2024 11:02:04 +0100 Subject: [PATCH 2/5] Remove unnecessary changes. --- .../ILCompilerRIDs.props | 2 +- .../ResolveReadyToRunCompilers.cs | 36 +++---------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props index 4930993e9f3874..7c32807ea03ffb 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props @@ -14,6 +14,6 @@ - + diff --git a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs index a4e3e5361a0c2e..ced9becf153a77 100644 --- a/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs +++ b/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs @@ -9,7 +9,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using NuGet.RuntimeModel; using NuGet.Versioning; namespace Microsoft.NET.Build.Tasks @@ -112,9 +111,8 @@ private bool ValidateCrossgenSupport() return false; } - RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); - if (!ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) || - !ExtractTargetPlatformAndArchitecture(runtimeGraph, _hostRuntimeIdentifier, out string hostPlatform, out _) || + if (!ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) || + !ExtractTargetPlatformAndArchitecture(_hostRuntimeIdentifier, out string hostPlatform, out _) || _targetPlatform != hostPlatform || !GetCrossgenComponentsPaths()) { @@ -144,8 +142,7 @@ private bool ValidateCrossgen2Support() } bool version5 = crossgen2PackVersion.Major < 6; - RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); - bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); + bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); // Normalize target OS for crossgen invocation string targetOS = (_targetPlatform == "win") ? "windows" : @@ -205,7 +202,7 @@ private static ITaskItem GetNETCoreAppPack(ITaskItem[] packs, string metadataKey .Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)); } - private static bool ExtractTargetPlatformAndArchitecture(RuntimeGraph runtimeGraph, string runtimeIdentifier, out string platform, out Architecture architecture) + private static bool ExtractTargetPlatformAndArchitecture(string runtimeIdentifier, out string platform, out Architecture architecture) { platform = null; architecture = default; @@ -237,30 +234,7 @@ private static bool ExtractTargetPlatformAndArchitecture(RuntimeGraph runtimeGra return false; } - string[] supportedRIDsList = [ - $"linux-{architectureStr}", - $"win-{architectureStr}", - $"osx-{architectureStr}", - $"freebsd-{architectureStr}", - $"maccatalyst-{architectureStr}", - $"iossimulator-{architectureStr}", - $"ios-{architectureStr}", - $"tvossimulator-{architectureStr}", - $"tvos-{architectureStr}" - ]; - - string platformRid = NuGetUtils.GetBestMatchingRid( - runtimeGraph, - runtimeIdentifier, - supportedRIDsList, - out _); - - if (platformRid == null) - { - return false; - } - - platform = platformRid.Substring(0, platformRid.LastIndexOf('-')).ToLowerInvariant(); + platform = runtimeIdentifier.Substring(0, separator).ToLowerInvariant(); return true; } From 44b1489727afff51db743794e7e368630666879f Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Tue, 5 Mar 2024 13:56:26 +0100 Subject: [PATCH 3/5] PR feedback. --- src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj | 5 ++--- .../Microsoft.NETCore.App.Crossgen2.sfxproj | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index 9498ac3066c42b..acebe7f0921309 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -20,16 +20,15 @@ true true true - + <_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')))) <_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1)))) <_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant) - <_hostPackageName>runtime.$(ToolsRID).Microsoft.DotNet.ILCompiler - + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj index f2bf8d9b233b63..40c864557ea055 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj @@ -41,7 +41,7 @@ KeepMetadata="REMOVE_ALL" /> - From 1bcdc49a50b0912260bbf42541ae32919b9bcbc1 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Wed, 6 Mar 2024 10:32:59 +0100 Subject: [PATCH 4/5] Use HostOS from top-level Directory.Build.props. --- src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index acebe7f0921309..9343a194bd31ba 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -20,8 +20,7 @@ true true true - - <_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')))) + <_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1)))) <_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant) @@ -90,7 +89,7 @@ - + Date: Wed, 6 Mar 2024 10:36:19 +0100 Subject: [PATCH 5/5] And same for BuildArchitecture. --- src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index 9343a194bd31ba..8ff84a80532c15 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -20,9 +20,6 @@ true true true - - <_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1)))) - <_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant) @@ -89,7 +86,7 @@ - +