[CmdletBinding()]
param(
[ValidateSet('Desktop','Console')][string]$Edition='Desktop',
[string]$PythonPath='python',
[switch]$DiagnosticProbe,
[switch]$RestoreOnly,
[switch]$UpdateLock
)
$ErrorActionPreference='Stop'
$Edition=if($Edition -eq 'Console'){'Console'}else{'Desktop'}
if($DiagnosticProbe -and $Edition -ne 'Desktop'){throw 'DiagnosticProbe is a separate runtime diagnostic and cannot build the console edition.'}
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
$tools=Join-Path $taskRoot '.tools'
$id='System-'+$Edition+'-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()+'-'+[Guid]::NewGuid().ToString('N').Substring(0,8)
$output=Join-Path $taskRoot ('build/IndependentKernel/'+$id)
[void][IO.Directory]::CreateDirectory($output)
$application=if($DiagnosticProbe){'Source/XFESystem.NativeRuntime/Probe/NativeRuntimeProbe.csproj'}elseif($Edition -eq 'Console'){'Source/XFESystem.NativeRuntime/ConsoleApplication/ConsoleApplication.csproj'}else{'Source/XFESystem.NativeRuntime/Application/NativeApplication.csproj'}
Push-Location $taskRoot
try {
$restoreArgs=@('restore',(Join-Path $PSScriptRoot 'Runtime/NativeToolchain.csproj'),'--configfile',(Join-Path $taskRoot 'Tools/CSharpBoot/NuGet.Config'))
if(!$UpdateLock){$restoreArgs+='--locked-mode'}
& dotnet @restoreArgs
if($LASTEXITCODE -ne 0){throw 'Independent Microsoft compiler/runtime package restore failed.'}
$appRestore=@('restore',$application,'--configfile',(Join-Path $taskRoot 'Tools/CSharpBoot/NuGet.Config'))
if(!$UpdateLock){$appRestore+='--locked-mode'}
& dotnet @appRestore
if($LASTEXITCODE -ne 0){throw 'Independent managed application locked restore failed.'}
& (Join-Path $PSScriptRoot 'Runtime/VerifyToolchain.ps1')
if($RestoreOnly){return}
$mathLog=Join-Path $output 'MathBuild.log'
& $PythonPath (Join-Path $PSScriptRoot 'Runtime/BuildMath.py') *> $mathLog
if($LASTEXITCODE -ne 0){throw ('Pinned mathematical library build failed: '+$mathLog)}
$mathResult=Get-Content -LiteralPath $mathLog -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$mathResult.Passed){throw 'Mathematical library compilation did not pass.'}
$managed=Join-Path $output 'Managed'
& (Join-Path $PSScriptRoot 'Runtime/CompileProbe.ps1') -ToolRoot $tools -ProjectPath (Join-Path $taskRoot $application) -OutputDirectory $managed
$port=Join-Path $output 'Port'
& (Join-Path $PSScriptRoot 'Runtime/PrepareRuntime.ps1') -ToolRoot $tools -ProbeDirectory $managed -OutputDirectory $port
$portReceipt=Join-Path $port 'PortReceipt.json'
$runtime=Get-Content -LiteralPath $portReceipt -Raw -Encoding UTF8 | ConvertFrom-Json
& (Join-Path $PSScriptRoot 'Build.ps1') -Edition $Edition -ToolsRoot $tools -RuntimeObjects @($runtime.FinalLinkInputs) -RuntimePortReceipt $portReceipt -MathReceipt $mathResult.Receipt -PythonPath $PythonPath
$portHash=(Get-FileHash -LiteralPath $portReceipt -Algorithm SHA256).Hash.ToLowerInvariant()
$latestBuild=Get-ChildItem -LiteralPath (Join-Path $taskRoot 'build/IndependentKernel') -Directory -Filter 'Build-*' |
Where-Object {
$candidate=Join-Path $_.FullName 'BuildReceipt.json'
if(Test-Path -LiteralPath $candidate) {
$candidateReceipt=Get-Content -LiteralPath $candidate -Raw -Encoding UTF8 | ConvertFrom-Json
$candidateReceipt.Passed -and $candidateReceipt.Edition -ceq $Edition -and $candidateReceipt.RuntimePortReceipt.Sha256 -ceq $portHash
} else {$false}
} | Sort-Object Name -Descending | Select-Object -First 1
if(!$latestBuild){throw 'The build did not produce a kernel bound to this runtime port.'}
$built=Get-Content -LiteralPath (Join-Path $latestBuild.FullName 'BuildReceipt.json') -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$built.Passed -or $built.RuntimePortReceipt.Sha256 -cne (Get-FileHash -LiteralPath $portReceipt -Algorithm SHA256).Hash.ToLowerInvariant()) {
throw 'The compiled kernel is not bound to this native runtime port.'
}
$result=[ordered]@{Kind='XfeIndependentSystemBuild';Passed=$true;Edition=$Edition;ApplicationProject=$application;DiagnosticProbe=[bool]$DiagnosticProbe;
ContainsCosmos=$false;KernelPath=$built.KernelPath;KernelSha256=$built.KernelSha256;
BuildReceipt=(Join-Path $latestBuild.FullName 'BuildReceipt.json');RuntimePortReceipt=$portReceipt;
MathReceipt=$mathResult.Receipt;GuestAcceptancePassed=$false;FullReleaseQualified=$false}
$result | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $output 'Result.json') -Encoding UTF8
Write-Output ('Independent system built: '+$built.KernelPath)
Write-Output ('System receipt: '+(Join-Path $output 'Result.json'))
} catch {
[ordered]@{Kind='XfeIndependentSystemBuild';Passed=$false;Edition=$Edition;Error=$_.Exception.Message} |
ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $output 'Failure.json') -Encoding UTF8
throw
} finally {Pop-Location}
[CmdletBinding()]
param(
[ValidateSet('Desktop','Console')][string]$Edition='Desktop',
[string]$PythonPath='python',
[switch]$DiagnosticProbe,
[switch]$RestoreOnly,
[switch]$UpdateLock
)
$ErrorActionPreference='Stop'
$Edition=if($Edition -eq 'Console'){'Console'}else{'Desktop'}
if($DiagnosticProbe -and $Edition -ne 'Desktop'){throw 'DiagnosticProbe is a separate runtime diagnostic and cannot build the console edition.'}
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
$tools=Join-Path $taskRoot '.tools'
$id='System-'+$Edition+'-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()+'-'+[Guid]::NewGuid().ToString('N').Substring(0,8)
$output=Join-Path $taskRoot ('build/IndependentKernel/'+$id)
[void][IO.Directory]::CreateDirectory($output)
$application=if($DiagnosticProbe){'Source/XFESystem.NativeRuntime/Probe/NativeRuntimeProbe.csproj'}elseif($Edition -eq 'Console'){'Source/XFESystem.NativeRuntime/ConsoleApplication/ConsoleApplication.csproj'}else{'Source/XFESystem.NativeRuntime/Application/NativeApplication.csproj'}
Push-Location $taskRoot
try {
$restoreArgs=@('restore',(Join-Path $PSScriptRoot 'Runtime/NativeToolchain.csproj'),'--configfile',(Join-Path $taskRoot 'Tools/CSharpBoot/NuGet.Config'))
if(!$UpdateLock){$restoreArgs+='--locked-mode'}
& dotnet @restoreArgs
if($LASTEXITCODE -ne 0){throw 'Independent Microsoft compiler/runtime package restore failed.'}
$appRestore=@('restore',$application,'--configfile',(Join-Path $taskRoot 'Tools/CSharpBoot/NuGet.Config'))
if(!$UpdateLock){$appRestore+='--locked-mode'}
& dotnet @appRestore
if($LASTEXITCODE -ne 0){throw 'Independent managed application locked restore failed.'}
& (Join-Path $PSScriptRoot 'Runtime/VerifyToolchain.ps1')
if($RestoreOnly){return}
$mathLog=Join-Path $output 'MathBuild.log'
& $PythonPath (Join-Path $PSScriptRoot 'Runtime/BuildMath.py') *> $mathLog
if($LASTEXITCODE -ne 0){throw ('Pinned mathematical library build failed: '+$mathLog)}
$mathResult=Get-Content -LiteralPath $mathLog -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$mathResult.Passed){throw 'Mathematical library compilation did not pass.'}
$managed=Join-Path $output 'Managed'
& (Join-Path $PSScriptRoot 'Runtime/CompileProbe.ps1') -ToolRoot $tools -ProjectPath (Join-Path $taskRoot $application) -OutputDirectory $managed
$port=Join-Path $output 'Port'
& (Join-Path $PSScriptRoot 'Runtime/PrepareRuntime.ps1') -ToolRoot $tools -ProbeDirectory $managed -OutputDirectory $port
$portReceipt=Join-Path $port 'PortReceipt.json'
$runtime=Get-Content -LiteralPath $portReceipt -Raw -Encoding UTF8 | ConvertFrom-Json
& (Join-Path $PSScriptRoot 'Build.ps1') -Edition $Edition -ToolsRoot $tools -RuntimeObjects @($runtime.FinalLinkInputs) -RuntimePortReceipt $portReceipt -MathReceipt $mathResult.Receipt -PythonPath $PythonPath
$portHash=(Get-FileHash -LiteralPath $portReceipt -Algorithm SHA256).Hash.ToLowerInvariant()
$latestBuild=Get-ChildItem -LiteralPath (Join-Path $taskRoot 'build/IndependentKernel') -Directory -Filter 'Build-*' |
Where-Object {
$candidate=Join-Path $_.FullName 'BuildReceipt.json'
if(Test-Path -LiteralPath $candidate) {
$candidateReceipt=Get-Content -LiteralPath $candidate -Raw -Encoding UTF8 | ConvertFrom-Json
$candidateReceipt.Passed -and $candidateReceipt.Edition -ceq $Edition -and $candidateReceipt.RuntimePortReceipt.Sha256 -ceq $portHash
} else {$false}
} | Sort-Object Name -Descending | Select-Object -First 1
if(!$latestBuild){throw 'The build did not produce a kernel bound to this runtime port.'}
$built=Get-Content -LiteralPath (Join-Path $latestBuild.FullName 'BuildReceipt.json') -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$built.Passed -or $built.RuntimePortReceipt.Sha256 -cne (Get-FileHash -LiteralPath $portReceipt -Algorithm SHA256).Hash.ToLowerInvariant()) {
throw 'The compiled kernel is not bound to this native runtime port.'
}
$result=[ordered]@{Kind='XfeIndependentSystemBuild';Passed=$true;Edition=$Edition;ApplicationProject=$application;DiagnosticProbe=[bool]$DiagnosticProbe;
ContainsCosmos=$false;KernelPath=$built.KernelPath;KernelSha256=$built.KernelSha256;
BuildReceipt=(Join-Path $latestBuild.FullName 'BuildReceipt.json');RuntimePortReceipt=$portReceipt;
MathReceipt=$mathResult.Receipt;GuestAcceptancePassed=$false;FullReleaseQualified=$false}
$result | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $output 'Result.json') -Encoding UTF8
Write-Output ('Independent system built: '+$built.KernelPath)
Write-Output ('System receipt: '+(Join-Path $output 'Result.json'))
} catch {
[ordered]@{Kind='XfeIndependentSystemBuild';Passed=$false;Edition=$Edition;Error=$_.Exception.Message} |
ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $output 'Failure.json') -Encoding UTF8
throw
} finally {Pop-Location}