Skip to content

crossgen2 doesn't resolve compilers for non-portable rids #28312

@tmds

Description

@tmds

I'm trying to make runtime repo build using artifacts produced for a non-portable rid in dotnet/runtime#75597.

The build fails while trying to resolve the R2R compiler:

  13:47:14.530    19>Target "ResolveReadyToRunCompilers: (TargetId:2247)" in file "/home/tmds/sdk/sdk/7.0.100-rtm.22478.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets" from project "/home/tmds/tarball41/src/runtime/artifacts/source-build/self/src/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj" (target "_PrepareForReadyToRunCompilation" depends on it):
                     Using "ResolveReadyToRunCompilers" task from assembly "/home/tmds/sdk/sdk/7.0.100-rtm.22478.1/Sdks/Microsoft.NET.Sdk/targets/../tools/net7.0/Microsoft.NET.Build.Tasks.dll".
                     Task "ResolveReadyToRunCompilers" (TaskId:1425)
                       Task Parameter:ReadyToRunUseCrossgen2=True (TaskId:1425)
                       Task Parameter:
                           TargetingPacks=
                               Microsoft.NETCore.App
                                       NuGetPackageId=Microsoft.NETCore.App.Ref
                                       NuGetPackageVersion=7.0.0-rtm.22465.3
                                       PackageConflictPreferredPackages=Microsoft.NETCore.App.Ref;Microsoft.NETCore.App.Runtime.fedora.36-x64
                                       PackageDirectory=/home/tmds/sdk/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22465.3
                                       Path=/home/tmds/sdk/packs/Microsoft.NETCore.App.Ref/7.0.0-rtm.22465.3
                                       RuntimeFrameworkName=Microsoft.NETCore.App
                                       RuntimePackRuntimeIdentifiers=fedora.36-x64
                                       TargetFramework=net7.0
                                       TargetingPackFormat= (TaskId:1425)
                       Task Parameter:NETCoreSdkRuntimeIdentifier=fedora.36-x64 (TaskId:1425)
                       Task Parameter:
                           Crossgen2Packs=
                               Microsoft.NETCore.App.Crossgen2.fedora.36-x64
                                       NuGetPackageId=Microsoft.NETCore.App.Crossgen2.fedora.36-x64
                                       NuGetPackageVersion=7.0.0-rtm.22465.3
                                       OriginalItemSpec=Microsoft.NETCore.App.Crossgen2.fedora.36-x64
                                       PackageDirectory=/home/tmds/tarball41/src/runtime/artifacts/source-build/self/package-cache/microsoft.netcore.app.crossgen2.fedora.36-x64/7.0.0-rtm.22465.3 (TaskId:1425)
                       Task Parameter:
                           RuntimePacks=
                               Microsoft.NETCore.App.Runtime.fedora.36-x64
                                       FrameworkName=Microsoft.NETCore.App
                                       IsTrimmable=
                                       NuGetPackageId=Microsoft.NETCore.App.Runtime.fedora.36-x64
                                       NuGetPackageVersion=7.0.0-rtm.22465.3
                                       OriginalItemSpec=Microsoft.NETCore.App.Runtime.fedora.36-x64
                                       PackageDirectory=/home/tmds/tarball41/src/runtime/artifacts/source-build/self/package-cache/microsoft.netcore.app.runtime.fedora.36-x64/7.0.0-rtm.22465.3
                                       RuntimeIdentifier=fedora.36-x64 (TaskId:1425)
                       Task Parameter:PerfmapFormatVersion=1 (TaskId:1425)
                       Task Parameter:RuntimeGraphPath=/home/tmds/tarball41/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json (TaskId:1425)
  13:47:14.535    19>/home/tmds/sdk/sdk/7.0.100-rtm.22478.1/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(299,5): error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false. [/home/tmds/tarball41/src/runtime/artifacts/source-build/self/src/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj]

Looking at the code in ResolveReadyToRunCompilers.cs, it looks like isSupportedTarget will be false because targetOS is will be null for a non-portable rid:

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
isSupportedTarget = isSupportedTarget &&
targetOS != null &&
(!version5 || _targetRuntimeIdentifier == _hostRuntimeIdentifier) &&
GetCrossgen2ComponentsPaths(version5);

cc @ViktorHofer @hoyosjs @AntonLapounov

How can we update this code so it works for non-portable rids?

Metadata

Metadata

Assignees

Labels

untriagedRequest triage from a team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions