scorpiox-bot-plugin-services
←build.ps1text
51 lines · 1 KBHEADBlameDownload
1# build.ps1 - Windows MinGW-w64 static build for plugin_services
2#
3# Usage (from the repo root, PowerShell):
4# powershell -ExecutionPolicy Bypass -File build.ps1
5#
6# Produces .\plugin_services.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
11Push-Location $ScriptDir
12try {
13 $Src = Join-Path $ScriptDir "src\plugin_services.c"
14 $Out = Join-Path $ScriptDir "plugin_services.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 # Regenerate the page header so the binary always matches src/ui.html.
31 if (Get-Command python -ErrorAction SilentlyContinue) {
32 python tools\gen_ui.py
33 }
34
35 Write-Host "==> building plugin_services.exe with $Cc"
36 & $Cc -O2 -std=c99 -Wall -Wextra -I src -static -o $Out $Src
37 if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" }
38
39 if (-not (Test-Path $Out)) { throw "build produced no output" }
40
41 # Sanity: a real PE starts with 'MZ'. An HTML error page saved as .exe does not.
42 $bytes = [System.IO.File]::ReadAllBytes($Out)
43 if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
44 throw "output is not a PE executable (missing MZ header)"
45 }
46
47 Write-Host "==> ok: $Out ($($bytes.Length) bytes)"
48 Write-Host " smoke test: .\plugin_services.exe --meta"
49} finally {
50 Pop-Location
51}