From aea2bba5bdf86ac45cdaabaffb307c03c4d71c37 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Fri, 7 Oct 2022 08:31:58 +0200 Subject: [PATCH 1/2] ResolveReadyToRunCompilers: map non-portable rids when targetOS is determined. --- .../ResolveReadyToRunCompilers.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs index 716a7f37c3cf..6967822aca12 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs @@ -143,7 +143,15 @@ private bool ValidateCrossgen2Support() bool version5 = crossgen2PackVersion.Major < 6; bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); - string targetOS = _targetPlatform switch + + var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); + string portablePlatform = NuGetUtils.GetBestMatchingRid( + runtimeGraph, + _targetPlatform, + new[] { "linux", "linux-musl", "osx", "win" }, + out _); + + string targetOS = portablePlatform switch { "linux" => "linux", "linux-musl" => "linux", From 389ad51a7ed0998be6f4a9baa2746882e249451b Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Fri, 7 Oct 2022 13:39:54 +0200 Subject: [PATCH 2/2] For source-build, allow using a rid that is not in the graph if it matches the host rid. --- .../ResolveReadyToRunCompilers.cs | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs index 6967822aca12..5d21bc96e846 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs @@ -144,28 +144,13 @@ private bool ValidateCrossgen2Support() bool version5 = crossgen2PackVersion.Major < 6; bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture); - var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); - string portablePlatform = NuGetUtils.GetBestMatchingRid( - runtimeGraph, - _targetPlatform, - new[] { "linux", "linux-musl", "osx", "win" }, - out _); - - string targetOS = portablePlatform switch - { - "linux" => "linux", - "linux-musl" => "linux", - "osx" => "osx", - "win" => "windows", - _ => null - }; - // In .NET 5 Crossgen2 supported only the following host->target compilation scenarios: // win-x64 -> win-x64 // linux-x64 -> linux-x64 // linux-musl-x64 -> linux-musl-x64 + string targetOS = null; isSupportedTarget = isSupportedTarget && - targetOS != null && + GetCrossgen2TargetOS(out targetOS) && (!version5 || _targetRuntimeIdentifier == _hostRuntimeIdentifier) && GetCrossgen2ComponentsPaths(version5); @@ -196,6 +181,48 @@ private bool ValidateCrossgen2Support() return true; } + private bool GetCrossgen2TargetOS(out string targetOS) + { + targetOS = null; + + // Determine targetOS based on target rid. + // Use the runtime graph to support non-portable target rids. + var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); + string portablePlatform = NuGetUtils.GetBestMatchingRid( + runtimeGraph, + _targetPlatform, + new[] { "linux", "linux-musl", "osx", "win" }, + out _); + + // For source-build, allow the bootstrap SDK rid to be unknown to the runtime repo graph. + if (portablePlatform == null && _targetRuntimeIdentifier == _hostRuntimeIdentifier) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + portablePlatform = "linux"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + portablePlatform = "win"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + portablePlatform = "osx"; + } + } + + targetOS = portablePlatform switch + { + "linux" => "linux", + "linux-musl" => "linux", + "osx" => "osx", + "win" => "windows", + _ => null + }; + + return targetOS != null; + } + private ITaskItem GetNETCoreAppRuntimePack() { return GetNETCoreAppPack(RuntimePacks, MetadataKeys.FrameworkName);