Skip to content

Commit dde68fa

Browse files
martincostelloeerhardtCodeBlanch
authored
Improve AoT validation and fix OpenTelemetryProtocol AoT warnings (#5520)
Co-authored-by: Eric Erhardt <[email protected]> Co-authored-by: Mikel Blanchard <[email protected]>
1 parent 7b604f7 commit dde68fa

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

Diff for: .github/workflows/verifyaotcompat.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
1313
matrix:
14-
os: [ ubuntu-latest ]
14+
os: [ ubuntu-latest, windows-latest ]
1515
version: [ net8.0 ]
1616

1717
runs-on: ${{ matrix.os }}
@@ -24,4 +24,3 @@ jobs:
2424
- name: publish AOT testApp, assert static analysis warning count, and run the app
2525
shell: pwsh
2626
run: .\build\test-aot-compatibility.ps1 ${{ matrix.version }}
27-

Diff for: Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
-->
2929

3030
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
31+
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
3132
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
3233
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Abstractions" Version="8.0.0" />
3334
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />

Diff for: build/test-aot-compatibility.ps1

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
param([string]$targetNetFramework)
22

33
$rootDirectory = Split-Path $PSScriptRoot -Parent
4-
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
4+
$publishOutput = dotnet publish $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj --framework $targetNetFramework -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true
55

66
$actualWarningCount = 0
77

88
foreach ($line in $($publishOutput -split "`r`n"))
99
{
10-
if ($line -like "*analysis warning IL*")
10+
if (($line -like "*analysis warning IL*") -or ($line -like "*analysis error IL*"))
1111
{
1212
Write-Host $line
13-
1413
$actualWarningCount += 1
1514
}
1615
}
1716

18-
pushd $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Release/$targetNetFramework/linux-x64
17+
Write-Host "Actual warning count is:", $actualWarningCount
18+
$expectedWarningCount = 0
19+
20+
if ($LastExitCode -ne 0)
21+
{
22+
Write-Host "There was an error while publishing AotCompatibility Test App. LastExitCode is:", $LastExitCode
23+
Write-Host $publishOutput
24+
}
25+
26+
$runtime = $IsWindows ? "win-x64" : ($IsMacOS ? "macos-x64" : "linux-x64")
27+
$app = $IsWindows ? "./OpenTelemetry.AotCompatibility.TestApp.exe" : "./OpenTelemetry.AotCompatibility.TestApp"
28+
29+
Push-Location $rootDirectory/test/OpenTelemetry.AotCompatibility.TestApp/bin/Release/$targetNetFramework/$runtime
1930

2031
Write-Host "Executing test App..."
21-
./OpenTelemetry.AotCompatibility.TestApp
32+
$app
2233
Write-Host "Finished executing test App"
2334

2435
if ($LastExitCode -ne 0)
2536
{
2637
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
2738
}
2839

29-
popd
30-
31-
Write-Host "Actual warning count is:", $actualWarningCount
32-
$expectedWarningCount = 0
40+
Pop-Location
3341

3442
$testPassed = 0
3543
if ($actualWarningCount -ne $expectedWarningCount)

Diff for: src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* Fix native AoT warnings in `OpenTelemetry.Exporter.OpenTelemetryProtocol`.
6+
([#5520](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5520))
7+
58
## 1.8.0
69

710
Released 2024-Apr-02

Diff for: src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<!-- this is temporary. will remove in future PR. -->
99
<Nullable>disable</Nullable>
1010
<DefineConstants>BUILDING_INTERNAL_PERSISTENT_STORAGE;$(DefineConstants)</DefineConstants>
11+
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
12+
<!-- SYSLIB1100;SYSLIB1101 - Configuration.Binder: can't create instance and unsupported type -->
13+
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
1114
</PropertyGroup>
1215

1316
<ItemGroup>
@@ -19,6 +22,7 @@
1922
<PackageReference Include="Grpc" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
2023
<PackageReference Include="Google.Protobuf" />
2124
<PackageReference Include="Grpc.Tools" PrivateAssets="All" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
2226
</ItemGroup>
2327

2428
<ItemGroup>

Diff for: src/Shared/Options/DelegatingOptionsFactory.cs

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ example of how that works.
1616
#nullable enable
1717

1818
using System.Diagnostics;
19+
#if NET6_0_OR_GREATER
20+
using System.Diagnostics.CodeAnalysis;
21+
#endif
1922
using Microsoft.Extensions.Configuration;
2023

2124
namespace Microsoft.Extensions.Options;
@@ -24,7 +27,11 @@ namespace Microsoft.Extensions.Options;
2427
/// Implementation of <see cref="IOptionsFactory{TOptions}"/>.
2528
/// </summary>
2629
/// <typeparam name="TOptions">The type of options being requested.</typeparam>
30+
#if NET6_0_OR_GREATER
31+
internal sealed class DelegatingOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> :
32+
#else
2733
internal sealed class DelegatingOptionsFactory<TOptions> :
34+
#endif
2835
IOptionsFactory<TOptions>
2936
where TOptions : class
3037
{

Diff for: src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#nullable enable
55

66
using System.Diagnostics;
7+
#if NET6_0_OR_GREATER
8+
using System.Diagnostics.CodeAnalysis;
9+
#endif
710
using Microsoft.Extensions.Configuration;
811
using Microsoft.Extensions.DependencyInjection.Extensions;
912
using Microsoft.Extensions.Options;
@@ -12,7 +15,11 @@ namespace Microsoft.Extensions.DependencyInjection;
1215

1316
internal static class DelegatingOptionsFactoryServiceCollectionExtensions
1417
{
18+
#if NET6_0_OR_GREATER
19+
public static IServiceCollection RegisterOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(
20+
#else
1521
public static IServiceCollection RegisterOptionsFactory<T>(
22+
#endif
1623
this IServiceCollection services,
1724
Func<IConfiguration, T> optionsFactoryFunc)
1825
where T : class
@@ -33,7 +40,11 @@ public static IServiceCollection RegisterOptionsFactory<T>(
3340
return services!;
3441
}
3542

43+
#if NET6_0_OR_GREATER
44+
public static IServiceCollection RegisterOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(
45+
#else
3646
public static IServiceCollection RegisterOptionsFactory<T>(
47+
#endif
3748
this IServiceCollection services,
3849
Func<IServiceProvider, IConfiguration, string, T> optionsFactoryFunc)
3950
where T : class

Diff for: test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>$(TargetFrameworksForAotCompatibilityTests)</TargetFramework>
5+
<TargetFrameworks>$(TargetFrameworksForAotCompatibilityTests)</TargetFrameworks>
66
<PublishAot>true</PublishAot>
77
<TrimmerSingleWarn>false</TrimmerSingleWarn>
88
<SelfContained>true</SelfContained>

0 commit comments

Comments
 (0)