Skip to content

Commit

Permalink
Validate AoT compatibility
Browse files Browse the repository at this point in the history
Add a console project that validates whether the new-in-v8 Polly assemblies are AoT compatible.

Relates to App-vNext#1732.
  • Loading branch information
martincostello committed Oct 28, 2023
1 parent 0abf400 commit 106ca8a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Polly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polly.Testing.Tests", "test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snippets", "src\Snippets\Snippets.csproj", "{D812B941-79B0-4E1E-BB70-4FAE345B5234}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polly.AotTest", "test\Polly.AotTest\Polly.AotTest.csproj", "{84091007-CFA5-4852-AC41-0171DF039C4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -120,6 +122,10 @@ Global
{D812B941-79B0-4E1E-BB70-4FAE345B5234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D812B941-79B0-4E1E-BB70-4FAE345B5234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D812B941-79B0-4E1E-BB70-4FAE345B5234}.Release|Any CPU.Build.0 = Release|Any CPU
{84091007-CFA5-4852-AC41-0171DF039C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84091007-CFA5-4852-AC41-0171DF039C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84091007-CFA5-4852-AC41-0171DF039C4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84091007-CFA5-4852-AC41-0171DF039C4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -140,6 +146,7 @@ Global
{9AD2D6AD-56E4-49D6-B6F1-EE975D5760B9} = {B7BF406B-B06F-4025-83E6-7219C53196A6}
{D333B5CE-982D-4C11-BDAF-4217AA02306E} = {A6CC41B9-E0B9-44F8-916B-3E4A78DA3BFB}
{D812B941-79B0-4E1E-BB70-4FAE345B5234} = {B7BF406B-B06F-4025-83E6-7219C53196A6}
{84091007-CFA5-4852-AC41-0171DF039C4E} = {A6CC41B9-E0B9-44F8-916B-3E4A78DA3BFB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E5D54CD-770A-4345-B585-1848FC2EA6F4}
Expand Down
28 changes: 23 additions & 5 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Task("__Clean")
CleanDirectories(cleanDirectories);
foreach(var path in cleanDirectories) { EnsureDirectoryExists(path); }
foreach (var path in cleanDirectories) { EnsureDirectoryExists(path); }
foreach(var path in solutionPaths)
foreach (var path in solutionPaths)
{
Information("Cleaning {0}", path);
Expand All @@ -93,7 +93,7 @@ Task("__Clean")
Task("__RestoreNuGetPackages")
.Does(() =>
{
foreach(var solution in solutions)
foreach (var solution in solutions)
{
Information("Restoring NuGet Packages for {0}", solution);
DotNetRestore(solution.ToString());
Expand All @@ -103,7 +103,7 @@ Task("__RestoreNuGetPackages")
Task("__BuildSolutions")
.Does(() =>
{
foreach(var solution in solutions)
foreach (var solution in solutions)
{
Information("Building {0}", solution);
Expand All @@ -125,6 +125,23 @@ Task("__BuildSolutions")
}
});

Task("__ValidateAot")
.Does(() =>
{
var aotProject = MakeAbsolute(File("./test/Polly.AotTest/Polly.AotTest.csproj"));
var settings = new DotNetPublishSettings
{
Configuration = configuration,
Verbosity = DotNetVerbosity.Minimal,
MSBuildSettings = new DotNetMSBuildSettings
{
TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error,
},
};
DotNetPublish(aotProject.ToString(), settings);
});

Task("__RunTests")
.Does(() =>
{
Expand All @@ -137,7 +154,7 @@ Task("__RunTests")
var projects = GetFiles("./test/**/*.csproj");
foreach(var proj in projects)
foreach (var proj in projects)
{
DotNetTest(proj.FullPath, new DotNetTestSettings
{
Expand Down Expand Up @@ -252,6 +269,7 @@ Task("Build")
.IsDependentOn("__RestoreNuGetPackages")
.IsDependentOn("__ValidateDocs")
.IsDependentOn("__BuildSolutions")
.IsDependentOn("__ValidateAot")
.IsDependentOn("__RunTests")
.IsDependentOn("__RunMutationTests")
.IsDependentOn("__CreateNuGetPackages");
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Core/Polly.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<ItemGroup>
<Using Include="Polly.Utils" />
<InternalsVisibleToProject Include="Polly.AotTest" />
<InternalsVisibleToProject Include="Polly.Core.Benchmarks" />
<InternalsVisibleToProject Include="Polly.Core.Tests" />
<InternalsVisibleToProject Include="Polly.Testing" />
Expand Down
19 changes: 19 additions & 0 deletions test/Polly.AotTest/Polly.AotTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
<SKIP_POLLY_ANALYZERS>true</SKIP_POLLY_ANALYZERS>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Polly.Core\Polly.Core.csproj" />
<ProjectReference Include="..\..\src\Polly.Extensions\Polly.Extensions.csproj" />
<ProjectReference Include="..\..\src\Polly.RateLimiting\Polly.RateLimiting.csproj" />
</ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="Polly.Core" />
<TrimmerRootAssembly Include="Polly.Extensions" />
<TrimmerRootAssembly Include="Polly.RateLimiting" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions test/Polly.AotTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Polly.Utils.Pipeline;

// See https://github.com/App-vNext/Polly/issues/1732#issuecomment-1782466692.
// This code is needed as a workaround until https://github.com/dotnet/runtime/issues/94131 is resolved.
var pipeline = CompositeComponent.Create(new[] { PipelineComponent.Empty, PipelineComponent.Empty }, null!, null!);
await pipeline.ExecuteCore<int, int>((state, context) => default, default!, default);

Console.WriteLine("Hello Polly!");

0 comments on commit 106ca8a

Please sign in to comment.