Skip to content

Commit

Permalink
Enable AOT analysis and fix warnings (#1924)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Oct 24, 2022
1 parent 45dd5d1 commit 4c2e66e
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 180 deletions.
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Grpc.DotNet.ruleset</CodeAnalysisRuleset>

<IsTrimmable>true</IsTrimmable>
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
</PropertyGroup>

<!-- IsGrpcPublishedPackage is set in csproj so related config must be in targets file -->
Expand Down
3 changes: 2 additions & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<MicrosoftCodeAnalysisNetAnalyzersPackageVersion>7.0.0-preview1.22464.1</MicrosoftCodeAnalysisNetAnalyzersPackageVersion>
<MicrosoftCrankEventSourcesPackageVersion>0.2.0-alpha.21255.1</MicrosoftCrankEventSourcesPackageVersion>
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.1</MicrosoftExtensionsLoggingTestingPackageVersion>
<MicrosoftExtensionsPackageVersion>3.0.3</MicrosoftExtensionsPackageVersion>
<MicrosoftExtensionsPackageVersion>7.0.0-rc.2.22472.3</MicrosoftExtensionsPackageVersion>
<MicrosoftExtensions3PackageVersion>3.0.3</MicrosoftExtensions3PackageVersion>
<MicrosoftNETTestSdkPackageVersion>16.9.1</MicrosoftNETTestSdkPackageVersion>
<MicrosoftSourceLinkGitHubPackageVersion>1.0.0</MicrosoftSourceLinkGitHubPackageVersion>
<MicrosoftWin32RegistryLinePackageVersion>4.6.0</MicrosoftWin32RegistryLinePackageVersion>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100-preview.4.22252.9",
"rollForward": "latestMajor"
"version": "7.0.100-rc.2.22477.23",
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,23 @@
</Content>

<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(EnableGrpcWeb)' == 'true'">
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0))">
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Server\Grpc.AspNetCore.Server.csproj" />

<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" PrivateAssets="All" />

<!--
TODO(JamesNK): This package ref should use MicrosoftAspNetCoreAppPackageVersion.
There is currently an issue using 6.0 versions so hardcode to 5.0
-->
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="5.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.23.2" />
<PackageReference Include="Google.Protobuf" Version="3.9.1" />
<PackageReference Include="Grpc.Tools" Version="2.23.0" PrivateAssets="All" />
<!-- TODO: Workaround https://github.com/dotnet/sdk/issues/28169. Remove when fixed. -->
<ItemGroup Condition="'$(PublishAot)'!='true'">
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Server\Grpc.AspNetCore.Server.csproj" />
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(PublishAot)'=='true'">
<PackageReference Include="Grpc.AspNetCore.Server" Version="$(GrpcDotNetPackageVersion)" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="$(GrpcDotNetPackageVersion)" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions perf/benchmarkapps/GrpcAspNetCoreServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#endregion

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime;
using Common;
Expand All @@ -31,6 +32,8 @@ public static void Main(string[] args)
CreateHostBuilder(args).Build().Run();
}

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

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

var protocol = config["protocol"] ?? "";
Expand Down
27 changes: 27 additions & 0 deletions perf/benchmarkapps/GrpcAspNetCoreServer/RunGrpcServer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Param
(
[string]$protocol = "h2c",
[string]$log_level = "None",
[bool]$enable_cert_auth = $false,
[bool]$publish_aot = $false
)

# Command line example:
# .\RunGrpcServer.ps1 -publish_aot $true

Write-Host "Protocol: $protocol" -ForegroundColor Cyan
Write-Host "Log level: $log_level" -ForegroundColor Cyan
Write-Host "Enable cert auth: $enable_cert_auth" -ForegroundColor Cyan
Write-Host "Publish AOT: $publish_aot" -ForegroundColor Cyan
Write-Host

dotnet publish -r win-x64 -c Release --self-contained --output bin\Publish -p:PublishAot=$publish_aot
if ($LASTEXITCODE -ne 0)
{
exit;
}

.\bin\Publish\GrpcAspNetCoreServer.exe --protocol $protocol --logLevel $log_level --enableCertAuth $enable_cert_auth
Write-Host

Write-Host "Done" -ForegroundColor Cyan
2 changes: 1 addition & 1 deletion perf/benchmarkapps/GrpcAspNetCoreServer/hosting.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"urls": "",
"server.urls": "",
"protocol": "h3", // This will be overriden when benchmarks are run
"protocol": "h2c", // This will be overriden when benchmarks are run
"certificateAuth": false,
"LogLevel": ""
}
24 changes: 11 additions & 13 deletions perf/benchmarkapps/GrpcClient/GrpcClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLinePackageVersion)" />

<PackageReference Include="Google.Protobuf" Version="$(GoogleProtobufPackageVersion)" />
<PackageReference Include="Grpc.Core" Version="$(GrpcPackageVersion)" />
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsPackageVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand All @@ -42,23 +46,17 @@
</None>
</ItemGroup>

<ItemGroup Condition="'$(EnableGrpcWeb)' == 'true'">
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
<!-- TODO: Workaround https://github.com/dotnet/sdk/issues/28169. Remove when fixed. -->
<ItemGroup Condition="'$(PublishAot)'!='true'">
<ProjectReference Include="..\..\..\src\Grpc.Net.Client\Grpc.Net.Client.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(PublishAot)'=='true'">
<PackageReference Include="Grpc.Net.Client" Version="$(GrpcDotNetPackageVersion)" />
</ItemGroup>

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

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

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Grpc.Net.Client" Version="2.23.2" />
<PackageReference Include="Google.Protobuf" Version="3.9.1" />
<PackageReference Include="Grpc.Core" Version="2.23.0" />
<PackageReference Include="Grpc.Tools" Version="2.23.0" PrivateAssets="All" />
</ItemGroup>

</Project>
Loading

0 comments on commit 4c2e66e

Please sign in to comment.