$ErrorActionPreference = 'Stop' . ./.local/toolchain/env.ps1 $env:CARGO_BUILD_JOBS = '1' $evidenceRoot = Join-Path (Get-Location) '.local/text-navigation-integration-20260911' foreach ($gateName in @('outline1','core1','clippy1')) { $prior = Get-Content -Raw -LiteralPath (Join-Path $evidenceRoot "$gateName-status.json") | ConvertFrom-Json if ($prior.exitCode -ne 0) { throw "Required prior gate failed: $gateName" } } function Invoke-RecordedNative { param([string]$Name,[string]$Executable,[string[]]$Arguments) $stdout = Join-Path $evidenceRoot "$Name-stdout.log" $stderr = Join-Path $evidenceRoot "$Name-stderr.log" $status = Join-Path $evidenceRoot "$Name-status.json" if ((Test-Path $stdout) -or (Test-Path $stderr) -or (Test-Path $status)) { throw "Refusing overwrite $Name" } $started = [DateTime]::UtcNow.ToString('o') & $Executable @Arguments 1> $stdout 2> $stderr $code = $LASTEXITCODE [ordered]@{started=$started;finished=[DateTime]::UtcNow.ToString('o');exitCode=$code;executable=$Executable;args=$Arguments;buildJobs=1} | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $status Get-Content -LiteralPath $stderr if ($Name -ne 'artifacts1') { Get-Content -LiteralPath $stdout } if ($code -ne 0) { exit $code } } Invoke-RecordedNative 'compiler1' 'rustc' @('-vV') Invoke-RecordedNative 'artifacts1' 'cargo' @('build','--locked','--offline','-p','oa-core','--lib','--message-format=json') $messages = Get-Content -LiteralPath (Join-Path $evidenceRoot 'artifacts1-stdout.log') | ForEach-Object { $_ | ConvertFrom-Json } $bindings = @{} $bindingRecords = @() foreach ($crate in @('oa_core','serde_json')) { $artifacts = @($messages | Where-Object { $_.reason -eq 'compiler-artifact' -and $_.target.name -eq $crate -and $_.target.kind -contains 'lib' }) if ($artifacts.Count -ne 1) { throw "Expected exactly one Cargo lib artifact for $crate; got $($artifacts.Count)" } $rlibs = @($artifacts[0].filenames | Where-Object { $_.EndsWith('.rlib') }) if ($rlibs.Count -ne 1) { throw "Expected one rlib for $crate" } $rlib = $rlibs[0] $suffix = [IO.Path]::GetFileNameWithoutExtension($rlib).Substring(('lib' + $crate + '-').Length) $packageName = if ($crate -eq 'oa_core') { 'oa-core' } else { $crate } $fingerprintRoot = Join-Path $env:CARGO_TARGET_DIR "debug/.fingerprint/$packageName-$suffix" $fingerprints = @() foreach ($name in @("lib-$crate", "lib-$crate.json")) { $fp = Join-Path $fingerprintRoot $name if (-not (Test-Path -LiteralPath $fp -PathType Leaf)) { throw "Missing exact fingerprint $fp" } $destination = Join-Path $evidenceRoot "fingerprints/$packageName-$suffix/$name" New-Item -ItemType Directory -Path (Split-Path $destination) -Force | Out-Null Copy-Item -LiteralPath $fp -Destination $destination $fingerprints += [ordered]@{original=$fp;copy=$destination;sha256=(Get-FileHash -LiteralPath $fp).Hash} } $bindings[$crate] = $rlib $bindingRecords += [ordered]@{crate=$crate;rlib=$rlib;bytes=(Get-Item -LiteralPath $rlib).Length;sha256=(Get-FileHash -LiteralPath $rlib).Hash;cargoArtifact=$artifacts[0];fingerprints=$fingerprints} } $bindingRecords | ConvertTo-Json -Depth 12 | Set-Content -LiteralPath (Join-Path $evidenceRoot 'query-bindings.json') $source = Join-Path $evidenceRoot 'source_symbols-v2.rs' $binary = Join-Path $evidenceRoot 'source-symbols-v2-tests.exe' $dependencies = Split-Path $bindings['oa_core'] if ((Split-Path $bindings['serde_json']) -ne $dependencies) { throw 'Artifact dependency directories differ' } Invoke-RecordedNative 'query-compile1' 'rustc' @('--edition=2024','--crate-name','source_symbols_v2','--test','-Dwarnings','-C','linker=clang.exe',$source,'--extern',"oa_core=$($bindings['oa_core'])",'--extern',"serde_json=$($bindings['serde_json'])",'-L',"dependency=$dependencies",'-o',$binary) Invoke-RecordedNative 'query-tests1' $binary @('--test-threads=1') [ordered]@{sourceSha256=(Get-FileHash -LiteralPath $source).Hash;binarySha256=(Get-FileHash -LiteralPath $binary).Hash;binaryBytes=(Get-Item -LiteralPath $binary).Length} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $evidenceRoot 'query-artifacts.json')