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

Publish crossgen as AOT if supported by the target platform #65948

Merged
merged 35 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1c237a9
Typo
agocke Feb 26, 2022
b3435c2
Publish crossgen as AOT if supported, and self-contained otherwise
agocke Feb 28, 2022
800b2d3
Remove debugging property
agocke Feb 28, 2022
2509e2f
Use CoreCLRArtifactsPath from liveBuild
agocke Mar 2, 2022
6a1c6ff
Fold crossgen_publish into crossgen
agocke Mar 3, 2022
bdc0042
Try to refactor targets
agocke Mar 3, 2022
b4b7721
Remove special PublishToDisk impl
agocke Mar 4, 2022
593dc27
Call restore in installer
agocke Mar 4, 2022
449fbf4
Hook more properties for installer partition
agocke Mar 4, 2022
c3b6fba
Use diasymreader copy from artifacts when publishing
agocke Mar 4, 2022
e210695
Fix Linux packaging
agocke Mar 4, 2022
69ae018
Include netfx facades in the crossgen toolpack
agocke Mar 5, 2022
a52f4ca
Disable crossgen package building on freebsd
agocke Mar 11, 2022
3fe8a1d
Adjust R2R logic and skip verification of Windows assemblies on non-w…
agocke Mar 12, 2022
4c3f31a
Move conditional exclusion just to WindowsDesktop libraries
agocke Mar 13, 2022
07c2f6c
Also include windows desktop
agocke Mar 13, 2022
f2f45e6
Always build pre-test for source build as well
agocke Mar 13, 2022
35fa89a
Use the coreclr centos version for sourcebuild since it has NativeAOT…
agocke Mar 15, 2022
5a8df96
Revert "Use the coreclr centos version for sourcebuild since it has N…
agocke Mar 15, 2022
497836e
Add -lssl -lcrypto to NativeAOT linking on Unix
agocke Mar 15, 2022
9897beb
Merge remote-tracking branch 'upstream/main' into crossgen-publish
agocke Mar 17, 2022
acb5fd5
Add testing step after publish
agocke Mar 16, 2022
9290f87
Include extension in check
agocke Mar 18, 2022
94c4545
Disable NativeAOT use in source build
agocke Mar 18, 2022
349dccc
Use OS and arch check instead of CrossBuild flag
agocke Mar 23, 2022
6333ee4
Respond to PR comments and skip verifying closure
agocke Mar 25, 2022
a8e28d0
Respond to PR comments
agocke Mar 29, 2022
4445b93
Set Configuration in sfxproj
agocke Mar 30, 2022
ff7c339
Remove Configuration set from sfxproj
agocke Mar 30, 2022
b897d68
Merge remote-tracking branch 'upstream/main' into crossgen-publish
agocke Mar 30, 2022
1e111f5
Disable NativeAOT for MacOS
agocke Mar 31, 2022
8553fee
Work around MacOS problem with single-file
agocke Mar 31, 2022
d8eeb9e
re-enable single-file
agocke Mar 31, 2022
f682eae
Copy over the S.P.C from the coreclr partition to ensure matching bits
agocke Mar 31, 2022
202eee4
Merge remote-tracking branch 'upstream/main' into crossgen-publish
agocke Apr 1, 2022
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
3 changes: 1 addition & 2 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
<DefaultLibrariesSubsets Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or
'$(BuildTargetFramework)' == '' or
'$(BuildAllConfigurations)' == 'true'">libs.native+</DefaultLibrariesSubsets>
<DefaultLibrariesSubsets>$(DefaultLibrariesSubsets)libs.sfx+libs.oob</DefaultLibrariesSubsets>
<DefaultLibrariesSubsets Condition="'$(DotNetBuildFromSource)' != 'true'">$(DefaultLibrariesSubsets)+libs.pretest</DefaultLibrariesSubsets>
<DefaultLibrariesSubsets>$(DefaultLibrariesSubsets)libs.sfx+libs.oob+libs.pretest</DefaultLibrariesSubsets>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary because the RuntimeList.xml file is only created when running the libs.pretest subset.

Copy link
Member

Choose a reason for hiding this comment

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

Why was the DotNetBuildFromSource condition added initially? Is removing it going to break source build?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested it and couldn't find a problem. Not sure if there's any other testing I should be doing.

Copy link
Member

Choose a reason for hiding this comment

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

DotNetBuildFromSource skips this because it doesn't need a layout as it doesn't run tests. Shouldn't we get the xml manifests from the installer partition instead of relying on the test layouts?


<DefaultHostSubsets>host.native+host.tools</DefaultHostSubsets>
<DefaultHostSubsets Condition="'$(DotNetBuildFromSource)' != 'true'">$(DefaultHostSubsets)+host.pkg+host.tests</DefaultHostSubsets>
Expand Down
15 changes: 15 additions & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<CoreCLRCrossTargetComponentDirName Condition="'$(TargetArchitecture)' == 'arm' and '$(BuildArchitecture)' != 'arm' and '$(TargetsWindows)' == 'true'">x86</CoreCLRCrossTargetComponentDirName>
<CoreCLRCrossTargetComponentDirName Condition="'$(TargetArchitecture)' == 'arm' and '$(BuildArchitecture)' != 'arm' and '$(TargetsLinux)' == 'true'">x64</CoreCLRCrossTargetComponentDirName>
<CoreCLRCrossTargetComponentDirName Condition="'$(TargetArchitecture)' == 'armel' and '$(BuildArchitecture)' != 'armel' and '$(TargetsLinux)' == 'true'">x64</CoreCLRCrossTargetComponentDirName>
<SingleFileHostSourcePath>$(CoreCLRArtifactsPath)/corehost/singlefilehost$(ExeSuffix)</SingleFileHostSourcePath>
agocke marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<Target Name="ResolveRuntimeFilesFromLocalBuild">
Expand Down Expand Up @@ -222,4 +223,18 @@
<PropertyGroup>
<BundledRuntimeIdentifierGraphFile>$(RuntimeIdGraphDefinitionFile)</BundledRuntimeIdentifierGraphFile>
</PropertyGroup>

<Target Name="RewriteRuntimePackDir"
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not thrilled with this approach -- I think we should move to a mechanism to have a "well-known" runtime pack that can be used and preferred over all others. This might require new SDK functionality, I'm not sure.

Also, I'll have to update crossgen to build for net7.0 in that case. Not a big deal since we have a public preview out, but it's an interesting problem for net8.0, where we will have a net8.0 runtime pack, but no bootstrap SDK that would contain 8.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jkoritzinsky would appreciate your feedback on this in particular

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, this approach (re-pointing to the live runtime pack for the current RID) looks fine to me.

Personally, I'd prefer that we require consuming projects to manually hook this target, especially since it's only used in once place.

When we start work on .NET 8, this should still be handleable without much issue as our work to update framework references .

Maybe we should refactor this into another .targets file like eng/runtimepacks.targets that can be manually included in projects that will use it (similar to the eng/targetingpacks.targets) file.

Condition="'$(RunningPublish)' == 'true'"
DependsOnTargets="ResolveRuntimeFilesFromLocalBuild"
BeforeTargets="ResolveRuntimePackAssets">
<ItemGroup>
<!-- Remove AspNetCore runtime pack since we don't build it locally -->
<ResolvedRuntimePack Remove="Microsoft.AspNetCore.App.Runtime.$(RuntimeIdentifier)" />

<ResolvedRuntimePack Update="Microsoft.NETCore.App.Runtime.$(RuntimeIdentifier)">
<PackageDirectory>$(MicrosoftNetCoreAppRuntimePackDir)</PackageDirectory>
</ResolvedRuntimePack>
</ItemGroup>
</Target>
</Project>
2 changes: 0 additions & 2 deletions eng/testing/tests.singlefile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<PublishSingleFile>true</PublishSingleFile>
<UseAppHost>true</UseAppHost>
<SelfContained>true</SelfContained>
<SingleFileHostSourcePath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(Configuration)', 'corehost'))/singlefilehost</SingleFileHostSourcePath>
<SingleFileHostSourcePath Condition="'$(TargetOS)' == 'windows'">$(SingleFileHostSourcePath).exe</SingleFileHostSourcePath>
</PropertyGroup>

<PropertyGroup Condition="'$(TestNativeAot)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Internal.TypeSystem.Ecma
/// </summary>
public abstract class UnmanagedPdbSymbolReader : PdbSymbolReader
{
public static PdbSymbolReader TryOpenSymbolReaderForMetadataFile(string metadataFileName, string searchPath)
public static PdbSymbolReader? TryOpenSymbolReaderForMetadataFile(string metadataFileName, string searchPath)
{
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/tools/aot/ILCompiler/ILCompiler.props
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@
<TargetSpec>$(TargetOSComponent)_$(TargetArchitectureForLocalJitBuild)_$(TargetArchitectureForSharedLibraries)</TargetSpec>

<JitInterfaceLibraryName>$(LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(LibSuffix)</JitInterfaceLibraryName>
<!-- This will be provided when using the liveBuild, and unset otherwise. -->
<CoreCLRArtifactsPath Condition="'$(CoreCLRArtifactsPath)' == ''">$(RuntimeBinDir)$(CrossHostArch)</CoreCLRArtifactsPath>
</PropertyGroup>

<ItemGroup>
<Content Include="$(RuntimeBinDir)$(CrossHostArch)/$(JitInterfaceLibraryName)"
<Content Include="$(CoreCLRArtifactsPath)/$(JitInterfaceLibraryName)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Link="%(FileName)%(Extension)"
/>

<Content Include="$(RuntimeBinDir)$(CrossHostArch)/$(LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(LibSuffix)"
<Content Include="$(CoreCLRArtifactsPath)/$(LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(LibSuffix)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Link="%(FileName)%(Extension)"
Expand Down
49 changes: 44 additions & 5 deletions src/coreclr/tools/aot/crossgen2/crossgen2.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<OutputPath>$(RuntimeBinDir)/crossgen2</OutputPath>
<!-- The default value for macOS is false -->
<UseAppHost>true</UseAppHost>
<AppHostRuntimeIdentifier>$(Crossgen2PackageRID)</AppHostRuntimeIdentifier>
<OutputPath>$(RuntimeBinDir)crossgen2</OutputPath>
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 and we
don't want to ship using NativeAOT on MacOS -->
<NativeAotSupported Condition="'$(DotNetBuildFromSource)' == 'true' or '$(TargetOS)' == 'osx'">false</NativeAotSupported>
<!-- Trimming is not currently working, but set the appropriate feature flags for NativeAOT -->
<PublishTrimmed Condition="'$(NativeAotSupported)' == 'true'">true</PublishTrimmed>
<RuntimeIdentifiers Condition="'$(RunningPublish)' != 'true'">linux-x64;linux-musl-x64;linux-arm;linux-musl-arm;linux-arm64;linux-musl-arm64;freebsd-x64;osx-x64;osx-arm64;win-x64;win-x86;win-arm64;win-arm</RuntimeIdentifiers>
</PropertyGroup>

<Import Project="crossgen2.props" />

<PropertyGroup Condition="'$(NativeAotSupported)' != 'true'">
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<!-- Disable crossgen on NetBSD, illumos and Solaris for now. This can be revisited when we have full support. -->
<PublishReadyToRun Condition="'$(TargetOS)'=='NetBSD' Or '$(TargetOS)'=='illumos' Or '$(TargetOS)'=='Solaris'">false</PublishReadyToRun>
<!-- Disable crossgen on FreeBSD when cross building from Linux. -->
<PublishReadyToRun Condition="'$(TargetOS)'=='FreeBSD' and '$(CrossBuild)'=='true'">false</PublishReadyToRun>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup Condition="'$(NativeAotSupported)' == 'true'">
<IlcToolsPath>$(CoreCLRILCompilerDir)</IlcToolsPath>
<IlcToolsPath Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)'">$(CoreCLRCrossILCompilerDir)</IlcToolsPath>
<CppCompilerAndLinker Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)' and '$(HostOS)' != 'windows'">clang-9</CppCompilerAndLinker>
<SysRoot Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)' and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
<IlcFrameworkPath>$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)</IlcFrameworkPath>
<IlcFrameworkNativePath>$(MicrosoftNetCoreAppRuntimePackNativeDir)</IlcFrameworkNativePath>
<TrimmerSingleWarn>false</TrimmerSingleWarn>

<!-- Forced by ILLink targets; we should fix the SDK -->
<SelfContained Condition="'$(RunningPublish)' == 'true'">true</SelfContained>
</PropertyGroup>

<Import Project="$(R2ROverridePath)" Condition="'$(R2ROverridePath)' != ''" />
<Import Project="$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.targets"
Condition="'$(NativeAotSupported)' == 'true' and '$(RunningPublish)' == 'true'" />

</Project>
10 changes: 7 additions & 3 deletions src/coreclr/tools/aot/crossgen2/crossgen2.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@
<TargetSpec>$(TargetOSComponent)_$(TargetArchitectureForLocalJitBuild)_$(TargetArchitectureForSharedLibraries)</TargetSpec>

<JitInterfaceLibraryName>$(LibPrefix)jitinterface_$(TargetArchitectureForSharedLibraries)$(LibSuffix)</JitInterfaceLibraryName>
<!-- This will be provided when using the liveBuild, and unset otherwise. -->
<CoreCLRArtifactsPath Condition="'$(CoreCLRArtifactsPath)' == ''">$(RuntimeBinDir)$(CrossHostArch)</CoreCLRArtifactsPath>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could you add the same comment as in ILCompiler.props? (<!-- This will be provided when using the liveBuild, and unset otherwise. -->)

</PropertyGroup>

<ItemGroup>
<Content Include="$(RuntimeBinDir)$(CrossHostArch)/$(JitInterfaceLibraryName)"
<Content Include="$(CoreCLRArtifactsPath)/$(JitInterfaceLibraryName)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Link="%(FileName)%(Extension)"
/>

<Content Include="$(RuntimeBinDir)$(CrossHostArch)/$(LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(LibSuffix)"
<Content Include="$(CoreCLRArtifactsPath)/$(LibPrefix)clrjit_*_$(TargetArchitectureForSharedLibraries)$(LibSuffix)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest"
Link="%(FileName)%(Extension)"
Expand All @@ -104,7 +106,9 @@
<DiaSymReaderTargetArch>$(TargetArchitectureForSharedLibraries)</DiaSymReaderTargetArch>
<DiaSymReaderTargetArch Condition="'$(DiaSymReaderTargetArch)' == 'x64'">amd64</DiaSymReaderTargetArch>
<DiaSymReaderTargetArchFileName>Microsoft.DiaSymReader.Native.$(DiaSymReaderTargetArch).dll</DiaSymReaderTargetArchFileName>
<DiaSymReaderTargetArchPath>$(PkgMicrosoft_DiaSymReader_Native)\runtimes\win\native\$(DiaSymReaderTargetArchFileName)</DiaSymReaderTargetArchPath>
<DiaSymReaderTargetArchPath Condition="'$(PkgMicrosoft_DiaSymReader_Native)' != ''">$(PkgMicrosoft_DiaSymReader_Native)\runtimes\win\native\$(DiaSymReaderTargetArchFileName)</DiaSymReaderTargetArchPath>
<!-- When publishing we won't have the NuGet packages, so use the copy from the build artifacts directory. -->
<DiaSymReaderTargetArchPath Condition="'$(PkgMicrosoft_DiaSymReader_Native)' == ''">$(CoreCLRArtifactsPath)crossgen2/$(DiaSymReaderTargetArchFileName)</DiaSymReaderTargetArchPath>
</PropertyGroup>

<ItemGroup Condition="'$(TargetOS)' == 'windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.SharedFramework.Sdk" />

<PropertyGroup>
<SkipBuild Condition="'$(RuntimeFlavor)' == 'Mono'">true</SkipBuild>
<PlatformPackageType>RuntimePack</PlatformPackageType>
<!-- Crossgen is not used for Mono, and does not currently create freebsd packages -->
<SkipBuild Condition="'$(RuntimeFlavor)' == 'Mono' or '$(RuntimeIdentifier)' == 'freebsd-x64'">true</SkipBuild>
<PlatformPackageType>ToolPack</PlatformPackageType>
<SharedFrameworkName>$(SharedFrameworkName).Crossgen2</SharedFrameworkName>
<PgoSuffix Condition="'$(PgoInstrument)' != ''">.PGO</PgoSuffix>
<OverridePackageId>$(SharedFrameworkName)$(PgoSuffix).$(RuntimeIdentifier)</OverridePackageId>
Expand All @@ -13,56 +14,65 @@
<!-- Build this pack for any RID if building from source. Otherwise, only build select RIDs. -->
<RuntimeIdentifiers Condition="'$(DotNetBuildFromSource)' != 'true'">linux-x64;linux-musl-x64;linux-arm;linux-musl-arm;linux-arm64;linux-musl-arm64;freebsd-x64;osx-x64;osx-arm64;win-x64;win-x86;win-arm64;win-arm</RuntimeIdentifiers>
<GenerateInstallers>false</GenerateInstallers>
<GetSharedFrameworkFilesForReadyToRunDependsOn>
AddRuntimeFilesToPackage;
AddFrameworkFilesToPackage
</GetSharedFrameworkFilesForReadyToRunDependsOn>
<PublishReadyToRun>true</PublishReadyToRun>
<!-- Disable crossgen on NetBSD, illumos and Solaris for now. This can be revisited when we have full support. -->
<PublishReadyToRun Condition="'$(TargetOS)'=='NetBSD' Or '$(TargetOS)'=='illumos' Or '$(TargetOS)'=='Solaris'">false</PublishReadyToRun>
<!-- Disable crossgen on FreeBSD when cross building from Linux. -->
<PublishReadyToRun Condition="'$(TargetOS)'=='FreeBSD' and '$(CrossBuild)'=='true'">false</PublishReadyToRun>
<HostJsonTargetPath>tools/</HostJsonTargetPath>
<PermitDllAndExeFilesLackingFileVersion>true</PermitDllAndExeFilesLackingFileVersion>
<!-- Publishing as single-file or NativeAOT means we can't examine the interior DLLs -->
<ShouldVerifyClosure>false</ShouldVerifyClosure>
</PropertyGroup>

<PropertyGroup>
<TargetOSComponent>unix</TargetOSComponent>
<TargetOSComponent Condition="'$(TargetOS)' == 'windows'">win</TargetOSComponent>
<TargetSpec>$(TargetOSComponent)-$(TargetArchitecture)</TargetSpec>
</PropertyGroup>
<Target Name="PublishCrossgen"
BeforeTargets="GetFilesToPackage">

<ItemGroup>
<NativeRuntimeAsset Include="$(CoreCLRCrossgen2Dir)crossgen2$(ExeSuffix)" TargetPath="tools/" />
<Reference Include="$(CoreCLRCrossgen2Dir)crossgen2.dll" />
<Reference Include="$(CoreCLRCrossgen2Dir)ILCompiler*.dll" />
<Reference Condition="'$(DotNetBuildFromSource)' != 'true'" Include="$(CoreCLRCrossgen2Dir)Microsoft.DiaSymReader.dll" />
<NativeRuntimeAsset Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)jitinterface_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)clrjit_win_x86_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)clrjit_universal_arm_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Condition="'$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'x64'" Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)clrjit_win_x64_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Condition="'$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'x64'" Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)clrjit_unix_x64_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Condition="'$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'x64'" Include="$(CoreCLRCrossgen2Dir)$(LibPrefix)clrjit_universal_arm64_$(TargetArchitecture)$(LibSuffix)" TargetPath="tools/" />
<!-- Include the native hosting layer -->
<NativeRuntimeAsset Include="$(DotNetHostBinDir)/$(LibPrefix)hostfxr$(LibSuffix)" TargetPath="tools/" />
<NativeRuntimeAsset Include="$(DotNetHostBinDir)/$(LibPrefix)hostpolicy$(LibSuffix)" TargetPath="tools/" />
</ItemGroup>
<!-- Copy System.Private.CoreLib from the coreclr bin directory to the runtime pack directory,
as we always need the copy of System.Private.CoreLib that matches exactly with the runtime. -->
<Copy SourceFiles="$(CoreCLRArtifactsPath)System.Private.CoreLib.dll"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />

<MSBuild Projects="$(RepoRoot)src/coreclr/tools/aot/crossgen2/crossgen2.csproj"
Properties="RunningPublish=true
;RuntimeIdentifier=$(RuntimeIdentifier)
;CoreCLRArtifactsPath=$(CoreCLRArtifactsPath)
;R2ROverridePath=$(MSBuildThisFileDirectory)ReadyToRun.targets"
Targets="Restore;Publish;PublishItemsOutputGroup">
<Output TaskParameter="TargetOutputs"
ItemName="_RawCrossgenPublishFiles" />
</MSBuild>

<Target Name="AddRuntimeFilesToPackage" DependsOnTargets="ResolveRuntimeFilesFromLocalBuild">
<ItemGroup>
<CrossgenFile Include="@(RuntimeFiles)" Condition="'%(Filename)' == 'crossgen'" />
<OptimizationDataFile Include="@(RuntimeFiles)" Condition="'%(Filename)' == 'StandardOptimizationData'" />
<ReferenceCopyLocalPaths Include="@(RuntimeFiles)" Exclude="@(CrossgenFile);@(OptimizationDataFile)" />
<ReferenceCopyLocalPaths TargetPath="tools/" />
<_CrossgenPublishFiles Include="@(_RawCrossgenPublishFiles->'%(OutputPath)')"
KeepMetadata="REMOVE_ALL" />
</ItemGroup>
<ItemGroup Condition="'$(NativeAotSupported)' != 'true'">
<FilesToPackage Include="@(_CrossgenPublishFiles)"
Exclude="*.pdb;*.h;*.lib"
TargetPath="tools/" />
</ItemGroup>
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
<!-- Treat all native aot assets as native runtime assets -->
<FilesToPackage Include="@(_CrossgenPublishFiles->Distinct())"
Condition="'%(Extension)' != '.pdb'"
TargetPath="tools/" />
</ItemGroup>
</Target>

<Target Name="AddFrameworkFilesToPackage" DependsOnTargets="ResolveLibrariesFromLocalBuild">
<ItemGroup>
<ReferenceCopyLocalPaths Include="@(LibrariesRuntimeFiles)" TargetPath="tools/" />
</ItemGroup>
<Target Name="RunPublishedCrossgen" AfterTargets="PublishCrossgen"
Condition="'$(TargetOs)' == '$(HostOs)' and '$(TargetArchitecture)' == '$(BuildArchitecture)'">
<!-- Run the published crossgen if we're not cross-compiling -->
<Exec Command="@(FilesToPackage) $(CoreCLRArtifactsPath)IL/System.Private.CoreLib.dll --out $(IntermediateOutputPath)S.P.C.tmp" Condition="'%(FileName)%(Extension)' == 'crossgen2$(ExeSuffix)'"
ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="CrossgenOutput" />
<Output TaskParameter="ExitCode" PropertyName="CrossgenExitCode" />
</Exec>
<Error Text="Crossgen failed with code $(CrossgenExitCode), output: $(CrossgenOutput)" Condition="$(CrossgenExitCode) != 0" />
</Target>

<PropertyGroup>
<TargetOSComponent>unix</TargetOSComponent>
<TargetOSComponent Condition="'$(TargetOS)' == 'windows'">win</TargetOSComponent>
<TargetSpec>$(TargetOSComponent)-$(TargetArchitecture)</TargetSpec>
</PropertyGroup>

<Target Name="AddCrossgen2SymbolFilesToPackage" BeforeTargets="GetFilesToPackage">
<ItemGroup>
<_Crossgen2SymbolFilesToPackage Include="@(Reference->'$(CoreCLRArtifactsPath)PDB\%(FileName).pdb')" />
Expand All @@ -75,22 +85,8 @@
</ItemGroup>
</Target>

<PropertyGroup Condition="'$(TargetOS)' == 'windows'">
<!-- DiaSymReader for the target architecture, which is placed into the package -->
<_diaSymTargetArch>$(TargetArchitecture)</_diaSymTargetArch>
<_diaSymTargetArch Condition="'$(TargetArchitecture)' == 'x64'">amd64</_diaSymTargetArch>
<_diaSymReaderTargetArchPath>$(PkgMicrosoft_DiaSymReader_Native)/runtimes/win/native/Microsoft.DiaSymReader.Native.$(_diaSymTargetArch).dll</_diaSymReaderTargetArchPath>
</PropertyGroup>

<ItemGroup Condition="Exists('$(_diaSymReaderTargetArchPath)')">
<NativeRuntimeAsset Include="$(_diaSymReaderTargetArchPath)" TargetPath="tools/" />
</ItemGroup>

<Import Project="$(Crossgen2SdkOverridePropsPath)" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.SharedFramework.Sdk" />
<Import Project="$(Crossgen2SdkOverrideTargetsPath)" />
<Import Project="ReadyToRun.targets" />

<Target Name="GetFilesToPublish">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Expand All @@ -106,4 +102,5 @@
TargetPath="" />
</ItemGroup>
</Target>

</Project>