Skip to content

Commit

Permalink
Remove dependencies on non-live illink (#91468)
Browse files Browse the repository at this point in the history
Removes remaining dependencies on non-live ILLink.

The live ILLink logic is consolidated into liveILLink.targets,
which gets imported from source projects that depend on ILLink.

This removes the dependency on UsingToolMicrosoftNetILLinkTasks,
and turns off ILLink dependency flow.

* Don't require illink analyzers for source generator projects

Microsoft.Extensions.Options.SourceGeneration was enabling
the single-file analyzer, but did not import illink.targets
because it is not a source project.

We could fix this by importing liveILLink.targets instead, but
this introduces more problems with circular dependencies
(generator projects depending on illink depending on
generator projects).

* Only enable single-file analyzer for source projects

This more closely matches the condition on the import of
illink.targets. When EnableSingleFileAnalyzer is true, we should
also import liveILLink.targets so that we get the live analyzer
bits.

* Remove import from tests.mobile.targets

Mobile trimmingtests should already use the live illink with
the logic in project.csproj.template. The import of illink.targets
shouldn't be required, unless tests.mobile.targets are required
for other test scenarios.

This import was resulting in a double-import, and wasn't working
because liveILLink needs ToolsILLinkDir to be set, but it's not
set during the trimming test build.

---------

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
  • Loading branch information
sbomer and ViktorHofer authored Oct 5, 2023
1 parent f555492 commit 1ef38a8
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 53 deletions.
5 changes: 3 additions & 2 deletions eng/Analyzers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(RunAnalyzers)' != 'false'">
<EnableSingleFileAnalyzer Condition="
'$(EnableSingleFileAnalyzer)' == '' And
'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">true</EnableSingleFileAnalyzer>
'$(EnableSingleFileAnalyzer)' == '' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(IsSourceProject)' == 'true'">true</EnableSingleFileAnalyzer>
</PropertyGroup>
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis.src.globalconfig" />
Expand Down
4 changes: 0 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@
<Sha>736dabeca728ccf8b911d96d1b4c575b4d0db7d2</Sha>
<SourceBuild RepoName="runtime" ManagedOnly="false" />
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="9.0.0-alpha.1.23470.17">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>736dabeca728ccf8b911d96d1b4c575b4d0db7d2</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.ILCompiler" Version="9.0.0-alpha.1.23470.17">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>736dabeca728ccf8b911d96d1b4c575b4d0db7d2</Sha>
Expand Down
2 changes: 0 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@
<CompilerPlatformTestingVersion>1.1.2-beta1.23323.1</CompilerPlatformTestingVersion>
<!-- Docs -->
<MicrosoftPrivateIntellisenseVersion>8.0.0-preview-20230918.1</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>9.0.0-alpha.1.23470.17</MicrosoftNETILLinkTasksVersion>
<!-- Mono Cecil -->
<MicrosoftDotNetCecilVersion>0.11.4-alpha.23476.1</MicrosoftDotNetCecilVersion>
<!-- ILCompiler -->
Expand Down
30 changes: 3 additions & 27 deletions eng/illink.targets
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
<Project>

<PropertyGroup>
<_ILLinkTasksSourceDir>$(ToolsProjectRoot)illink\src\ILLink.Tasks\</_ILLinkTasksSourceDir>
<ILLinkAnalyzersPropsPath>$(ToolsProjectRoot)illink\src\ILLink.RoslynAnalyzer\build\Microsoft.NET.ILLink.Analyzers.props</ILLinkAnalyzersPropsPath>
<!-- Custom trimming logic should always use live ILLink, even when none of the
trimming-related SDK properties are set. -->
<_RequiresLiveILLink>true</_RequiresLiveILLink>
</PropertyGroup>

<ItemGroup>
<!-- The assembly shouldn't be referenced, nor promoted to a package dependency, nor copied to the output directory. -->
<ProjectReference Include="$(_ILLinkTasksSourceDir)ILLink.Tasks.csproj"
ReferenceOutputAssembly="false"
PrivateAssets="all"
Private="false"
SetConfiguration="Configuration=$(ToolsConfiguration)">
<!-- Keep TFMs in sync with ILLink.Tasks.csproj -->
<SetTargetFramework Condition="'$(MSBuildRuntimeType)' == 'Core'">TargetFramework=$(NetCoreAppToolCurrent)</SetTargetFramework>
<SetTargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">TargetFramework=$(NetFrameworkToolCurrent)</SetTargetFramework>
</ProjectReference>
</ItemGroup>

<Import Project="$(_ILLinkTasksSourceDir)build\Microsoft.NET.ILLink.Tasks.props" />

<PropertyGroup>
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<!-- Don't use SDK's trimming functionality.
Once we have an SDK with
https://github.com/dotnet/sdk/commit/bdce224bba472ccad4bade07b757ac5275040c0e
and
https://github.com/dotnet/sdk/commit/f051b536cc12190488231f3a889df44214c1bc2e,
we might be able to use built-in functionality instead of a packagereference.
-->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(ToolsILLinkDir)$(NetCoreAppToolCurrent)\ILLink.Tasks.dll</ILLinkTasksAssembly>
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(ToolsILLinkDir)$(NetFrameworkToolCurrent)\ILLink.Tasks.dll</ILLinkTasksAssembly>
<PrepareResourcesDependsOn>_EmbedILLinkXmls;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);ILLinkTrimAssembly</TargetsTriggeredByCompilation>

Expand Down
44 changes: 44 additions & 0 deletions eng/liveILLink.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project>

<!-- NOTE: these targets should be a no-op, unless _RequiresLiveILLink, computed below, is true. -->

<PropertyGroup>
<!-- Keep these conditions in sync with _RequiresILLinkPack in
https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets -->
<_RequiresLiveILLink Condition="'$(_RequiresLiveILLink)' == '' And (
'$(PublishAot)' == 'true' Or
'$(IsAotCompatible)' == 'true' Or '$(EnableAotAnalyzer)' == 'true' Or
'$(PublishTrimmed)' == 'true' Or
'$(IsTrimmable)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or
'$(EnableSingleFileAnalyzer)' == 'true')">true</_RequiresLiveILLink>
</PropertyGroup>

<PropertyGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<_ILLinkTasksSourceDir>$(ToolsProjectRoot)illink\src\ILLink.Tasks\</_ILLinkTasksSourceDir>
<ILLinkAnalyzersPropsPath>$(ToolsProjectRoot)illink\src\ILLink.RoslynAnalyzer\build\Microsoft.NET.ILLink.Analyzers.props</ILLinkAnalyzersPropsPath>
</PropertyGroup>

<Import Project="$(_ILLinkTasksSourceDir)build\Microsoft.NET.ILLink.Tasks.props" Condition="'$(_RequiresLiveILLink)' == 'true'" />

<PropertyGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<!-- Don't use SDK's trimming functionality. -->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<!-- Keep in sync with SetTargetFramework metadata on the ProjectReference below. -->
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(ToolsILLinkDir)$(NetCoreAppToolCurrent)\ILLink.Tasks.dll</ILLinkTasksAssembly>
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(ToolsILLinkDir)$(NetFrameworkToolCurrent)\ILLink.Tasks.dll</ILLinkTasksAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<!-- The assembly shouldn't be referenced, nor promoted to a package dependency, nor copied to the output directory. -->
<ProjectReference Include="$(_ILLinkTasksSourceDir)ILLink.Tasks.csproj"
ReferenceOutputAssembly="false"
PrivateAssets="all"
Private="false"
SetConfiguration="Configuration=$(ToolsConfiguration)">
<!-- Keep TFMs in sync with ILLink.Tasks.csproj -->
<SetTargetFramework Condition="'$(MSBuildRuntimeType)' == 'Core'">TargetFramework=$(NetCoreAppToolCurrent)</SetTargetFramework>
<SetTargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">TargetFramework=$(NetFrameworkToolCurrent)</SetTargetFramework>
</ProjectReference>
</ItemGroup>

</Project>
7 changes: 0 additions & 7 deletions eng/targetingpacks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@
Condition="'$(UseLocalAppHostPack)' == 'true' and '@(KnownAppHostPack->AnyHaveMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))' != 'true'" />
</ItemGroup>

<!-- Add known packs from the downlevel TFM until we are building with an SDK that supports the new TFM all-up. -->
<ItemGroup Condition="'$(NetCoreAppToolCurrent)' != '$(NetCoreAppCurrent)'">
<KnownILLinkPack Include="@(KnownILLinkPack->WithMetadataValue('Identity', 'Microsoft.NET.ILLink.Tasks')->WithMetadataValue('TargetFramework', '$(NetCoreAppToolCurrent)'))">
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
</KnownILLinkPack>
</ItemGroup>

<!-- Simple name references will be resolved from the targeting pack folders and should never be copied to the output. -->
<ItemGroup>
<Reference Update="@(Reference)">
Expand Down
3 changes: 3 additions & 0 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<!-- This must be done after the usual nuget props imports, to override the implicitly referenced
Microsoft.NET.ILLink.Tasks.props from the SDK. -->
<Import Project="$(ToolsILLinkDir)$(NetCoreAppToolCurrent)/build/Microsoft.NET.ILLink.Tasks.props" />

<PropertyGroup>
<!-- Don't use SDK's trimming functionality. -->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<ILLinkTasksAssembly>$(ToolsILLinkDir)$(NetCoreAppToolCurrent)/ILLink.Tasks.dll</ILLinkTasksAssembly>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,4 @@
DependsOnTargets="InstallWorkloadUsingArtifacts"
Condition="'$(InstallWorkloadForTesting)' == 'true'" />

<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(EnableAggressiveTrimming)' == 'true' or '$(EnableSoftTrimming)' == 'true'" />
</Project>
2 changes: 2 additions & 0 deletions src/coreclr/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<Import Project="..\..\Directory.Build.targets" />

<ItemGroup Condition="'$(UsingMicrosoftNoTargetsSdk)' != 'true'">
Expand Down Expand Up @@ -28,5 +29,6 @@

<!-- Import targets here to have TargetPath and other macros defined. Limit to CoreLib. -->
<Import Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib' or '$(IsNativeAotProject)' == 'true'" Project="$(RepositoryEngineeringDir)illink.targets" />
<Import Project="$(RepositoryEngineeringDir)liveILLink.targets" />

</Project>
1 change: 1 addition & 0 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableRunSettingsSupport)' == 'true' or '$(EnableCoverageSupport)' == 'true'" />

<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(IsSourceProject)' == 'true' or '$(ExplicitlyImportCustomILLinkTargets)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)liveILLink.targets" />
<Import Project="$(RepositoryEngineeringDir)nativeSanitizers.targets" />

<ItemGroup Condition="'$(UseTargetFrameworkPackage)' != 'false'">
Expand Down
4 changes: 1 addition & 3 deletions src/libraries/sendtohelix-mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
<_XHarnessAppleCustomCommand Condition="'$(NeedsiOSSDK)' == 'true'">
source build-apple-app.sh
</_XHarnessAppleCustomCommand>
<!-- Use ILLink.Tasks version matching the SDK used to build. See comment about _RequiresILLinkPack in eng/illink.targets -->
<ILLinkDir>$([MSBuild]::NormalizeDirectory('$(NuGetPackageRoot)', 'microsoft.net.illink.tasks', '$(BundledNETCoreAppPackageVersion)'))</ILLinkDir>
</PropertyGroup>

<ItemGroup Condition="'$(NeedsiOSSDK)' == 'true'">
Expand All @@ -79,7 +77,7 @@
Destination="build/BuildIntegration" />
<HelixCorrelationPayload Include="$(CoreCLRAotSdkDir)" Condition="'$(RuntimeFlavor)' == 'coreclr'"
Destination="build/aotsdk" />
<HelixCorrelationPayload Include="$(ILLinkDir)" Destination="build/microsoft.net.illink.tasks" />
<HelixCorrelationPayload Include="$(ToolsILLinkDir)" Destination="build/microsoft.net.illink.tasks" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsAppleMobile)' == 'true'">
Expand Down
2 changes: 2 additions & 0 deletions src/mono/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

<!-- Import targets here to have TargetPath and other macros defined. Limit to CoreLib. -->
<Import Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'" Project="$(RepositoryEngineeringDir)illink.targets" />
<Import Project="$(RepositoryEngineeringDir)liveILLink.targets" />

</Project>
4 changes: 2 additions & 2 deletions src/mono/msbuild/apple/build/AppleBuild.LocalBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<IlcSdkPath>$([MSBuild]::NormalizeDirectory('$(BuildBaseDir)', 'aotsdk'))</IlcSdkPath>
<IlcFrameworkPath>$(MicrosoftNetCoreAppRuntimePackLibDir)</IlcFrameworkPath>
<IlcFrameworkNativePath>$(MicrosoftNetCoreAppRuntimePackNativeDir)</IlcFrameworkNativePath>
<ILLinkTargetsPath>$([MSBuild]::NormalizePath('$(BuildBaseDir)', 'microsoft.net.illink.tasks', 'build', 'Microsoft.NET.ILLink.targets'))</ILLinkTargetsPath>
<ILLinkTasksAssembly>$([MSBuild]::NormalizePath('$(BuildBaseDir)', 'microsoft.net.illink.tasks', 'tools', '$(_NetCoreAppToolCurrent)', 'ILLink.Tasks.dll'))</ILLinkTasksAssembly>
<ILLinkTargetsPath>$([MSBuild]::NormalizePath('$(BuildBaseDir)', 'microsoft.net.illink.tasks', '$(_NetCoreAppToolCurrent)', 'build', 'Microsoft.NET.ILLink.targets'))</ILLinkTargetsPath>
<ILLinkTasksAssembly>$([MSBuild]::NormalizePath('$(BuildBaseDir)', 'microsoft.net.illink.tasks', '$(_NetCoreAppToolCurrent)', 'ILLink.Tasks.dll'))</ILLinkTasksAssembly>
<_MonoAotCrossCompilerPath>$([MSBuild]::NormalizePath($(MonoAotCrossDir), 'mono-aot-cross'))</_MonoAotCrossCompilerPath>
<_MonoAotCrossCompilerPath Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">$(_MonoAotCrossCompilerPath).exe</_MonoAotCrossCompilerPath>
</PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LibrariesConfiguration>Release</LibrariesConfiguration>
<!-- NativeAot tests rely on presence of ILLink targets, but don't actually run ILLink. -->
<UsingToolMicrosoftNetILLinkTasks Condition="'$(UsingToolMicrosoftNetILLinkTasks)' == ''">true</UsingToolMicrosoftNetILLinkTasks>
<InstallV8ForTests>false</InstallV8ForTests>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
<MSBuild Projects="@(ProjectReference)"
Targets="CopyAllNativeProjectReferenceBinaries"
Condition="'$(IsMergedTestRunnerAssembly)' == 'true'"
SkipNonexistentTargets="true"
BuildInParallel="true" />
</Target>

Expand Down Expand Up @@ -592,6 +593,7 @@
<Import Project="$(RepositoryEngineeringDir)nativeSanitizers.targets" Condition="'$(TestBuildMode)' == 'nativeaot'" />

<Import Project="$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets" Condition="'$(TestBuildMode)' == 'nativeaot'" />
<Import Project="$(RepoRoot)eng/liveILLink.targets" />

<ItemGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
<Content Include="@(SanitizerRuntimeToCopy->'$(CoreCLRArtifactsPath)/%(Identity)')" CopyToOutputDirectory="PreserveNewest" />
Expand Down
4 changes: 3 additions & 1 deletion src/tools/illink/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@

<PropertyGroup>
<Nullable>enable</Nullable>
<!-- Disable analyzer to prevent a circular dependency due to ProjectReference to ILLink.Tasks. -->
<EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
</PropertyGroup>
</Project>
</Project>
2 changes: 0 additions & 2 deletions src/tools/illink/src/ILLink.Tasks/ILLink.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeMultiTargetRoslynComponentTargets>false</IncludeMultiTargetRoslynComponentTargets>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddBuildOutputToToolsPackage</TargetsForTfmSpecificContentInPackage>
<!-- Disable analyzer to prevent a circular dependency due to PackageReference to the LKG Microsoft.NET.ILLink.Tasks. -->
<EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
</PropertyGroup>

<!-- Include the illink.runtimeconfig.pack.json file (which depends on the runtimeversion being built)
Expand Down

0 comments on commit 1ef38a8

Please sign in to comment.