Skip to content

Commit

Permalink
Centralize all performance-related properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Sep 20, 2024
1 parent 92d651e commit ebfecc4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 62 deletions.
29 changes: 29 additions & 0 deletions build/Directory.Build.Performance.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project>

<!--
Additional global options for all projects targeting Windows in their TFMs.
We actually set these in a .props file and without checking the framework, as:
- Setting these properties in non-Windows projects will just not do anything.
- Setting these from the shared .targets causes them to be imported too late.
They'd need to be added to "CustomBeforeMicrosoftCommonTargets" file, but the
complexity of having to set that up and validate it is just not worth it, as
we can just unconditionally set these and worst case, they'll be no-ops.
-->
<PropertyGroup>

<!--
Enable the CsWinRT trim/AOT analyzer for scenarios involving all types (including built-in types).
The .NET SDK sets this to '1' (which excludes built-in types) by default to reduce false positives.
-->
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>

<!--
We're only referencing CsWinRT for the source generators, we don't need to read any WinRT metadata.
CsWinRT is in projection mode by default, so we want to disable it (or it'd need the Windows SDK).
-->
<CsWinRTGenerateProjection>false</CsWinRTGenerateProjection>

<!-- We'll never have any IIDs to patch in any projects in the solution -->
<CsWinRTIIDOptimizerOptOut>true</CsWinRTIIDOptimizerOptOut>
</PropertyGroup>
</Project>
46 changes: 46 additions & 0 deletions build/Directory.Build.Performance.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project>

<!-- Properties exclusive to all .NET 8 projects (not just published projects) -->
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">

<!-- Emit the [DisableRuntimeMarshalling] attribute (also enables the associated analyzer) -->
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
</PropertyGroup>

<!--
The following target has been ported from TerraFX.Interop.Windows.
See: https://github.com/terrafx/terrafx.interop.windows.
This generates the [module: SkipLocalsInit] attribute for all projects.
-->
<PropertyGroup>
<GeneratedSkipLocalsInitFile Condition="'$(GeneratedSkipLocalsInitFile)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs</GeneratedSkipLocalsInitFile>
<GeneratedSkipLocalsInitFileLines>
<![CDATA[//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[module: System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]>
</GeneratedSkipLocalsInitFileLines>
</PropertyGroup>

<Target Name="GenerateSkipLocalsInit"
BeforeTargets="BeforeCompile;CoreCompile"
DependsOnTargets="PrepareForBuild"
Condition="'$(Language)' == 'C#'"
Inputs="$(MSBuildAllProjects)"
Outputs="$(GeneratedSkipLocalsInitFile)">

<!-- Write the file with the attribute -->
<WriteLinesToFile Lines="$(GeneratedSkipLocalsInitFileLines)" Overwrite="true" WriteOnlyWhenDifferent="true" File="$(GeneratedSkipLocalsInitFile)" />

<!-- Include the generated file in the list of files to compile -->
<ItemGroup>
<Compile Include="$(GeneratedSkipLocalsInitFile)" />
</ItemGroup>
</Target>
</Project>
2 changes: 2 additions & 0 deletions build/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,6 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\build\computesharp.snk</AssemblyOriginatorKeyFile>
<AssemblySignPublicKey>00240000048000009400000006020000002400005253413100040000010001001DA244ACFEE0D02ADF2D7F464B5E2562BB1AEF50B32DCD8B2DADEC659A5ED8B6C5817B03EB5E723067718A7972C936F626879DCE8E85636E7812B92CAB100D4947E3E6655AD49359E279A09F34B65E5ECA5FD5D8941C70BD48E56D8739A3BFF4F1C85071B7494D0B3A692F16CA6CC40585BCA8AD5B24BB2E7B834F15B6E667BB</AssemblySignPublicKey>
</PropertyGroup>

<Import Project="Directory.Build.Performance.props" />
</Project>
24 changes: 2 additions & 22 deletions build/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@
MSBuildAllProjects, as that is done by the file that imports us.
-->

<!--
Additional global options for all projects targeting Windows in their TFMs.
These must be in a .targets file because they need to read 'TargetFramework'.
-->
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows'))">

<!--
Enable the CsWinRT trim/AOT analyzer for scenarios involving all types (including built-in types).
The .NET SDK sets this to '1' (which excludes built-in types) by default to reduce false positives.
-->
<CsWinRTAotWarningLevel>2</CsWinRTAotWarningLevel>

<!--
We're only referencing CsWinRT for the source generators, we don't need to read any WinRT metadata.
CsWinRT is in projection mode by default, so we want to disable it (or it'd need the Windows SDK).
-->
<CsWinRTGenerateProjection>false</CsWinRTGenerateProjection>

<!-- We'll never have any IIDs to patch in this library -->
<CsWinRTIIDOptimizerOptOut>true</CsWinRTIIDOptimizerOptOut>
</PropertyGroup>

<!--
Manually set the version if null. This is copied from Microsoft.NET.DefaultAssemblyInfo.targets and is needed
for cases where that target is not being automatically imported (which happens because MSBuild is used instead
Expand Down Expand Up @@ -65,4 +43,6 @@
<AutoGen>True</AutoGen>
</Compile>
</ItemGroup>

<Import Project="Directory.Build.Performance.targets" />
</Project>
40 changes: 0 additions & 40 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
the analyzers will not run, so warnings will be skipped.
-->
<IsAotCompatible>true</IsAotCompatible>

<!-- Emit the [DisableRuntimeMarshalling] attribute (also enables the associated analyzer) -->
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
</PropertyGroup>

<!--
Expand All @@ -78,41 +75,4 @@
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<!--
The following target has been ported from TerraFX.Interop.Windows.
See: https://github.com/terrafx/terrafx.interop.windows.
This generates the [module: SkipLocalsInit] attribute for all projects.
-->
<PropertyGroup>
<GeneratedSkipLocalsInitFile Condition="'$(GeneratedSkipLocalsInitFile)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs</GeneratedSkipLocalsInitFile>
<GeneratedSkipLocalsInitFileLines>
<![CDATA[//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[module: System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]>
</GeneratedSkipLocalsInitFileLines>
</PropertyGroup>

<Target Name="GenerateSkipLocalsInit"
BeforeTargets="BeforeCompile;CoreCompile"
DependsOnTargets="PrepareForBuild"
Condition="'$(Language)' == 'C#'"
Inputs="$(MSBuildAllProjects)"
Outputs="$(GeneratedSkipLocalsInitFile)">

<!-- Write the file with the attribute -->
<WriteLinesToFile Lines="$(GeneratedSkipLocalsInitFileLines)" Overwrite="true" WriteOnlyWhenDifferent="true" File="$(GeneratedSkipLocalsInitFile)" />

<!-- Include the generated file in the list of files to compile -->
<ItemGroup>
<Compile Include="$(GeneratedSkipLocalsInitFile)" />
</ItemGroup>
</Target>
</Project>

0 comments on commit ebfecc4

Please sign in to comment.