Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResolveReadyToRunCompilers: map non-portable rids when targetOS is determined. #28380

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,14 @@ private bool ValidateCrossgen2Support()

bool version5 = crossgen2PackVersion.Major < 6;
bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture);
string targetOS = _targetPlatform 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);

Expand Down Expand Up @@ -188,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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the initial bootstrap using Microsoft's SDK (e.g. linux-x64) further builds of source-build can use a non-portable SDK that was previously built (e.g. fedora.36-x64).

The runtime repo overwrites the BundledRuntimeIdentifierGraphFile to either the one it includes in its sources, or the one that it generates.

These graph files may not know the rid from the bootstrap SDK (e.g. fedora.36-x64).
(It will be known to the graph that is in the SDK.)

Rather than make the BundledRuntimeIdentifierGraphFile also use the SDK graph in some cases, I've opted to special case it here under _targetRuntimeIdentifier == _hostRuntimeIdentifier.

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);
Expand Down