diff --git a/.github/workflows/aot-check.yml b/.github/workflows/aot-check.yml new file mode 100644 index 000000000..07799d360 --- /dev/null +++ b/.github/workflows/aot-check.yml @@ -0,0 +1,28 @@ +name: "AOT Check" + +on: + push: + branches: [ "master", "rel/v2" ] + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + branches: [ "master", "rel/v2" ] + +jobs: + analyze: + runs-on: windows-latest + name: AOT check + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Runs powershell script + id: aot-powershell + run: build\test-aot.ps1 'net8.0' + diff --git a/Microsoft.Identity.Web.sln b/Microsoft.Identity.Web.sln index 3297c7fbc..cbb4c2f30 100644 --- a/Microsoft.Identity.Web.sln +++ b/Microsoft.Identity.Web.sln @@ -169,7 +169,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "benchmark\Ben EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoWorker", "tests\DevApps\ContosoWorker\ContosoWorker.csproj", "{4A63EA63-5679-4498-BB4C-30E09F268E00}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Identity.Web.UI", "src\Microsoft.Identity.Web.UI\Microsoft.Identity.Web.UI.csproj", "{C6CB0D5B-917A-4127-9984-7592C757BBDE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.UI", "src\Microsoft.Identity.Web.UI\Microsoft.Identity.Web.UI.csproj", "{C6CB0D5B-917A-4127-9984-7592C757BBDE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.AotCompatibility.TestApp", "tests\Microsoft.Identity.Web.AotCompatibility.TestApp\Microsoft.Identity.Web.AotCompatibility.TestApp.csproj", "{BCE63265-6D36-423A-9C3D-BF8E448C7EA0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -401,6 +403,10 @@ Global {C6CB0D5B-917A-4127-9984-7592C757BBDE}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6CB0D5B-917A-4127-9984-7592C757BBDE}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6CB0D5B-917A-4127-9984-7592C757BBDE}.Release|Any CPU.Build.0 = Release|Any CPU + {BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BCE63265-6D36-423A-9C3D-BF8E448C7EA0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -480,6 +486,7 @@ Global {8FB5433F-D625-464E-8957-FDD0AC20FBDE} = {A6799B45-E2FD-4ACA-86A2-D1AD5B1E2ECE} {4A63EA63-5679-4498-BB4C-30E09F268E00} = {E37CDBC1-18F6-4C06-A3EE-532C9106721F} {C6CB0D5B-917A-4127-9984-7592C757BBDE} = {1DDE1AAC-5AE6-4725-94B6-A26C58D3423F} + {BCE63265-6D36-423A-9C3D-BF8E448C7EA0} = {B4E72F1C-603F-437C-AAA1-153A604CD34A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {104367F1-CE75-4F40-B32F-F14853973187} diff --git a/build/test-aot.ps1 b/build/test-aot.ps1 new file mode 100644 index 000000000..13734d2d2 --- /dev/null +++ b/build/test-aot.ps1 @@ -0,0 +1,50 @@ +param([string]$targetNetFramework) + +$projectName='Microsoft.Identity.Web.AotCompatibility.TestApp' +$rootDirectory = Split-Path $PSScriptRoot -Parent +$publishOutput = dotnet publish $rootDirectory/tests/$projectName/$projectName.csproj --framework $targetNetFramework -nodeReuse:false /p:UseSharedCompilation=false + +$actualWarningCount = 0 + +foreach ($line in $($publishOutput -split "`r`n")) +{ + if (($line -like "*analysis warning IL*") -or ($line -like "*analysis error IL*")) + { + Write-Host $line + $actualWarningCount += 1 + } +} + +Write-Host "Actual warning count is: ", $actualWarningCount +$expectedWarningCount = 63 + +if ($LastExitCode -ne 0) +{ + Write-Host "There was an error while publishing AotCompatibility Test App. LastExitCode is:", $LastExitCode + Write-Host $publishOutput +} + +$runtime = if ($IsWindows) { "win-x64" } elseif ($IsMacOS) { "macos-x64"} else {"linux-x64"} +$app = if ($IsWindows ) {"./$projectName.exe" } else {"./$projectName" } + +Push-Location $rootDirectory/tests/$projectName/bin/Release/$targetNetFramework/$runtime + +Write-Host "Executing test App..." +$app +Write-Host "Finished executing test App" + +if ($LastExitCode -ne 0) +{ + Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode +} + +Pop-Location + +$testPassed = 0 +if ($expectedWarningCount -ne $actualWarningCount) +{ + $testPassed = 1 + Write-Host "Actual warning count:", $actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount +} + +Exit $testPassed diff --git a/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Microsoft.Identity.Web.AotCompatibility.TestApp.csproj b/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Microsoft.Identity.Web.AotCompatibility.TestApp.csproj new file mode 100644 index 000000000..d35fa212d --- /dev/null +++ b/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Microsoft.Identity.Web.AotCompatibility.TestApp.csproj @@ -0,0 +1,37 @@ + + + + net8.0 + Exe + true + true + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Program.cs b/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Program.cs new file mode 100644 index 000000000..eadd92b4e --- /dev/null +++ b/tests/Microsoft.Identity.Web.AotCompatibility.TestApp/Program.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +internal sealed class Program +{ + // The code in this program is expected to be trim and AOT compatible + private static int Main() + { + return 100; + } +}