Skip to content

Commit 261e7d3

Browse files
committed
Move [SkipLocalsInit] to shared .targets file
1 parent e896978 commit 261e7d3

File tree

7 files changed

+73
-26
lines changed

7 files changed

+73
-26
lines changed

src/CommunityToolkit.Common/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/CommunityToolkit.Diagnostics/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/CommunityToolkit.HighPerformance/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#if !NETSTANDARD2_1_OR_GREATER
56
using System.Runtime.CompilerServices;
67

7-
// We can suppress the .init flag for local variables for the entire module.
8-
// This doesn't affect the correctness of methods in this assembly, as none of them
9-
// are relying on the JIT ensuring that all local memory is zeroed out to work. Doing
10-
// this can provide some minor performance benefits, depending on the workload.
11-
[module: SkipLocalsInit]
12-
138
// We need to test the RuntimeHelpers polyfills on applicable runtimes
14-
#if !NETSTANDARD2_1_OR_GREATER
159
[assembly: InternalsVisibleTo("CommunityToolkit.HighPerformance.UnitTests, publickey=002400000480000094000000060200000024000052534131000400000100010041753AF735AE6140C9508567666C51C6AB929806ADB0D210694B30AB142A060237BC741F9682E7D8D4310364B4BBA4EE89CC9D3D5CE7E5583587E8EA44DCA09977996582875E71FB54FA7B170798D853D5D8010B07219633BDB761D01AC924DA44576D6180CDCEAE537973982BB461C541541D58417A3794E34F45E6F2D129E2")]
1610
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if !NET6_0_OR_GREATER
6+
7+
namespace System.Runtime.CompilerServices;
8+
9+
/// <summary>
10+
/// Used to indicate to the compiler that the <c>.locals init</c> flag should not be set in method headers.
11+
/// </summary>
12+
/// <remarks>Internal copy from the BCL attribute.</remarks>
13+
[AttributeUsage(
14+
AttributeTargets.Module |
15+
AttributeTargets.Class |
16+
AttributeTargets.Struct |
17+
AttributeTargets.Interface |
18+
AttributeTargets.Constructor |
19+
AttributeTargets.Method |
20+
AttributeTargets.Property |
21+
AttributeTargets.Event,
22+
Inherited = false)]
23+
internal sealed class SkipLocalsInitAttribute : Attribute
24+
{
25+
}
26+
27+
#endif

src/CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<ItemGroup>
3434
<Compile Include="$(MSBuildThisFileDirectory)Attributes\NotNullWhenAttribute.cs" />
3535
<Compile Include="$(MSBuildThisFileDirectory)Attributes\NullabilityAttributesGenerator.cs" />
36+
<Compile Include="$(MSBuildThisFileDirectory)Attributes\SkipLocalsInitAttribute.cs" />
3637
<Compile Include="$(MSBuildThisFileDirectory)ComponentModel\INotifyPropertyChangedGenerator.cs" />
3738
<Compile Include="$(MSBuildThisFileDirectory)ComponentModel\Models\AttributeInfo.cs" />
3839
<Compile Include="$(MSBuildThisFileDirectory)ComponentModel\Models\INotifyPropertyChangedInfo.cs" />

src/CommunityToolkit.Mvvm/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44

55
using System.Runtime.CompilerServices;
66

7-
// See notes in CommunityToolkit.HighPerformance for more info
8-
[module: SkipLocalsInit]
9-
107
[assembly: InternalsVisibleTo("CommunityToolkit.Mvvm.Internals.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010041753AF735AE6140C9508567666C51C6AB929806ADB0D210694B30AB142A060237BC741F9682E7D8D4310364B4BBA4EE89CC9D3D5CE7E5583587E8EA44DCA09977996582875E71FB54FA7B170798D853D5D8010B07219633BDB761D01AC924DA44576D6180CDCEAE537973982BB461C541541D58417A3794E34F45E6F2D129E2")]

src/Directory.Build.targets

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<Import Project="..\Directory.Build.targets" />
4+
5+
<!--
6+
The following target has been ported from TerraFX.Interop.Windows.
7+
See: https://github.com/terrafx/terrafx.interop.windows.
8+
Using [module: SkipLocalsInit] suppresses the .init flag for local variables for the entire module.
9+
This doesn't affect the correctness of methods in this assembly, as none of them are relying on the
10+
JIT ensuring that all local memory is zeroed out to work. Doing this can provide some minor
11+
performance benefits, depending on the workload.
12+
-->
13+
<PropertyGroup>
14+
<GeneratedSkipLocalsInitFile Condition="'$(GeneratedSkipLocalsInitFile)' == ''">$(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs</GeneratedSkipLocalsInitFile>
15+
<GeneratedSkipLocalsInitFileLines>
16+
<![CDATA[//------------------------------------------------------------------------------
17+
// <auto-generated>
18+
// This code was generated by a tool.
19+
//
20+
// Changes to this file may cause incorrect behavior and will be lost if
21+
// the code is regenerated.
22+
// </auto-generated>
23+
//------------------------------------------------------------------------------
24+
25+
[module: global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]>
26+
</GeneratedSkipLocalsInitFileLines>
27+
</PropertyGroup>
28+
29+
<Target Name="GenerateSkipLocalsInit"
30+
BeforeTargets="BeforeCompile;CoreCompile"
31+
DependsOnTargets="PrepareForBuild"
32+
Condition="'$(Language)' == 'C#'"
33+
Inputs="$(MSBuildAllProjects)"
34+
Outputs="$(GeneratedSkipLocalsInitFile)">
35+
36+
<!-- Write the file with the attribute -->
37+
<WriteLinesToFile Lines="$(GeneratedSkipLocalsInitFileLines)" Overwrite="true" WriteOnlyWhenDifferent="true" File="$(GeneratedSkipLocalsInitFile)" />
38+
39+
<!-- Include the generated file in the list of files to compile -->
40+
<ItemGroup>
41+
<Compile Include="$(GeneratedSkipLocalsInitFile)" />
42+
</ItemGroup>
43+
</Target>
44+
</Project>

0 commit comments

Comments
 (0)