Explorar o código

Add an AOT compatibility test app (#1378)

* Add an AOT compatibility test app

Following the guides at
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0
and https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/,
add an application which is published for AOT in CI.

This process fully verifies all code-paths in the library and its dependencies
for trimming/AOT, which the analyzers are not themselves able to do.

(As a side benefit, now we are also checking the library builds in Release)

* Test failure scenario

* Revert "Test failure scenario"

This reverts commit 6ff943b5024b9ef57f94feb466dabeb55257fe2e.
Rob Hague hai 1 ano
pai
achega
71423c17f9

+ 1 - 0
Directory.Build.props

@@ -5,6 +5,7 @@
         Assembly Info properties that apply to all projects/assemblies.
     -->
   <PropertyGroup>
+    <IsPackable>false</IsPackable>
     <SignAssembly>true</SignAssembly>
     <AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Renci.SshNet.snk</AssemblyOriginatorKeyFile>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>

+ 22 - 0
Renci.SshNet.sln

@@ -84,6 +84,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.Benchmarks", "
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.IntegrationBenchmarks", "test\Renci.SshNet.IntegrationBenchmarks\Renci.SshNet.IntegrationBenchmarks.csproj", "{6DFC1807-3F44-4302-A302-43F7D887C4E0}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.AotCompatibilityTestApp", "test\Renci.SshNet.AotCompatibilityTestApp\Renci.SshNet.AotCompatibilityTestApp.csproj", "{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -212,6 +214,26 @@ Global
 		{6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x64.Build.0 = Release|Any CPU
 		{6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x86.ActiveCfg = Release|Any CPU
 		{6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x86.Build.0 = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|ARM.ActiveCfg = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|ARM.Build.0 = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x64.Build.0 = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x86.Build.0 = Debug|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|ARM.ActiveCfg = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|ARM.Build.0 = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x64.ActiveCfg = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x64.Build.0 = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x86.ActiveCfg = Release|Any CPU
+		{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 0
appveyor.yml

@@ -36,6 +36,7 @@ for:
   build_script:
     - echo build
     - dotnet build Renci.SshNet.sln -c Debug
+    - dotnet publish -c Release -r win-x64 /warnaserror .\test\Renci.SshNet.AotCompatibilityTestApp\
 
   test_script:
     - ps: echo "Run unit tests for .NET 8.0"

+ 2 - 3
src/Renci.SshNet/Renci.SshNet.csproj

@@ -8,6 +8,7 @@
   </PropertyGroup>
 
   <PropertyGroup>
+    <IsPackable>true</IsPackable>
     <PackageId>SSH.NET</PackageId>
     <Title>SSH.NET</Title>
     <Version>2024.0.0</Version>
@@ -24,9 +25,7 @@
   </PropertyGroup>
 
   <PropertyGroup Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) ">
-    <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
-    <EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
-    <EnableAotAnalyzer>true</EnableAotAnalyzer>
+    <IsAotCompatible>true</IsAotCompatible>
   </PropertyGroup>
 
   <ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">

+ 19 - 0
test/Renci.SshNet.AotCompatibilityTestApp/Program.cs

@@ -0,0 +1,19 @@
+using System;
+
+namespace Renci.SshNet.AotCompatibilityTestApp
+{
+    public static class Program
+    {
+        public static void Main()
+        {
+            // This app is used to verify the trim- and AOT-friendliness of
+            // the library and its dependencies, by specifying <TrimmerRootAssembly>
+            // in the csproj and publishing with e.g. "dotnet publish -c Release -r win-x64"
+
+            // See https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0
+            // and https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/
+
+            Console.WriteLine("Hello, AOT!");
+        }
+    }
+}

+ 16 - 0
test/Renci.SshNet.AotCompatibilityTestApp/Renci.SshNet.AotCompatibilityTestApp.csproj

@@ -0,0 +1,16 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <PublishAot>true</PublishAot>
+    <SelfContained>true</SelfContained>
+    <TrimmerSingleWarn>false</TrimmerSingleWarn>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\..\src\Renci.SshNet\Renci.SshNet.csproj" />
+    <TrimmerRootAssembly Include="Renci.SshNet" />
+  </ItemGroup>
+
+</Project>

+ 0 - 1
test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

@@ -3,7 +3,6 @@
   <PropertyGroup>
     <TargetFrameworks>net48;net8.0</TargetFrameworks>
     <ImplicitUsings>enable</ImplicitUsings>
-    <IsPackable>false</IsPackable>
     <IsTestProject>true</IsTestProject>
     <NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>