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

Use current runtime version in ILLink.Tasks package #90197

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 4 additions & 3 deletions eng/packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@
<Target Name="AddBuildOutputToToolsPackage">
<ItemGroup>
<!-- Include build outputs in the package under tools directory. -->
<TfmSpecificPackageFile Include="$(OutputPath)**"
Exclude="$(OutputPath)publish\**;
$(OutputPath)"
<_BuildOutputPackageFile Include="$(OutputPath)**"
Exclude="$(OutputPath)publish\**;
$(OutputPath)" />
<TfmSpecificPackageFile Include="@(_BuildOutputPackageFile)"
Comment on lines +277 to +280
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain this change? I'm not sure what it is doing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Before this change, the PackagePath was just tools/$(TargetFramework)/ - the %(RecursiveDir)%(FileName)%(Extension) part was empty because the itemgroup hadn't been defined, and the build output was showing:

packaging.targets(280,30): message : MSB4120: Item 'TfmSpecificPackageFile' definition within target references itself via (qualified or unqualified) metadatum 'RecursiveDir'. This can lead to unintended expansion and cross-applying of pre-existing items. More info: https://aka.ms/msbuild/metadata-self-ref [/home/svbomer/src/runtime/src/tools/illink/src/ILLink.Tasks/ILLink.Tasks.csproj::TargetFramework=net8.0]

I needed the filename to be included to make it easier to filter later.

PackagePath="tools/$(TargetFramework)/%(RecursiveDir)%(FileName)%(Extension)" />
<TfmSpecificDebugSymbolsFile Include="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))"
TargetPath="/%(TfmSpecificPackageFile.PackagePath)/%(Filename)%(Extension)"
Expand Down
9 changes: 0 additions & 9 deletions eng/testing/linker/SupportFiles/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<Project>

<!-- Use live illink bits. It is necessary to both import the package props and override
the tasks assembly, because the live package props in the build output do not use
the same layout as the NuGet package. -->
<Import Project="$(ToolsILLinkDir)$(NetCoreAppToolCurrent)/build/Microsoft.NET.ILLink.Tasks.props" />
<PropertyGroup>
<ILLinkTasksAssembly>$(ToolsILLinkDir)$(NetCoreAppToolCurrent)/ILLink.Tasks.dll</ILLinkTasksAssembly>
</PropertyGroup>

<PropertyGroup>
<SkipConfigureTrimming>true</SkipConfigureTrimming>
<PublishTrimmed>true</PublishTrimmed>
Expand Down
14 changes: 10 additions & 4 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Needed for PublishTrimmed -->
<NetCoreAppToolCurrent>{NetCoreAppToolCurrent}</NetCoreAppToolCurrent>
<ToolsILLinkDir>{ToolsILLinkDir}</ToolsILLinkDir>
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<!-- Use live illink bits. It is necessary to both import the package props and override
the tasks assembly, because the live package props in the build output do not use
the same layout as the NuGet package. -->
<!-- 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>
<ILLinkTasksAssembly>$(ToolsILLinkDir)$(NetCoreAppToolCurrent)/ILLink.Tasks.dll</ILLinkTasksAssembly>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>{TargetFramework}</TargetFramework>
Expand Down Expand Up @@ -84,6 +92,4 @@

<Import Project="{NativeSanitizersTargets}" />

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

</Project>
14 changes: 14 additions & 0 deletions src/tools/illink/src/ILLink.Tasks/ILLink.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
<EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
</PropertyGroup>

<!-- Include the illink.runtimeconfig.pack.json file (which depends on the runtimeversion being built)
as illink.runtime.config.json in the package, instead of the original illink.runtime.config.json. -->
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<Target Name="FixPackageRuntimeConfigPath"
AfterTargets="AddBuildOutputToToolsPackage"
Condition="'$(TargetFramework)' == '$(NetCoreAppToolCurrent)'">
<ItemGroup>
<TfmSpecificPackageFile Remove="@(TfmSpecificPackageFile)"
Condition="$([System.String]::Copy('%(Identity)').EndsWith('.runtimeconfig.json'))" />
<TfmSpecificPackageFile
Condition="$([System.String]::Copy('%(TfmSpecificPackageFile.PackagePath)').EndsWith('.pack.json'))"
PackagePath="$([System.String]::Copy(%(TfmSpecificPackageFile.PackagePath)).Substring(0, $([MSBuild]::Subtract($([System.String]::Copy('%(TfmSpecificPackageFile.PackagePath)').Length), 10)))).json" />
</ItemGroup>
</Target>

<ItemGroup>
<!-- Note: 'build/Microsoft.NET.ILLink.targets' should not match the package name, because we don't want the targets
to be imported by nuget. The SDK will import them in the right order. -->
Expand Down
37 changes: 37 additions & 0 deletions src/tools/illink/src/linker/Mono.Linker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,43 @@
<DefineConstants>$(DefineConstants);ILLINK</DefineConstants>
</PropertyGroup>

<Target Name="_ComputePackRuntimeConfigFilePath">
<PropertyGroup>
<PackRuntimeConfigFilePath>$([System.IO.Path]::ChangeExtension($(ProjectRuntimeConfigFilePath), pack.json))</PackRuntimeConfigFilePath>
</PropertyGroup>
</Target>

<!-- Generate a runtimeconfig.pack.json file that has the runtime version replaced by version of dotnet/runtime being built.
This will be the version used by the ILLink.Tasks package. -->
<Target Name="GeneratePackageRuntimeConfig" AfterTargets="GenerateBuildRuntimeConfigurationFiles"
DependsOnTargets="_ComputePackRuntimeConfigFilePath"
Condition="'$(TargetFramework)' == '$(NetCoreAppToolCurrent)'">
<PropertyGroup>
<_RuntimeConfigContents>$([System.IO.File]::ReadAllText('$(ProjectRuntimeConfigFilePath)'))</_RuntimeConfigContents>
<ReplacementPattern>"version": ".*"</ReplacementPattern>
<ReplacementString>"version": "$(Version)"</ReplacementString>
<_NewRuntimeConfigContents>$([System.Text.RegularExpressions.Regex]::Replace($(_RuntimeConfigContents), $(ReplacementPattern), $(ReplacementString)))</_NewRuntimeConfigContents>
</PropertyGroup>

<WriteLinesToFile File="$(PackRuntimeConfigFilePath)"
Lines="$(_NewRuntimeConfigContents)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
</Target>

<!-- Ensure that the pack.json file flows to ILLink.Tasks so that it can be included in the package.
The original runtimeconfig.json file (included by default) is also needed so that projects which use
the ILLink.Tasks build output can run illink using the LKG SDK. -->
<Target Name="AddPackageRuntimeConfigToCopyItemsForReferencingProjects"
DependsOnTargets="_ComputePackRuntimeConfigFilePath"
AfterTargets="AddDepsJsonAndRuntimeConfigToCopyItemsForReferencingProjects">
<ItemGroup>
<AllItemsFullPathWithTargetPath Include="$(PackRuntimeConfigFilePath)"
TargetPath="$([System.IO.Path]::GetFileName($(PackRuntimeConfigFilePath)))"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>

<!-- The default pack logic will include the implementation assembly in lib.
This also adds the reference assembly under ref. -->
<Target Name="_AddReferenceAssemblyToPackage" DependsOnTargets="ResolveProjectReferences">
Expand Down
Loading