| 1 | # build.ps1 — Windows MinGW-w64 static build for plugin_docker |
| 2 | # |
| 3 | # Usage (from the repo root, PowerShell): |
| 4 | # powershell -ExecutionPolicy Bypass -File build.ps1 |
| 5 | # |
| 6 | # Produces .\plugin_docker.exe (static PE, runs on any Windows 10/11 x64 node). |
| 7 | # Requires x86_64-w64-mingw32-gcc or a WinLibs/UCRT gcc on PATH (or C:\gcc16\bin). |
| 8 | |
| 9 | $ErrorActionPreference = "Stop" |
| 10 | $ScriptDir = $PSScriptRoot |
| 11 | Push-Location $ScriptDir |
| 12 | try { |
| 13 | $Src = Join-Path $ScriptDir "src\plugin_docker.c" |
| 14 | $Out = Join-Path $ScriptDir "plugin_docker.exe" |
| 15 | $Cc = "x86_64-w64-mingw32-gcc" |
| 16 | |
| 17 | if (-not (Test-Path $Src)) { throw "source not found: $Src" } |
| 18 | |
| 19 | # Prefer MinGW-w64, fall back to a plain gcc (WinLibs / MSYS2 UCRT) if present. |
| 20 | if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) { |
| 21 | if (Test-Path "C:\gcc16\bin\gcc.exe") { |
| 22 | $Cc = "C:\gcc16\bin\gcc.exe" |
| 23 | } elseif (Get-Command gcc -ErrorAction SilentlyContinue) { |
| 24 | $Cc = "gcc" |
| 25 | } else { |
| 26 | throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)" |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | Write-Host "==> building plugin_docker.exe with $Cc" |
| 31 | & $Cc -O2 -std=c99 -Wall -Wextra -static -o $Out $Src |
| 32 | if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" } |
| 33 | |
| 34 | if (-not (Test-Path $Out)) { throw "build produced no output" } |
| 35 | |
| 36 | # Sanity: a real PE starts with 'MZ'. An HTML error page saved as .exe does not. |
| 37 | $bytes = [System.IO.File]::ReadAllBytes($Out) |
| 38 | if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) { |
| 39 | throw "output is not a PE executable (missing MZ header)" |
| 40 | } |
| 41 | |
| 42 | Write-Host "==> metadata check" |
| 43 | & $Out --meta |
| 44 | if ($LASTEXITCODE -ne 0) { throw "--meta failed" } |
| 45 | |
| 46 | $size = (Get-Item $Out).Length |
| 47 | Write-Host "" |
| 48 | Write-Host "Built $Out ($size bytes)" |
| 49 | Write-Host "Install: Copy-Item plugin_docker.exe `"`$env:LOCALAPPDATA\scorpiox\plugins\`"" |
| 50 | } |
| 51 | finally { |
| 52 | Pop-Location |
| 53 | } |