11#r " nuget: Fun.Build, 1.1.17"
22
33open Fun.Build
4+ open System
5+ open System.Diagnostics
6+ open System.IO
7+ open System.Runtime .InteropServices
48
59let src = __ SOURCE_ DIRECTORY__
610let fsproj = $" {src}/FSharp.SystemCommandLine/FSharp.SystemCommandLine.fsproj"
@@ -19,6 +23,57 @@ pipeline "Build" {
1923 runIfOnlySpecified false
2024}
2125
26+ // Use a unique package version so repeated local runs cannot reuse a cached build.
27+ let smokeDir = Path.Combine( src, " TestNativeAot" )
28+ let smokePackages = Path.Combine( smokeDir, " obj" , " packages" )
29+ let smokeOutput = Path.Combine( smokeDir, " bin" , " native-aot" )
30+ let smokeVersion = " 0.0.0-aot-" + Guid.NewGuid() .ToString( " N" )
31+ let smokeExecutable =
32+ Path.Combine( smokeOutput, if OperatingSystem.IsWindows() then " TestNativeAot.exe" else " TestNativeAot" )
33+
34+ let checkNativeAot args expectedExitCode expectedOutput =
35+ let startInfo = ProcessStartInfo( smokeExecutable)
36+ startInfo.UseShellExecute <- false
37+ startInfo.RedirectStandardOutput <- true
38+ startInfo.RedirectStandardError <- true
39+ for arg in args do startInfo.ArgumentList.Add( arg)
40+ use child = Process.Start( startInfo)
41+ let stdout = child.StandardOutput.ReadToEndAsync()
42+ let stderr = child.StandardError.ReadToEndAsync()
43+ if not ( child.WaitForExit( 30_000 )) then
44+ child.Kill( true )
45+ failwithf " NativeAOT smoke test timed out: %A " args
46+ let output = stdout.GetAwaiter() .GetResult()
47+ let errors = stderr.GetAwaiter() .GetResult()
48+ if child.ExitCode <> expectedExitCode || not ( output.Contains( expectedOutput: string)) then
49+ failwithf " NativeAOT smoke test %A : expected exit %d and output containing %A ; got exit %d .\n %s \n %s "
50+ args expectedExitCode expectedOutput child.ExitCode output errors
51+ printfn " NativeAOT smoke test passed: %A " args
52+
53+ pipeline " NativeAOT" {
54+ // The consumer's global.json selects .NET 10 for both pack and publish.
55+ workingDir smokeDir
56+
57+ stage " Pack library for NativeAOT" {
58+ run $" dotnet pack \" {fsproj}\" --configuration Release --output \" {smokePackages}\" -p:PackageVersion={smokeVersion}"
59+ }
60+
61+ stage " Publish NativeAOT package consumer" {
62+ run $" dotnet publish TestNativeAot.fsproj --configuration Release --runtime {RuntimeInformation.RuntimeIdentifier} --output \" {smokeOutput}\" -p:SmokePackageVersion={smokeVersion}"
63+ }
64+
65+ stage " Run NativeAOT smoke tests" {
66+ run ( fun _ ->
67+ checkNativeAot [ " --help" ] 0 " --count"
68+ checkNativeAot [ " hello" ; " world" ; " --count" ; " 2" ] 0 " words=hello,world;count=2"
69+ checkNativeAot [] 0 " words=;count=0"
70+ checkNativeAot [ " --count" ; " invalid" ] 1 " "
71+ )
72+ }
73+
74+ runIfOnlySpecified true
75+ }
76+
2277open System.Xml .Linq
2378
2479pipeline " Publish" {
@@ -39,4 +94,4 @@ pipeline "Publish" {
3994 runIfOnlySpecified true
4095}
4196
42- tryPrintPipelineCommandHelp ()
97+ tryPrintPipelineCommandHelp ()
0 commit comments