Skip to content

Commit d454781

Browse files
committed
ResolveReadyToRunCompilers: map non-portable rids when targetOS is determined (backport dotnet#28380)
1 parent 79a92b4 commit d454781

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,14 @@ private bool ValidateCrossgen2Support()
143143

144144
bool version5 = crossgen2PackVersion.Major < 6;
145145
bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture);
146-
string targetOS = _targetPlatform switch
147-
{
148-
"linux" => "linux",
149-
"linux-musl" => "linux",
150-
"osx" => "osx",
151-
"win" => "windows",
152-
_ => null
153-
};
154146

155147
// In .NET 5 Crossgen2 supported only the following host->target compilation scenarios:
156148
// win-x64 -> win-x64
157149
// linux-x64 -> linux-x64
158150
// linux-musl-x64 -> linux-musl-x64
151+
string targetOS = null;
159152
isSupportedTarget = isSupportedTarget &&
160-
targetOS != null &&
153+
GetCrossgen2TargetOS(out targetOS) &&
161154
(!version5 || _targetRuntimeIdentifier == _hostRuntimeIdentifier) &&
162155
GetCrossgen2ComponentsPaths(version5);
163156

@@ -188,6 +181,48 @@ private bool ValidateCrossgen2Support()
188181
return true;
189182
}
190183

184+
private bool GetCrossgen2TargetOS(out string targetOS)
185+
{
186+
targetOS = null;
187+
188+
// Determine targetOS based on target rid.
189+
// Use the runtime graph to support non-portable target rids.
190+
var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
191+
string portablePlatform = NuGetUtils.GetBestMatchingRid(
192+
runtimeGraph,
193+
_targetPlatform,
194+
new[] { "linux", "linux-musl", "osx", "win" },
195+
out _);
196+
197+
// For source-build, allow the bootstrap SDK rid to be unknown to the runtime repo graph.
198+
if (portablePlatform == null && _targetRuntimeIdentifier == _hostRuntimeIdentifier)
199+
{
200+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
201+
{
202+
portablePlatform = "linux";
203+
}
204+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
205+
{
206+
portablePlatform = "win";
207+
}
208+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
209+
{
210+
portablePlatform = "osx";
211+
}
212+
}
213+
214+
targetOS = portablePlatform switch
215+
{
216+
"linux" => "linux",
217+
"linux-musl" => "linux",
218+
"osx" => "osx",
219+
"win" => "windows",
220+
_ => null
221+
};
222+
223+
return targetOS != null;
224+
}
225+
191226
private ITaskItem GetNETCoreAppRuntimePack()
192227
{
193228
return GetNETCoreAppPack(RuntimePacks, MetadataKeys.FrameworkName);

0 commit comments

Comments
 (0)