Skip to content

Commit 4928e41

Browse files
authored
Merge pull request #1471 from microsoft/dev/andarno/nativeAOT
Add trim and NativeAOT safety attributes
2 parents 34347a3 + 5cb439e commit 4928e41

23 files changed

+392
-263
lines changed

Directory.Build.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141
<LangVersion Condition="'$(MSBuildProjectExtension)'=='.vbproj'">16.9</LangVersion>
4242
</PropertyGroup>
4343

44+
<PropertyGroup>
45+
<RidOsPrefix Condition="$([MSBuild]::IsOsPlatform('Windows'))">win</RidOsPrefix>
46+
<RidOsPrefix Condition="$([MSBuild]::IsOsPlatform('Linux'))">linux</RidOsPrefix>
47+
<RidOsPrefix Condition="$([MSBuild]::IsOsPlatform('OSX'))">osx</RidOsPrefix>
48+
49+
<RidOsArchitecture Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'x64'">x64</RidOsArchitecture>
50+
<RidOsArchitecture Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'ARM64'">arm64</RidOsArchitecture>
51+
52+
<DefaultRuntimeIdentifier>$(RidOsPrefix)-$(RidOsArchitecture)</DefaultRuntimeIdentifier>
53+
<!-- <AvailableRuntimeIdentifiers>$(RidOsPrefix)-arm64;$(RidOsPrefix)-x64</AvailableRuntimeIdentifiers> -->
54+
<AvailableRuntimeIdentifiers>$(DefaultRuntimeIdentifier)</AvailableRuntimeIdentifiers>
55+
</PropertyGroup>
56+
4457
<ItemGroup>
4558
<None Include="$(RepoRootPath)obj/NOTICE" Pack="true" PackagePath="" Visible="false" Condition=" Exists('$(RepoRootPath)obj/NOTICE') " />
4659
</ItemGroup>

Directory.Build.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
<!-- Avoid compile error about missing namespace when combining ImplicitUsings with .NET Framework target frameworks. -->
55
<Using Remove="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
66
</ItemGroup>
7+
8+
<Import Project="Directory.Traversal.targets" Condition="'$(IsTraversal)'=='true'" />
79
</Project>

Directory.Traversal.targets

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project>
2+
<PropertyGroup>
3+
<PackInParallel>true</PackInParallel>
4+
5+
<TestX64Binaries>false</TestX64Binaries>
6+
<TestArm64Binaries>false</TestArm64Binaries>
7+
<TestX64Binaries Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'x64'">true</TestX64Binaries>
8+
<TestArm64Binaries Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'ARM64'">true</TestArm64Binaries>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<!-- <ProjectReference Include="@(MultiRIDProjectReference)" AdditionalProperties="RuntimeIdentifier=$(RidOsPrefix)-x64" Test="$(TestX64Binaries)" />
12+
<ProjectReference Include="@(MultiRIDProjectReference)" AdditionalProperties="RuntimeIdentifier=$(RidOsPrefix)-arm64" Test="$(TestArm64Binaries)" /> -->
13+
<ProjectReference Include="@(MultiRIDProjectReference)" AdditionalProperties="RuntimeIdentifier=$(DefaultRuntimeIdentifier);TargetFramework=%(TargetFramework)" Test="true" />
14+
</ItemGroup>
15+
</Project>

Microsoft.VisualStudio.Threading.slnx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@
1111
<File Path="Directory.Build.props" />
1212
<File Path="Directory.Build.targets" />
1313
<File Path="Directory.Packages.props" />
14+
<File Path="Directory.Traversal.targets" />
1415
<File Path="global.json" />
1516
<File Path="nuget.config" />
1617
<File Path="stylecop.json" />
1718
<File Path="version.json" />
1819
</Folder>
20+
<Folder Name="/Solution Items/tools/">
21+
<File Path="tools/dirs.proj" />
22+
</Folder>
1923
<Folder Name="/src/">
2024
<File Path="src/.editorconfig" />
2125
<File Path="src/AssemblyInfo.cs" />
2226
<File Path="src/Directory.Build.props" />
2327
<File Path="src/Directory.Build.targets" />
28+
<File Path="src/dirs.proj" />
2429
<Project Path="src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes.csproj" />
2530
<Project Path="src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj" />
2631
<Project Path="src/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic.csproj" />
@@ -33,12 +38,15 @@
3338
</Folder>
3439
<Folder Name="/test/">
3540
<File Path="test/.editorconfig" />
41+
<File Path="test/AOT.props" />
3642
<File Path="test/Directory.Build.props" />
3743
<File Path="test/Directory.Build.targets" />
44+
<File Path="test/dirs.proj" />
3845
<Project Path="samples/samples.csproj" />
3946
<Project Path="test/IsolatedTestHost/IsolatedTestHost.csproj" />
4047
<Project Path="test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj" />
4148
<Project Path="test/Microsoft.VisualStudio.Threading.Tests.Win7RegistryWatcher/Microsoft.VisualStudio.Threading.Tests.Win7RegistryWatcher.csproj" />
4249
<Project Path="test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj" />
50+
<Project Path="test/NativeAOTCompatibility.Test/NativeAOTCompatibility.Test.csproj" />
4351
</Folder>
4452
</Solution>

azure-pipelines/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ jobs:
200200
Is1ESPT: ${{ parameters.Is1ESPT }}
201201
RunTests: ${{ parameters.RunTests }}
202202
IsOptProf: ${{ parameters.IsOptProf }}
203+
osRID: win
203204

204205
- ${{ if and(parameters.EnableDotNetFormatCheck, not(parameters.EnableLinuxBuild)) }}:
205206
- script: dotnet format --verify-no-changes
@@ -244,6 +245,7 @@ jobs:
244245
parameters:
245246
Is1ESPT: ${{ parameters.Is1ESPT }}
246247
RunTests: ${{ parameters.RunTests }}
248+
osRID: linux
247249
- ${{ if parameters.EnableDotNetFormatCheck }}:
248250
- script: dotnet format --verify-no-changes
249251
displayName: 💅 Verify formatted code
@@ -279,6 +281,7 @@ jobs:
279281
parameters:
280282
Is1ESPT: ${{ parameters.Is1ESPT }}
281283
RunTests: ${{ parameters.RunTests }}
284+
osRID: osx
282285

283286
- job: WrapUp
284287
dependsOn:

azure-pipelines/dotnet.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ parameters:
55
default: false
66
- name: Is1ESPT
77
type: boolean
8+
- name: osRID
9+
type: string
810

911
steps:
1012

11-
- script: dotnet build -t:build,pack --no-restore -c $(BuildConfiguration) -warnAsError -warnNotAsError:NU1901,NU1902,NU1903,NU1904,LOCTASK002 /bl:"$(Build.ArtifactStagingDirectory)/build_logs/build.binlog"
13+
- script: dotnet build tools/dirs.proj -t:build,pack,publish --no-restore -c $(BuildConfiguration) -warnAsError -warnNotAsError:NU1901,NU1902,NU1903,NU1904,LOCTASK002 /bl:"$(Build.ArtifactStagingDirectory)/build_logs/build.binlog"
1214
displayName: 🛠 dotnet build
1315

1416
- ${{ if not(parameters.IsOptProf) }}:

global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"msbuild-sdks": {
88
"MSBuild.Sdk.Extras": "3.0.44",
9-
"Microsoft.Build.NoTargets": "3.7.56"
9+
"Microsoft.Build.NoTargets": "3.7.56",
10+
"Microsoft.Build.Traversal": "4.1.82"
1011
}
1112
}

src/Microsoft.VisualStudio.Threading/AsyncReaderWriterLock+HangReportContributor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Globalization;
78
using System.Linq;
89
using System.Text;
910
using System.Threading;
10-
using System.Threading.Tasks;
1111
using System.Xml.Linq;
1212

1313
namespace Microsoft.VisualStudio.Threading
@@ -46,6 +46,7 @@ protected internal virtual SynchronizationContext NoMessagePumpSynchronizationCo
4646
/// Contributes data for a hang report.
4747
/// </summary>
4848
/// <returns>The hang report contribution. Null values should be ignored.</returns>
49+
[RequiresUnreferencedCode(Reasons.DiagnosticAnalysisOnly)]
4950
HangReportContribution IHangReportContributor.GetHangReport()
5051
{
5152
return this.GetHangReport();
@@ -55,7 +56,8 @@ HangReportContribution IHangReportContributor.GetHangReport()
5556
/// Contributes data for a hang report.
5657
/// </summary>
5758
/// <returns>The hang report contribution. Null values should be ignored.</returns>
58-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
59+
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity"), SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
60+
[RequiresUnreferencedCode(Reasons.DiagnosticAnalysisOnly)]
5961
protected virtual HangReportContribution GetHangReport()
6062
{
6163
using (this.NoMessagePumpSynchronizationContext.Apply())
@@ -125,6 +127,7 @@ private static XDocument CreateDgml(out XElement nodes, out XElement links)
125127
/// <summary>
126128
/// Appends details of a given collection of awaiters to the hang report.
127129
/// </summary>
130+
[RequiresUnreferencedCode(Reasons.DiagnosticAnalysisOnly)]
128131
private static XElement CreateAwaiterNode(Awaiter awaiter)
129132
{
130133
Requires.NotNull(awaiter, nameof(awaiter));
@@ -211,9 +214,13 @@ public IEnumerable<string> Categories
211214
{
212215
get
213216
{
217+
#if NET
218+
foreach (AwaiterCollection value in Enum.GetValues<AwaiterCollection>())
219+
#else
214220
#pragma warning disable CS8605 // Unboxing a possibly null value.
215221
foreach (AwaiterCollection value in Enum.GetValues(typeof(AwaiterCollection)))
216222
#pragma warning restore CS8605 // Unboxing a possibly null value.
223+
#endif
217224
{
218225
if (this.Membership.HasFlag(value))
219226
{
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
4+
using System.Diagnostics.CodeAnalysis;
95

106
namespace Microsoft.VisualStudio.Threading;
117

@@ -18,5 +14,6 @@ public interface IHangReportContributor
1814
/// Contributes data for a hang report.
1915
/// </summary>
2016
/// <returns>The hang report contribution. Null values should be ignored.</returns>
17+
[RequiresUnreferencedCode(Reasons.DiagnosticAnalysisOnly)]
2118
HangReportContribution GetHangReport();
2219
}

0 commit comments

Comments
 (0)