Skip to content

Commit

Permalink
Don't require there to be a supported runtime pack runtime identifier…
Browse files Browse the repository at this point in the history
… for crossgen2 (#45487)
  • Loading branch information
jkoritzinsky authored Jan 2, 2025
1 parent 4e1f5b3 commit 362c12d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ private ToolPackSupport AddToolPack(
runtimePackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
}

runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, hostRuntimeIdentifier);

switch (toolPackType)
{
case ToolPackType.Crossgen2:
Expand Down
52 changes: 36 additions & 16 deletions src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,7 @@ protected override void ExecuteCore()
_runtimePack = GetNETCoreAppRuntimePack();
_targetRuntimeIdentifier = _runtimePack?.GetMetadata(MetadataKeys.RuntimeIdentifier);

// Get the list of runtime identifiers that we support and can target
ITaskItem targetingPack = GetNETCoreAppTargetingPack();
string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);

var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
var supportedRIDsList = supportedRuntimeIdentifiers == null ? Array.Empty<string>() : supportedRuntimeIdentifiers.Split(';');

// Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
_hostRuntimeIdentifier = NuGetUtils.GetBestMatchingRid(
runtimeGraph,
NETCoreSdkRuntimeIdentifier,
supportedRIDsList,
out _);

if (_hostRuntimeIdentifier == null || _targetRuntimeIdentifier == null)
if (_targetRuntimeIdentifier == null)
{
Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
return;
Expand Down Expand Up @@ -96,6 +82,13 @@ protected override void ExecuteCore()

private bool ValidateCrossgenSupport()
{
_hostRuntimeIdentifier = GetHostRuntimeIdentifierForCrossgen();
if (_hostRuntimeIdentifier == null)
{
Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
return false;
}

_crossgenTool.PackagePath = _runtimePack?.GetMetadata(MetadataKeys.PackageDirectory);
if (_crossgenTool.PackagePath == null)
{
Expand All @@ -121,12 +114,39 @@ private bool ValidateCrossgenSupport()
}

return true;

string GetHostRuntimeIdentifierForCrossgen()
{
// Crossgen's host RID comes from the runtime pack that Crossgen will be loaded from.

// Get the list of runtime identifiers that we support and can target
ITaskItem targetingPack = GetNETCoreAppTargetingPack();
string supportedRuntimeIdentifiers = targetingPack?.GetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers);

var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
var supportedRIDsList = supportedRuntimeIdentifiers == null ? Array.Empty<string>() : supportedRuntimeIdentifiers.Split(';');

// Get the best RID for the host machine, which will be used to validate that we can run crossgen for the target platform and architecture
return NuGetUtils.GetBestMatchingRid(
runtimeGraph,
NETCoreSdkRuntimeIdentifier,
supportedRIDsList,
out _);
}
}

private bool ValidateCrossgen2Support()
{
ITaskItem crossgen2Pack = Crossgen2Packs?.FirstOrDefault();
_crossgen2Tool.PackagePath = crossgen2Pack?.GetMetadata(MetadataKeys.PackageDirectory);

_hostRuntimeIdentifier = crossgen2Pack?.GetMetadata(MetadataKeys.RuntimeIdentifier);
if (_hostRuntimeIdentifier == null)
{
Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError);
return false;
}

_crossgen2Tool.PackagePath = crossgen2Pack.GetMetadata(MetadataKeys.PackageDirectory);

if (string.IsNullOrEmpty(_crossgen2Tool.PackagePath) ||
!NuGetVersion.TryParse(crossgen2Pack.GetMetadata(MetadataKeys.NuGetPackageVersion), out NuGetVersion crossgen2PackVersion))
Expand Down

0 comments on commit 362c12d

Please sign in to comment.