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

ILCompiler: support publishing using a non-portable ILCompiler build. #99148

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<!-- Define the name of the runtime specific compiler package to import -->
<_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))))</_hostOS>

<_targetsNonPortableSdkRid>false</_targetsNonPortableSdkRid>
<_targetsNonPortableSdkRid Condition="'$(RuntimeIdentifier)' == '$(NETCoreSdkRuntimeIdentifier)' and '$(RuntimeIdentifier)' != '$(NETCoreSdkPortableRuntimeIdentifier)'">true</_targetsNonPortableSdkRid>
tmds marked this conversation as resolved.
Show resolved Hide resolved

<_originalTargetOS>$(RuntimeIdentifier.SubString(0, $(RuntimeIdentifier.LastIndexOf('-'))))</_originalTargetOS>
<_originalTargetOS Condition="'$(_targetsNonPortableSdkRid)' == 'true'">$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))))</_originalTargetOS>
<_originalTargetOS Condition="$(_originalTargetOS.Contains('.'))">$(_originalTargetOS.SubString(0, $(_originalTargetOS.IndexOf('.'))))</_originalTargetOS>
<_originalTargetOS Condition="$(_originalTargetOS.StartsWith('win'))">win</_originalTargetOS>

Expand All @@ -17,7 +21,9 @@
<_targetArchitecture>$(RuntimeIdentifier.SubString($([MSBuild]::Add($(RuntimeIdentifier.LastIndexOf('-')), 1))))</_targetArchitecture>

<_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler</_hostPackageName>
<_hostPackageName Condition="'$(_targetsNonPortableSdkRid)' == 'true'">runtime.$(RuntimeIdentifier).Microsoft.DotNet.ILCompiler</_hostPackageName>
<_targetPackageName>runtime.$(_originalTargetOS)-$(_targetArchitecture).Microsoft.DotNet.ILCompiler</_targetPackageName>
<_targetPackageName Condition="'$(_targetsNonPortableSdkRid)' == 'true'">runtime.$(RuntimeIdentifier).Microsoft.DotNet.ILCompiler</_targetPackageName>

<!-- Treat linux-musl and linux-bionic etc. as linux -->
<_targetOS>$(_originalTargetOS)</_targetOS>
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<!-- BEGIN: Workaround for https://github.com/dotnet/runtime/issues/67742 -->
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<PublishDir>$(RuntimeBinDir)ilc-published/</PublishDir>
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
<NativeAotSupported Condition="'$(DotNetBuildSourceOnly)' == 'true'">false</NativeAotSupported>
<NativeAotSupported Condition="$(OutputRID.StartsWith('tizen')) == 'true'">false</NativeAotSupported>
<NativeAotSupported Condition="$(OutputRID.EndsWith('-arm')) == 'true'">false</NativeAotSupported>
<!-- Disable native AOT on FreeBSD when cross building from Linux. -->
Expand All @@ -26,7 +24,7 @@
<_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))))</_hostOS>
tmds marked this conversation as resolved.
Show resolved Hide resolved
<_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1))))</_hostArchitecture>
tmds marked this conversation as resolved.
Show resolved Hide resolved
<_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant)</_hostArchitecture>
<_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler</_hostPackageName>
<_hostPackageName>runtime.$(ToolsRID).Microsoft.DotNet.ILCompiler</_hostPackageName>
tmds marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<!-- Can't use NativeAOT in non-portable build yet https://github.com/dotnet/runtime/issues/66859 -->
<NativeAotSupported Condition="'$(PortableBuild)' != 'true'">false</NativeAotSupported>
<NativeAotSupported Condition="$(OutputRID.StartsWith('tizen')) == 'true'">false</NativeAotSupported>
<NativeAotSupported Condition="$(OutputRID.EndsWith('-arm')) == 'true'">false</NativeAotSupported>
<!-- Publish crossgen2 as a single-file app on native-OS builds. Cross-OS NativeAOT compilation is not supported yet -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<OfficialBuildRID Include="win-x64" Platform="x64" />
<OfficialBuildRID Include="freebsd-x64" Platform="x64" />
<OfficialBuildRID Include="freebsd-arm64" Platform="arm64" />
<OfficialBuildRID Include="$(OutputRID)" Platform="$(TargetArchitecture)" Condition="'$(NativeAotSupported)' == 'true'" Exclude="@(OfficialBuildRID)" />
tmds marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
<ShouldVerifyClosure>false</ShouldVerifyClosure>
<!-- Publish crossgen2 as a single-file app on native-OS builds. Cross-OS NativeAOT compilation is not supported yet -->
<NativeAotSupported Condition="'$(CrossBuild)' == 'true' and '$(TargetOS)' != '$(HostOS)'">false</NativeAotSupported>
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
<NativeAotSupported Condition="'$(DotNetBuildSourceOnly)' == 'true'">false</NativeAotSupported>
</PropertyGroup>

<ItemGroup>
Expand All @@ -43,7 +41,7 @@
KeepMetadata="REMOVE_ALL" />
</ItemGroup>
<ItemGroup Condition="'$(NativeAotSupported)' != 'true'">
<FilesToPackage Include="@(_CrossgenPublishFiles)"
<FilesToPackage Include="@(_CrossgenPublishFiles->Distinct())"
tmds marked this conversation as resolved.
Show resolved Hide resolved
Exclude="*.pdb;*.h;*.lib"
TargetPath="tools/" />
</ItemGroup>
Expand Down
36 changes: 31 additions & 5 deletions src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using Microsoft.Build.Framework;
tmds marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Build.Utilities;
using NuGet.RuntimeModel;
using NuGet.Versioning;

namespace Microsoft.NET.Build.Tasks
Expand Down Expand Up @@ -111,8 +112,9 @@ private bool ValidateCrossgenSupport()
return false;
}

if (!ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) ||
!ExtractTargetPlatformAndArchitecture(_hostRuntimeIdentifier, out string hostPlatform, out _) ||
RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
if (!ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture) ||
!ExtractTargetPlatformAndArchitecture(runtimeGraph, _hostRuntimeIdentifier, out string hostPlatform, out _) ||
_targetPlatform != hostPlatform ||
!GetCrossgenComponentsPaths())
{
Expand Down Expand Up @@ -142,7 +144,8 @@ private bool ValidateCrossgen2Support()
}

bool version5 = crossgen2PackVersion.Major < 6;
bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(_targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture);
RuntimeGraph runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath);
bool isSupportedTarget = ExtractTargetPlatformAndArchitecture(runtimeGraph, _targetRuntimeIdentifier, out _targetPlatform, out _targetArchitecture);

// Normalize target OS for crossgen invocation
string targetOS = (_targetPlatform == "win") ? "windows" :
Expand Down Expand Up @@ -202,7 +205,7 @@ private static ITaskItem GetNETCoreAppPack(ITaskItem[] packs, string metadataKey
.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase));
}

private static bool ExtractTargetPlatformAndArchitecture(string runtimeIdentifier, out string platform, out Architecture architecture)
private static bool ExtractTargetPlatformAndArchitecture(RuntimeGraph runtimeGraph, string runtimeIdentifier, out string platform, out Architecture architecture)
{
platform = null;
architecture = default;
Expand Down Expand Up @@ -234,7 +237,30 @@ private static bool ExtractTargetPlatformAndArchitecture(string runtimeIdentifie
return false;
}

platform = runtimeIdentifier.Substring(0, separator).ToLowerInvariant();
string[] supportedRIDsList = [
$"linux-{architectureStr}",
$"win-{architectureStr}",
$"osx-{architectureStr}",
$"freebsd-{architectureStr}",
$"maccatalyst-{architectureStr}",
$"iossimulator-{architectureStr}",
$"ios-{architectureStr}",
$"tvossimulator-{architectureStr}",
$"tvos-{architectureStr}"
];

string platformRid = NuGetUtils.GetBestMatchingRid(
runtimeGraph,
runtimeIdentifier,
supportedRIDsList,
out _);

if (platformRid == null)
{
return false;
}

platform = platformRid.Substring(0, platformRid.LastIndexOf('-')).ToLowerInvariant();
return true;
}

Expand Down
Loading