Skip to content

Commit 4c2e66e

Browse files
authored
Enable AOT analysis and fix warnings (#1924)
1 parent 45dd5d1 commit 4c2e66e

22 files changed

+312
-180
lines changed

Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Grpc.DotNet.ruleset</CodeAnalysisRuleset>
2020

2121
<IsTrimmable>true</IsTrimmable>
22+
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
2223
</PropertyGroup>
2324

2425
<!-- IsGrpcPublishedPackage is set in csproj so related config must be in targets file -->

build/dependencies.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<MicrosoftCodeAnalysisNetAnalyzersPackageVersion>7.0.0-preview1.22464.1</MicrosoftCodeAnalysisNetAnalyzersPackageVersion>
1616
<MicrosoftCrankEventSourcesPackageVersion>0.2.0-alpha.21255.1</MicrosoftCrankEventSourcesPackageVersion>
1717
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.1</MicrosoftExtensionsLoggingTestingPackageVersion>
18-
<MicrosoftExtensionsPackageVersion>3.0.3</MicrosoftExtensionsPackageVersion>
18+
<MicrosoftExtensionsPackageVersion>7.0.0-rc.2.22472.3</MicrosoftExtensionsPackageVersion>
19+
<MicrosoftExtensions3PackageVersion>3.0.3</MicrosoftExtensions3PackageVersion>
1920
<MicrosoftNETTestSdkPackageVersion>16.9.1</MicrosoftNETTestSdkPackageVersion>
2021
<MicrosoftSourceLinkGitHubPackageVersion>1.0.0</MicrosoftSourceLinkGitHubPackageVersion>
2122
<MicrosoftWin32RegistryLinePackageVersion>4.6.0</MicrosoftWin32RegistryLinePackageVersion>

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.100-preview.4.22252.9",
4-
"rollForward": "latestMajor"
3+
"version": "7.0.100-rc.2.22477.23",
4+
"rollForward": "latestMinor"
55
}
66
}

perf/benchmarkapps/GrpcAspNetCoreServer/GrpcAspNetCoreServer.csproj

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,23 @@
3838
</Content>
3939

4040
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
41-
</ItemGroup>
42-
43-
<ItemGroup Condition="'$(EnableGrpcWeb)' == 'true'">
44-
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
45-
</ItemGroup>
46-
47-
<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0))">
48-
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Server\Grpc.AspNetCore.Server.csproj" />
49-
5041
<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
5142
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" PrivateAssets="All" />
52-
5343
<!--
5444
TODO(JamesNK): This package ref should use MicrosoftAspNetCoreAppPackageVersion.
5545
There is currently an issue using 6.0 versions so hardcode to 5.0
5646
-->
5747
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="5.0.1" />
5848
</ItemGroup>
5949

60-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
61-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.23.2" />
62-
<PackageReference Include="Google.Protobuf" Version="3.9.1" />
63-
<PackageReference Include="Grpc.Tools" Version="2.23.0" PrivateAssets="All" />
50+
<!-- TODO: Workaround https://github.com/dotnet/sdk/issues/28169. Remove when fixed. -->
51+
<ItemGroup Condition="'$(PublishAot)'!='true'">
52+
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Server\Grpc.AspNetCore.Server.csproj" />
53+
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
6454
</ItemGroup>
55+
<ItemGroup Condition="'$(PublishAot)'=='true'">
56+
<PackageReference Include="Grpc.AspNetCore.Server" Version="$(GrpcDotNetPackageVersion)" />
57+
<PackageReference Include="Grpc.AspNetCore.Web" Version="$(GrpcDotNetPackageVersion)" />
58+
</ItemGroup>
59+
6560
</Project>

perf/benchmarkapps/GrpcAspNetCoreServer/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#endregion
1818

19+
using System.Diagnostics.CodeAnalysis;
1920
using System.Reflection;
2021
using System.Runtime;
2122
using Common;
@@ -31,6 +32,8 @@ public static void Main(string[] args)
3132
CreateHostBuilder(args).Build().Run();
3233
}
3334

35+
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode",
36+
Justification = "DependencyInjection only used with safe types.")]
3437
public static IHostBuilder CreateHostBuilder(string[] args)
3538
{
3639
var runtimeVersion = typeof(object).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";
@@ -42,7 +45,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
4245
Console.WriteLine("----------------------------");
4346
Console.WriteLine($"Args: {string.Join(' ', args)}");
4447
Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");
45-
Console.WriteLine($"WebHostBuilder loading from: {typeof(WebHostBuilder).GetTypeInfo().Assembly.Location}");
48+
Console.WriteLine($"WebHostBuilder loading from: {AppContext.BaseDirectory}");
4649
Console.WriteLine($"NetCoreAppVersion: {runtimeVersion}");
4750
Console.WriteLine($"{nameof(GCSettings.IsServerGC)}: {isServerGC}");
4851
Console.WriteLine($"{nameof(Environment.ProcessorCount)}: {processorCount}");
@@ -124,7 +127,7 @@ public static IHostBuilder CreateHostBuilder(string[] args)
124127

125128
private static void ConfigureListenOptions(ListenOptions listenOptions, IConfigurationRoot config, System.Net.IPEndPoint endPoint)
126129
{
127-
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
130+
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory);
128131
var certPath = Path.Combine(basePath!, "Certs", "server1.pfx");
129132

130133
var protocol = config["protocol"] ?? "";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Param
2+
(
3+
[string]$protocol = "h2c",
4+
[string]$log_level = "None",
5+
[bool]$enable_cert_auth = $false,
6+
[bool]$publish_aot = $false
7+
)
8+
9+
# Command line example:
10+
# .\RunGrpcServer.ps1 -publish_aot $true
11+
12+
Write-Host "Protocol: $protocol" -ForegroundColor Cyan
13+
Write-Host "Log level: $log_level" -ForegroundColor Cyan
14+
Write-Host "Enable cert auth: $enable_cert_auth" -ForegroundColor Cyan
15+
Write-Host "Publish AOT: $publish_aot" -ForegroundColor Cyan
16+
Write-Host
17+
18+
dotnet publish -r win-x64 -c Release --self-contained --output bin\Publish -p:PublishAot=$publish_aot
19+
if ($LASTEXITCODE -ne 0)
20+
{
21+
exit;
22+
}
23+
24+
.\bin\Publish\GrpcAspNetCoreServer.exe --protocol $protocol --logLevel $log_level --enableCertAuth $enable_cert_auth
25+
Write-Host
26+
27+
Write-Host "Done" -ForegroundColor Cyan
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"urls": "",
33
"server.urls": "",
4-
"protocol": "h3", // This will be overriden when benchmarks are run
4+
"protocol": "h2c", // This will be overriden when benchmarks are run
55
"certificateAuth": false,
66
"LogLevel": ""
77
}

perf/benchmarkapps/GrpcClient/GrpcClient.csproj

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsPackageVersion)" />
2929
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
3030
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLinePackageVersion)" />
31+
32+
<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
33+
<PackageReference Include="Grpc.Core" Version="$(GrpcPackageVersion)" />
34+
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" PrivateAssets="All" />
3135
</ItemGroup>
3236

3337
<ItemGroup>
@@ -42,23 +46,17 @@
4246
</None>
4347
</ItemGroup>
4448

45-
<ItemGroup Condition="'$(EnableGrpcWeb)' == 'true'">
46-
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
49+
<!-- TODO: Workaround https://github.com/dotnet/sdk/issues/28169. Remove when fixed. -->
50+
<ItemGroup Condition="'$(PublishAot)'!='true'">
51+
<ProjectReference Include="..\..\..\src\Grpc.Net.Client\Grpc.Net.Client.csproj" />
52+
</ItemGroup>
53+
<ItemGroup Condition="'$(PublishAot)'=='true'">
54+
<PackageReference Include="Grpc.Net.Client" Version="$(GrpcDotNetPackageVersion)" />
4755
</ItemGroup>
4856

49-
<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0))">
50-
<ProjectReference Include="..\..\..\src\Grpc.Net.Client\Grpc.Net.Client.csproj" />
5157

52-
<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
53-
<PackageReference Include="Grpc.Core" Version="$(GrpcPackageVersion)" />
54-
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" PrivateAssets="All" />
55-
</ItemGroup>
58+
<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0))">
5659

57-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
58-
<PackageReference Include="Grpc.Net.Client" Version="2.23.2" />
59-
<PackageReference Include="Google.Protobuf" Version="3.9.1" />
60-
<PackageReference Include="Grpc.Core" Version="2.23.0" />
61-
<PackageReference Include="Grpc.Tools" Version="2.23.0" PrivateAssets="All" />
6260
</ItemGroup>
6361

6462
</Project>

0 commit comments

Comments
 (0)