scorpiox-bot-plugin-memory
←build.ps1text
66 lines · 2 KBHEADBlameDownload
1# build.ps1 - Windows static build for plugin_memory
2#
3# Usage (from the repo root, PowerShell):
4# powershell -ExecutionPolicy Bypass -File build.ps1
5#
6# Produces .\plugin_memory.exe (static PE, runs on any Windows 10/11 x64 node).
7# Requires x86_64-w64-mingw32-gcc or a WinLibs/MSYS2 UCRT gcc on PATH
8# (or C:\gcc16\bin\gcc.exe).
9#
10# The binary is four translation units plus the vendored yyjson amalgamation -
11# no DLLs, no libcurl, no sqlite, nothing to install on the node.
12
13$ErrorActionPreference = "Stop"
14$ScriptDir = $PSScriptRoot
15Push-Location $ScriptDir
16try {
17 $Srcs = @(
18 "src\plugin_memory.c",
19 "src\graph.c",
20 "src\tools.c",
21 "src\api.c",
22 "vendor\yyjson.c"
23 )
24 $Out = Join-Path $ScriptDir "plugin_memory.exe"
25 $Cc = "x86_64-w64-mingw32-gcc"
26
27 foreach ($s in $Srcs) {
28 $p = Join-Path $ScriptDir $s
29 if (-not (Test-Path $p)) { throw "source not found: $p" }
30 }
31
32 # Prefer MinGW-w64, fall back to a plain gcc (WinLibs / MSYS2 UCRT) if present.
33 if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) {
34 if (Test-Path "C:\gcc16\bin\gcc.exe") {
35 $Cc = "C:\gcc16\bin\gcc.exe"
36 } elseif (Get-Command gcc -ErrorAction SilentlyContinue) {
37 $Cc = "gcc"
38 } else {
39 throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)"
40 }
41 }
42
43 # Regenerate the page header so the binary always matches src/ui.html.
44 if (Get-Command python -ErrorAction SilentlyContinue) {
45 python tools\gen_ui.py
46 }
47
48 Write-Host "==> building plugin_memory.exe with $Cc"
49 & $Cc -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -I src -I vendor `
50 -static -o $Out $Srcs
51 if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" }
52
53 if (-not (Test-Path $Out)) { throw "build produced no output" }
54
55 # Sanity: a real PE starts with 'MZ'. An HTML error page saved as .exe does not.
56 $bytes = [System.IO.File]::ReadAllBytes($Out)
57 if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
58 throw "output is not a PE executable (missing MZ header)"
59 }
60
61 Write-Host "==> ok: $Out ($($bytes.Length) bytes)"
62 Write-Host " smoke test: .\plugin_memory.exe --meta"
63 Write-Host " .\plugin_memory.exe --mcp (then paste a JSON-RPC line)"
64} finally {
65 Pop-Location
66}