Skip to content

Commit 3f28b1a

Browse files
authored
Move tools to use LKG ILC (#107772)
Starts with crossgen2 and moves shared helpers into a central targets file. This still leaves a significant amount of work to do. We're still building 3 copies of the crossgen2 and ILC projects (plain, in-build, and AOT) and not all might be necessary. Also, some pieces could maybe be reused in other portions of the build. There's also no way to _not_ use LKG bits. That's left as future work.
1 parent 0f04f6d commit 3f28b1a

19 files changed

+131
-307
lines changed

Directory.Build.targets

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Import Project="$(RepositoryEngineeringDir)Analyzers.targets" />
1111
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
1212
<Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
13+
<Import Project="$(RepositoryEngineeringDir)toolAot.targets" />
1314
<Import Project="$(RepositoryEngineeringDir)generators.targets" />
1415
<Import Project="$(RepositoryEngineeringDir)python.targets" />
1516
<Import Project="$(RepositoryEngineeringDir)generatorProjects.targets" Condition="'$(IsGeneratorProject)' == 'true'" />

eng/Subsets.props

+4-2
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@
357357
$(CoreClrProjectRoot)tools\r2rtest\R2RTest.csproj;
358358
$(CoreClrProjectRoot)tools\PdbChecker\PdbChecker.csproj;
359359
$(CoreClrProjectRoot)tools\AssemblyChecker\AssemblyChecker.csproj" Category="clr" Condition="'$(DotNetBuildSourceOnly)' != 'true'"/>
360-
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2.csproj" Category="clr" />
360+
<!-- skip the architectures that don't have LKG runtime packs -->
361+
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_publish.csproj" Condition="'$(NativeAotSupported)' == 'true'" Category="clr" />
361362
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Build.Tasks\ILCompiler.Build.Tasks.csproj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
362363
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler.csproj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
363364
<ProjectToBuild Include="$(CoreClrProjectRoot)nativeaot\BuildIntegration\BuildIntegration.proj" Category="clr" Condition="'$(NativeAotSupported)' == 'true'" />
364365

365-
<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != '')" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_crossarch.csproj" Category="clr" />
366+
<ProjectToBuild Condition="'$(NativeAotSupported)' == 'true' and ('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != '')" Include="$(CoreClrProjectRoot)tools\aot\ILCompiler\ILCompiler_inbuild.csproj" Category="clr" />
367+
366368
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\crossgen2\crossgen2_inbuild.csproj" Category="clr" />
367369

368370
<ProjectToBuild Condition="'$(TargetOS)' == 'windows' or ('$(TargetOS)' == 'linux' and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')) or '$(TargetOS)' == 'osx'" Include="$(CoreClrProjectRoot)tools\SuperFileCheck\SuperFileCheck.csproj" Category="clr" />

eng/liveBuilds.targets

+2-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
<CoreCLRAotSdkDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'aotsdk'))</CoreCLRAotSdkDir>
2929
<CoreCLRBuildIntegrationDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'build'))</CoreCLRBuildIntegrationDir>
3030

31-
<Crossgen2Dir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'crossgen2'))</Crossgen2Dir>
31+
<Crossgen2Dir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', 'crossgen2-published'))</Crossgen2Dir>
32+
<Crossgen2InBuildDir>$([MSBuild]::NormalizeDirectory('$(CoreCLRArtifactsPath)', '$(BuildArchitecture)', 'crossgen2'))</Crossgen2InBuildDir>
3233

3334
<ToolsILLinkDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'ILLink.Tasks', '$(ToolsConfiguration)'))</ToolsILLinkDir>
3435

@@ -58,15 +59,6 @@
5859
<SingleFileHostSourcePath>$([MSBuild]::NormalizePath('$(CoreCLRArtifactsPath)', 'corehost', 'singlefilehost$(ExeSuffix)'))</SingleFileHostSourcePath>
5960
</PropertyGroup>
6061

61-
<!-- Not a live build, but allow overriding the LKG ILCompiler package with a specific version. -->
62-
<PropertyGroup Condition="'$(UseNativeAotForComponents)' == 'true' and '$(PublishAot)' == 'true' and '$(MicrosoftDotNetILCompilerVersion)' != ''">
63-
<SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning>
64-
</PropertyGroup>
65-
<ItemGroup Condition="'$(UseNativeAotForComponents)' == 'true' and '$(PublishAot)' == 'true' and '$(MicrosoftDotNetILCompilerVersion)' != ''">
66-
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerVersion)" />
67-
<PackageReference Include="runtime.$(ToolsRID).Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerVersion)" />
68-
</ItemGroup>
69-
7062
<Target Name="ResolveRuntimeFilesFromLocalBuild">
7163
<Error Condition="!Exists('$(CoreCLRArtifactsPath)') and '$(RuntimeFlavor)' == 'CoreCLR'"
7264
Text="The CoreCLR artifacts path does not exist '$(CoreCLRArtifactsPath)'. The 'clr' subset must be built before building this project. Configuration: '$(CoreCLRConfiguration)'. To use a different configuration, specify the 'RuntimeConfiguration' property." />

eng/targetingpacks.targets

+1-13
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
NuGetPackageVersion="$(ProductVersion)" />
142142
</ItemGroup>
143143
</Target>
144-
144+
145145
<!-- Use local app host pack for NetCoreAppCurrent. -->
146146
<Target Name="UpdateLocalAppHostPack"
147147
Condition="'$(UseLocalAppHostPack)' == 'true'"
@@ -167,16 +167,4 @@
167167
Condition="'%(RuntimeFramework.FrameworkName)' == '$(LocalFrameworkOverrideName)'" />
168168
</ItemGroup>
169169
</Target>
170-
171-
<!-- Update the resolved crossgen2 tool to use the app with the same .NET host as the build instead of the built apphost. -->
172-
<Target Name="UpdateLocalCrossgen2Tool"
173-
Condition="'$(UseLocalCrossgen2Pack)' == 'true'"
174-
AfterTargets="ResolveReadyToRunCompilers">
175-
<ItemGroup>
176-
<OriginalCrossgen2Tool Include="@(Crossgen2Tool)" Crossgen2Dll="$([System.IO.Path]::ChangeExtension('%(Identity)', '.dll'))" />
177-
<Crossgen2Tool Remove="@(Crossgen2Tool)" />
178-
<Crossgen2Tool Include="@(OriginalCrossgen2Tool->'%(Crossgen2Dll)')"
179-
DotNetHostPath="$(DotNetTool)" />
180-
</ItemGroup>
181-
</Target>
182170
</Project>

eng/testing/tests.singlefile.targets

-56
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,6 @@
3838
<SelfContained>true</SelfContained>
3939
</PropertyGroup>
4040

41-
<!-- Needed for the amd64 -> amd64 musl cross-build to pass the target flag. -->
42-
<Target Name="_FixIlcTargetTriple"
43-
AfterTargets="SetupOSSpecificProps"
44-
Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">
45-
<!-- Compute CrossCompileRid, and copy the downstream logic as-is. -->
46-
<PropertyGroup>
47-
<CrossCompileRid>$(RuntimeIdentifier)</CrossCompileRid>
48-
49-
<CrossCompileArch />
50-
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-x64'))">x86_64</CrossCompileArch>
51-
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' != 'true'">aarch64</CrossCompileArch>
52-
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' == 'true'">arm64</CrossCompileArch>
53-
54-
<TargetTriple />
55-
<TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
56-
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
57-
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
58-
</PropertyGroup>
59-
60-
<ItemGroup>
61-
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
62-
</ItemGroup>
63-
</Target>
64-
65-
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
66-
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
67-
</ItemGroup>
68-
6941
<PropertyGroup Condition="'$(PublishSingleFile)' == 'true' or '$(TestNativeAot)' == 'true'">
7042
<DefineConstants>$(DefineConstants);SINGLE_FILE_TEST_RUNNER</DefineConstants>
7143
</PropertyGroup>
@@ -229,34 +201,6 @@
229201
</ItemGroup>
230202
</Target>
231203

232-
<!--
233-
Use init-compiler.sh to locate the compiler toolchain which was resolved for rest of the build.
234-
This target is essentially an override hook which is called before `SetupOSSpecificProps` in
235-
`Microsoft.NETCore.Native.Unix.targets`. Note that the input is `CppCompilerAndLinker`
236-
and the output is `CppLinker`, because from `SetupOSSpecificProps` onwards, we only use `CppLinker`
237-
(when alternative compiler, i.e. gcc, is not selected)
238-
-->
239-
<Target Name="LocateNativeCompiler"
240-
Condition="'$(TestNativeAot)' == 'true' and '$(HostOS)' != 'windows'"
241-
BeforeTargets="SetupOSSpecificProps">
242-
<PropertyGroup>
243-
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
244-
</PropertyGroup>
245-
246-
<Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo &quot;$CC;$LDFLAGS&quot;' 2>/dev/null"
247-
EchoOff="true"
248-
ConsoleToMsBuild="true"
249-
StandardOutputImportance="Low">
250-
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
251-
</Exec>
252-
253-
<PropertyGroup>
254-
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
255-
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
256-
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
257-
</PropertyGroup>
258-
</Target>
259-
260204
<Target Name="PublishTestAsSingleFile"
261205
Condition="'$(IsCrossTargetingBuild)' != 'true'"
262206
AfterTargets="Build"

eng/toolAot.targets

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<Project>
2+
<!-- Settings for tools that publish as AOT -->
3+
4+
<PropertyGroup Condition="'$(AotOrSingleFile)' == 'true' and '$(UseNativeAotForComponents)' == 'true'">
5+
<PublishAot>true</PublishAot>
6+
<!-- Use .dwarf files instead of .dsym files since our symbol exporting may not safely handle folders. -->
7+
<NativeSymbolExt Condition="'$(_IsApplePlatform)' == 'true'">.dwarf</NativeSymbolExt>
8+
<DsymUtilOptions Condition="'$(_IsApplePlatform)' == 'true'">--flat</DsymUtilOptions>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition="'$(AotOrSingleFile)' == 'true' and '$(UseNativeAotForComponents)' != 'true'">
12+
<PublishSingleFile>true</PublishSingleFile>
13+
<PublishReadyToRun>true</PublishReadyToRun>
14+
<!-- Disable crossgen on NetBSD, illumos, Solaris, and Haiku for now. This can be revisited when we have full support. -->
15+
<PublishReadyToRun Condition="'$(TargetOS)' == 'netbsd' Or '$(TargetOS)' == 'illumos' Or '$(TargetOS)' == 'solaris' Or '$(TargetOS)' == 'haiku'">false</PublishReadyToRun>
16+
<!-- Disable crossgen on FreeBSD when cross building from Linux. -->
17+
<PublishReadyToRun Condition="'$(TargetOS)' == 'freebsd' and '$(CrossBuild)' == 'true'">false</PublishReadyToRun>
18+
<PublishReadyToRunComposite>$(PublishReadyToRun)</PublishReadyToRunComposite>
19+
</PropertyGroup>
20+
21+
<!-- Allow overriding the LKG ILCompiler package with a specific version. -->
22+
<PropertyGroup Condition="'$(UseNativeAotForComponents)' == 'true' and '$(PublishAot)' == 'true' and '$(MicrosoftDotNetILCompilerVersion)' != ''">
23+
<SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning>
24+
</PropertyGroup>
25+
26+
<ItemGroup Condition="'$(UseNativeAotForComponents)' == 'true' and '$(PublishAot)' == 'true' and '$(MicrosoftDotNetILCompilerVersion)' != ''">
27+
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerVersion)" />
28+
<PackageReference Include="runtime.$(ToolsRID).Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerVersion)" />
29+
</ItemGroup>
30+
31+
<!-- Needed for the amd64 -> amd64 musl cross-build to pass the target flag. -->
32+
<Target Name="_FixIlcTargetTriple"
33+
AfterTargets="SetupOSSpecificProps"
34+
Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">
35+
<!-- Compute CrossCompileRid, and copy the downstream logic as-is. -->
36+
<PropertyGroup>
37+
<CrossCompileRid>$(RuntimeIdentifier)</CrossCompileRid>
38+
39+
<CrossCompileArch />
40+
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-x64'))">x86_64</CrossCompileArch>
41+
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' != 'true'">aarch64</CrossCompileArch>
42+
<CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' == 'true'">arm64</CrossCompileArch>
43+
44+
<TargetTriple />
45+
<TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
46+
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
47+
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
48+
</PropertyGroup>
49+
50+
<ItemGroup>
51+
<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'osx' and '$(TargetTriple)' != ''" />
52+
</ItemGroup>
53+
</Target>
54+
55+
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
56+
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
57+
</ItemGroup>
58+
59+
<Target Name="LocateNativeCompiler"
60+
Condition="'$(UseNativeAotForComponents)' == 'true' and '$(HostOS)' != 'windows'"
61+
BeforeTargets="SetupOSSpecificProps">
62+
<PropertyGroup>
63+
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
64+
</PropertyGroup>
65+
66+
<Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo &quot;$CC;$LDFLAGS&quot;' 2>/dev/null"
67+
EchoOff="true"
68+
ConsoleToMsBuild="true"
69+
StandardOutputImportance="Low">
70+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
71+
</Exec>
72+
73+
<PropertyGroup>
74+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
75+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
76+
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
77+
</PropertyGroup>
78+
</Target>
79+
80+
<!-- Cross-build settings -->
81+
<PropertyGroup>
82+
<LinkerFlavor Condition="'$(CrossBuild)' == 'true' and '$(TargetsLinux)' == 'true'">lld</LinkerFlavor>
83+
<SysRoot Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
84+
</PropertyGroup>
85+
86+
</Project>

src/coreclr/crossgen-corelib.proj

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<Project Sdk="Microsoft.Build.NoTargets">
22

3-
<PropertyGroup>
4-
<UseCrossArchCrossgen2 Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(EnableNativeSanitizers)' != ''">true</UseCrossArchCrossgen2>
5-
</PropertyGroup>
6-
73
<ItemGroup>
84
<ProjectReference Include="$(CoreClrProjectRoot)/tools/aot/crossgen2/crossgen2_inbuild.csproj" OutputItemType="Crossgen2" />
95
<ProjectReference Include="$(CoreClrProjectRoot)/tools/dotnet-pgo/dotnet-pgo.csproj" OutputItemType="DotNetPgo" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />
@@ -99,10 +95,12 @@
9995
</ItemGroup>
10096

10197
<PropertyGroup>
102-
<Crossgen2OutputPath>%(Crossgen2.RootDir)%(Crossgen2.Directory)</Crossgen2OutputPath>
98+
<Crossgen2OutputPath>%(Crossgen2.RootDir)/%(Crossgen2.Directory)</Crossgen2OutputPath>
10399
</PropertyGroup>
104100
<ItemGroup>
105-
<Crossgen2Files Include="$(Crossgen2OutputPath)/*.dll;$(Crossgen2OutputPath)/*.so;$(Crossgen2OutputPath)/*.dylib" />
101+
<Crossgen2Files Include="$(Crossgen2OutputPath)/*.dll" />
102+
<Crossgen2Files Include="$(Crossgen2OutputPath)/*.so" />
103+
<Crossgen2Files Include="$(Crossgen2OutputPath)/*.dylib" />
106104
</ItemGroup>
107105
</Target>
108106

0 commit comments

Comments
 (0)