Skip to content

Commit 428eb39

Browse files
[release/6.0-preview5] Add support for Pgo Mibc files to be used by the SDK (#17930)
Port #17769 to preview 5. - A new ItemList (PublishReadyToRunPgoFiles) can be used to specify a custom list of Mibc files - Any Mibc files defined in associated RuntimePacks via a RuntimeAsset with AssetType PgoData will also be included This behavior can be disabled by setting PublishReadyToRunUseRuntimePackOptimizationData to false
1 parent 746505d commit 428eb39

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ private void AddRuntimePackAssetsFromManifest(List<ITaskItem> runtimePackAssets,
118118
{
119119
assetType = "native";
120120
}
121+
else if (typeAttributeValue.Equals("PgoData", StringComparison.OrdinalIgnoreCase))
122+
{
123+
assetType = "pgodata";
124+
}
121125
else if (typeAttributeValue.Equals("Resources", StringComparison.OrdinalIgnoreCase))
122126
{
123127
assetType = "resources";
@@ -166,7 +170,9 @@ private static TaskItem CreateAssetItem(string assetPath, string assetType, ITas
166170

167171
var assetItem = new TaskItem(assetPath);
168172

169-
assetItem.SetMetadata(MetadataKeys.CopyLocal, "true");
173+
if (assetType != "pgodata")
174+
assetItem.SetMetadata(MetadataKeys.CopyLocal, "true");
175+
170176
if (string.IsNullOrEmpty(culture))
171177
{
172178
assetItem.SetMetadata(MetadataKeys.DestinationSubPath, Path.GetFileName(assetPath));

src/Tasks/Microsoft.NET.Build.Tasks/ResolvedFile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ internal enum AssetType
1313
None,
1414
Runtime,
1515
Native,
16-
Resources
16+
Resources,
17+
PgoData
1718
}
1819

1920
internal class ResolvedFile

src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class RunReadyToRunCompiler : ToolTask
2525
public bool ShowCompilerWarnings { get; set; }
2626
public bool UseCrossgen2 { get; set; }
2727
public string Crossgen2ExtraCommandLineArgs { get; set; }
28+
public ITaskItem[] Crossgen2PgoFiles { get; set; }
2829

2930
[Output]
3031
public bool WarningsDetected { get; set; }
@@ -329,6 +330,14 @@ private string GenerateCrossgen2ResponseFile()
329330
}
330331
}
331332

333+
if (Crossgen2PgoFiles != null)
334+
{
335+
foreach (var mibc in Crossgen2PgoFiles)
336+
{
337+
result.AppendLine($"-m:\"{mibc.ItemSpec}\"");
338+
}
339+
}
340+
332341
if (!string.IsNullOrEmpty(Crossgen2ExtraCommandLineArgs))
333342
{
334343
foreach (string extraArg in Crossgen2ExtraCommandLineArgs.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries))

src/Tasks/Microsoft.NET.Build.Tasks/RuntimePackAssetInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public static RuntimePackAssetInfo FromItem(ITaskItem item)
3939
{
4040
assetInfo.AssetType = AssetType.Resources;
4141
}
42+
else if (assetTypeString.Equals("pgodata", StringComparison.OrdinalIgnoreCase))
43+
{
44+
assetInfo.AssetType = AssetType.PgoData;
45+
}
4246
else
4347
{
4448
throw new InvalidOperationException("Unexpected asset type: " + item.GetMetadata(MetadataKeys.AssetType));

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Copyright (c) .NET Foundation. All rights reserved.
1717
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunComposite)' == '' and '$(_TargetFrameworkVersionWithoutV)' >= '6.0'">false</PublishReadyToRunComposite>
1818
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunComposite)' == ''">true</PublishReadyToRunComposite>
1919
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunUseCrossgen2)' != 'true' or '$(SelfContained)' != 'true'">false</PublishReadyToRunComposite>
20+
<PublishReadyToRunUseRuntimePackOptimizationData Condition="'$(PublishReadyToRunUseRuntimePackOptimizationData)' == ''">true</PublishReadyToRunUseRuntimePackOptimizationData>
2021
</PropertyGroup>
2122

2223
<!--
@@ -367,7 +368,7 @@ Copyright (c) .NET Foundation. All rights reserved.
367368
Prepare build for ReadyToRun compilations. Builds list of assemblies to compile, and computes paths to ReadyToRun compiler bits
368369
============================================================
369370
-->
370-
<UsingTask Condition="'$(Crossgen2TasksOverriden)' != 'true'" TaskName="PrepareForReadyToRunCompilation" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)"/>
371+
<UsingTask Condition="'$(Crossgen2TasksOverriden)' != 'true'" TaskName="PrepareForReadyToRunCompilation" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
371372
<Target Name="_PrepareForReadyToRunCompilation" DependsOnTargets="ResolveReadyToRunCompilers;_ComputeManagedRuntimePackAssemblies;_ComputeAssembliesToPostprocessOnPublish">
372373

373374
<PropertyGroup>
@@ -397,6 +398,12 @@ Copyright (c) .NET Foundation. All rights reserved.
397398
<_ReadyToRunImplementationAssemblies Include="@(_ReadyToRunImplementationAssembliesWithoutConflicts)" />
398399
</ItemGroup>
399400

401+
<ItemGroup>
402+
<_ReadyToRunPgoFiles Include="@(PublishReadyToRunPgoFiles)" />
403+
<_ReadyToRunPgoFiles Include="@(RuntimePackAsset)"
404+
Condition="'%(RuntimePackAsset.AssetType)' == 'pgodata' and '%(RuntimePackAsset.Extension)' == '.mibc' and '$(PublishReadyToRunUseRuntimePackOptimizationData)' == 'true'" />
405+
</ItemGroup>
406+
400407
<PrepareForReadyToRunCompilation CrossgenTool="@(CrossgenTool)"
401408
Crossgen2Tool="@(Crossgen2Tool)"
402409
OutputPath="$(_ReadyToRunOutputPath)"
@@ -444,12 +451,13 @@ Copyright (c) .NET Foundation. All rights reserved.
444451
-->
445452
<UsingTask Condition="'$(Crossgen2TasksOverriden)' != 'true'" TaskName="RunReadyToRunCompiler" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
446453
<Target Name="_CreateR2RImages"
447-
Inputs="@(_ReadyToRunCompileList);@(_ReadyToRunCompositeBuildInput)"
454+
Inputs="@(_ReadyToRunCompileList);@(_ReadyToRunCompositeBuildInput);@(_ReadyToRunPgoFiles)"
448455
Outputs="%(_ReadyToRunCompileList.OutputR2RImage);%(_ReadyToRunCompileList.OutputPDBImage)">
449456

450457
<RunReadyToRunCompiler CrossgenTool="@(CrossgenTool)"
451458
Crossgen2Tool="@(Crossgen2Tool)"
452459
UseCrossgen2="$(PublishReadyToRunUseCrossgen2)"
460+
Crossgen2PgoFiles="@(_ReadyToRunPgoFiles)"
453461
Crossgen2ExtraCommandLineArgs="$(PublishReadyToRunCrossgen2ExtraArgs)"
454462
ImplementationAssemblyReferences="@(_ReadyToRunAssembliesToReference)"
455463
ShowCompilerWarnings="$(PublishReadyToRunShowWarnings)"

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ Copyright (c) .NET Foundation. All rights reserved.
499499

500500
<ItemGroup>
501501
<_ResolvedCopyLocalPublishAssets Include="@(RuntimePackAsset)"
502-
Condition="'$(SelfContained)' == 'true' Or '%(RuntimePackAsset.RuntimePackAlwaysCopyLocal)' == 'true'" />
502+
Condition="('$(SelfContained)' == 'true' Or '%(RuntimePackAsset.RuntimePackAlwaysCopyLocal)' == 'true') and '%(RuntimePackAsset.AssetType)' != 'pgodata'" />
503503
</ItemGroup>
504504

505505
<ItemGroup Condition="'$(_UseBuildDependencyFile)' != 'true'">

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ Copyright (c) .NET Foundation. All rights reserved.
398398

399399
<ItemGroup>
400400
<ReferenceCopyLocalPaths Include="@(RuntimePackAsset)"
401-
Condition="'$(CopyLocalLockFileAssemblies)' == 'true' and ('$(SelfContained)' == 'true' or '%(RuntimePackAsset.RuntimePackAlwaysCopyLocal)' == 'true')" />
401+
Condition="'$(CopyLocalLockFileAssemblies)' == 'true' and ('$(SelfContained)' == 'true' or '%(RuntimePackAsset.RuntimePackAlwaysCopyLocal)' == 'true') and '%(RuntimePackAsset.AssetType)' != 'pgodata'" />
402402
</ItemGroup>
403403

404404

0 commit comments

Comments
 (0)