Skip to content

Commit 34f9ba6

Browse files
authored
Make dependency on lld optional (#85667)
This detects availability of lld by reusing the logic in `init-compiler.sh`.
1 parent 36c507f commit 34f9ba6

File tree

5 files changed

+70
-15
lines changed

5 files changed

+70
-15
lines changed

eng/testing/linker/project.csproj.template

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@
3636
<IlcSdkPath>{IlcSdkPath}</IlcSdkPath>
3737
<IlcFrameworkPath>{IlcFrameworkPath}</IlcFrameworkPath>
3838
<IlcFrameworkNativePath>{IlcFrameworkNativePath}</IlcFrameworkNativePath>
39-
<LinkerFlavor Condition="'$(TargetOS)' == 'linux'">lld</LinkerFlavor>
40-
<SysRoot Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)') and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
39+
<SysRoot Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)') and '$(ROOTFS_DIR)' != ''">$(ROOTFS_DIR)</SysRoot>
4140
<CoreCLRBuildIntegrationDir>{CoreCLRBuildIntegrationDir}</CoreCLRBuildIntegrationDir>
4241
</PropertyGroup>
4342

4443
<ItemGroup>
45-
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
44+
<CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(ROOTFS_DIR)' != ''" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
4645
</ItemGroup>
4746

4847
<ItemGroup>
@@ -62,4 +61,25 @@
6261
IsImplicitlyDefined="true" />
6362
</ItemGroup>
6463

64+
<Target Name="LocateNativeCompiler"
65+
Condition="'$(PublishAot)' == 'true' and '$(_hostOS)' != 'win'"
66+
BeforeTargets="SetupOSSpecificProps">
67+
<PropertyGroup>
68+
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
69+
</PropertyGroup>
70+
71+
<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"
72+
EchoOff="true"
73+
ConsoleToMsBuild="true"
74+
StandardOutputImportance="Low">
75+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
76+
</Exec>
77+
78+
<PropertyGroup>
79+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
80+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
81+
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
82+
</PropertyGroup>
83+
</Target>
84+
6585
</Project>

eng/testing/tests.singlefile.targets

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
3030
<IlcFrameworkPath>$(NetCoreAppCurrentTestHostSharedFrameworkPath)</IlcFrameworkPath>
3131
<IlcFrameworkNativePath>$(NetCoreAppCurrentTestHostSharedFrameworkPath)</IlcFrameworkNativePath>
32-
<LinkerFlavor Condition="'$(TargetOS)' == 'linux'">lld</LinkerFlavor>
3332
<NoWarn>$(NoWarn);IL1005;IL2105;IL3000;IL3001;IL3002;IL3003</NoWarn>
3433
<TrimMode>partial</TrimMode>
3534
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
@@ -130,12 +129,18 @@
130129
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
131130
</PropertyGroup>
132131

133-
<Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo $CC' 2>/dev/null"
132+
<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"
134133
EchoOff="true"
135134
ConsoleToMsBuild="true"
136135
StandardOutputImportance="Low">
137-
<Output TaskParameter="ConsoleOutput" PropertyName="CppLinker" />
136+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
138137
</Exec>
138+
139+
<PropertyGroup>
140+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
141+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
142+
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
143+
</PropertyGroup>
139144
</Target>
140145

141146
<Target Name="__ReplaceCrossgen2ExecutableWithFreshlyBuiltOne"

src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,26 @@
4444
</ItemGroup>
4545
</Target>
4646

47-
<Target Name="LocateNativeCompiler"
47+
<Target Name="LocateNativeCompiler"
4848
Condition="'$(NativeAotSupported)' == 'true' and '$(HostOS)' != 'windows'"
4949
BeforeTargets="SetupOSSpecificProps">
5050
<PropertyGroup>
5151
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
52-
<!-- TODO: change to <LinkerFlavor>lld</LinkerFlavor> once we pick up an SDK with https://github.com/dotnet/runtime/pull/83558. -->
53-
<UseLLVMLinker Condition="'$(CppCompilerAndLinker)' == 'clang' and '$(TargetOS)' == 'linux'">true</UseLLVMLinker>
5452
</PropertyGroup>
5553

56-
<Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo $CC' 2>/dev/null"
54+
<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"
5755
EchoOff="true"
5856
ConsoleToMsBuild="true"
5957
StandardOutputImportance="Low">
60-
<Output TaskParameter="ConsoleOutput" PropertyName="CppLinker" />
58+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
6159
</Exec>
60+
61+
<PropertyGroup>
62+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
63+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
64+
<!-- TODO: change to <LinkerFlavor>lld</LinkerFlavor> once we pick up an SDK with https://github.com/dotnet/runtime/pull/83558. -->
65+
<UseLLVMLinker Condition="$(_LDFLAGS.Contains('lld'))">true</UseLLVMLinker>
66+
</PropertyGroup>
6267
</Target>
6368

6469
<ItemGroup Condition="'$(NativeAotSupported)' == 'true'">

src/coreclr/tools/aot/crossgen2/crossgen2.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,20 @@
9090
BeforeTargets="SetupOSSpecificProps">
9191
<PropertyGroup>
9292
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
93-
<LinkerFlavor Condition="'$(CppCompilerAndLinker)' == 'clang' and '$(TargetOS)' == 'linux'">lld</LinkerFlavor>
9493
</PropertyGroup>
9594

96-
<Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo $CC' 2>/dev/null"
95+
<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"
9796
EchoOff="true"
9897
ConsoleToMsBuild="true"
9998
StandardOutputImportance="Low">
100-
<Output TaskParameter="ConsoleOutput" PropertyName="CppLinker" />
99+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
101100
</Exec>
101+
102+
<PropertyGroup>
103+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
104+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
105+
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
106+
</PropertyGroup>
102107
</Target>
103108

104109
</Project>

src/tests/Directory.Build.targets

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@
533533
<IlcFrameworkNativePath>$(MicrosoftNetCoreAppRuntimePackNativeDir)</IlcFrameworkNativePath>
534534
<RuntimeIdentifier>$(OutputRID)</RuntimeIdentifier>
535535

536-
<LinkerFlavor Condition="'$(TargetOS)' == 'linux'">lld</LinkerFlavor>
537536
<SysRoot Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
538537
<BuildNativeAotFrameworkObjects Condition="'$(IlcMultiModule)' == 'true'">true</BuildNativeAotFrameworkObjects>
539538
<DisableFrameworkLibGeneration Condition="'$(BuildNativeAotFrameworkObjects)' == 'true'">true</DisableFrameworkLibGeneration>
@@ -570,4 +569,25 @@
570569
Condition="'$(_WillCLRTestProjectBuild)' == 'true' and '$(CLRTestKind)' == 'BuildAndRun'"
571570
DependsOnTargets="ComputeResolvedFilesToPublishList;LinkNative" />
572571

572+
<Target Name="LocateNativeCompiler"
573+
Condition="'$(TestBuildMode)' == 'nativeaot' and '$(HostOS)' != 'windows'"
574+
BeforeTargets="SetupOSSpecificProps">
575+
<PropertyGroup>
576+
<CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
577+
</PropertyGroup>
578+
579+
<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"
580+
EchoOff="true"
581+
ConsoleToMsBuild="true"
582+
StandardOutputImportance="Low">
583+
<Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
584+
</Exec>
585+
586+
<PropertyGroup>
587+
<CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
588+
<_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
589+
<LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
590+
</PropertyGroup>
591+
</Target>
592+
573593
</Project>

0 commit comments

Comments
 (0)