Skip to content

Commit

Permalink
Derive _targetOS from RuntimeIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Feb 25, 2023
1 parent bfde05f commit ae475ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

<PropertyGroup Condition="'$(RuntimeIdentifier)' != '' and '$(NETCoreSdkPortableRuntimeIdentifier)' != ''">
<!-- Define the name of the runtime specific compiler package to import -->
<_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.IndexOf('-'))))</_hostOS>
<_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))))</_hostOS>

<_useTPI Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'unix'">true</_useTPI>
<_targetOS Condition="'$(_useTPI)' == 'true'">$(TargetPlatformIdentifier.ToLowerInvariant)</_targetOS>
<_targetOS Condition="'$(_useTPI)' != 'true'">$(_hostOS)</_targetOS>
<_targetOS>$(RuntimeIdentifier.SubString(0, $(RuntimeIdentifier.LastIndexOf('-'))))</_targetOS>
<_indexOfPeriod>$(_targetOS.IndexOf('.'))</_indexOfPeriod>
<_targetOS Condition="'$(_indexOfPeriod)' &gt; -1">$(_targetOS.SubString(0, $(_indexOfPeriod)))</_targetOS>
<_targetOS Condition="$(_targetOS.StartsWith('win'))">win</_targetOS>

<!-- On non-Windows, determine _hostArchitecture from NETCoreSdkPortableRuntimeIdentifier -->
<_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1))))</_hostArchitecture>
<!-- On Windows, default to host that matches OS architecture on Windows. It allows compilation using msbuild.exe that is x86 by default -->
<_hostArchitecture Condition="'$(OS)' == 'Windows_NT'>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant)</_hostArchitecture>
<_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant)</_hostArchitecture>

<!-- Determine _targetArchitecture from RuntimeIdentifier -->
<_targetArchitecture>$(RuntimeIdentifier.SubString($([MSBuild]::Add($(RuntimeIdentifier.LastIndexOf('-')), 1))))</_targetArchitecture>

<_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler</_hostPackageName>
<_targetPackageName>runtime.$(_targetOS)-$(_targetArchitecture).Microsoft.DotNet.ILCompiler</_targetPackageName>
<_targetPackageName>runtime.$(_targetOSPkg)-$(_targetArchitecture).Microsoft.DotNet.ILCompiler</_targetPackageName>

<!-- From this point onwards, we will treat linux-musl as linux -->
<_targetOS Condition="$(_targetOS.StartsWith('linux'))">linux</_targetOS>

<IlcCalledViaPackage>true</IlcCalledViaPackage>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Error Condition="'$(DisableUnsupportedError)' != 'true' and !('$(_hostArchitecture)' == 'x64' or '$(_hostArchitecture)' == 'arm64')"
Text="Native compilation can run on x64 and arm64 hosts only." />

<Error Condition="'$(IlcHostPackagePath)' == '' and '$(RuntimePackagePath)' != '' and ('$(_hostArchitecture)' == 'x64' or '$(_hostArchitecture)' == 'arm64')"
<Error Condition="'$(_hostPackageName)' == '' and '$(RuntimePackagePath)' != '' and ('$(_hostArchitecture)' == 'x64' or '$(_hostArchitecture)' == 'arm64')"
Text="Add a PackageReference for '$(_hostPackageName)' to allow cross-compilation for $(_targetArchitecture)" />

<!-- NativeAOT runtime pack assemblies need to be defined to avoid the default CoreCLR implementations being set as compiler inputs -->
Expand Down

0 comments on commit ae475ce

Please sign in to comment.