scorpiox-bot-plugin-tetris-3d
←build.ps1text
47 lines · 1 KBHEADBlameDownload
1# build.ps1 - Windows MinGW-w64 static build for plugin_tetris_3d
2#
3# Usage (from the repo root, PowerShell):
4# powershell -ExecutionPolicy Bypass -File build.ps1
5#
6# Produces .\plugin_tetris_3d.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_tetris_3d.c"
14 $Hdr = Join-Path $ScriptDir "src\ui_html.h"
15 $Out = Join-Path $ScriptDir "plugin_tetris_3d.exe"
16 $Cc = "x86_64-w64-mingw32-gcc"
17
18 if (-not (Test-Path $Src)) { throw "source not found: $Src" }
19 if (-not (Test-Path $Hdr)) { throw "generated UI header not found: $Hdr" }
20
21 # Prefer MinGW-w64, fall back to a plain gcc (WinLibs / MSYS2 UCRT) if present.
22 $Candidate = $null
23 if (Get-Command $Cc -ErrorAction SilentlyContinue) {
24 $Candidate = $Cc
25 } elseif (Test-Path "C:\gcc16\bin\gcc.exe") {
26 $Candidate = "C:\gcc16\bin\gcc.exe"
27 } elseif (Get-Command gcc -ErrorAction SilentlyContinue) {
28 $Candidate = "gcc"
29 }
30 if (-not $Candidate) { throw "no C compiler found (need x86_64-w64-mingw32-gcc, C:\gcc16\bin\gcc.exe or gcc on PATH)" }
31
32 Write-Host "Compiling plugin_tetris_3d.exe with $Candidate ..."
33 & $Candidate -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings -o $Out $Src
34 if ($LASTEXITCODE -ne 0) { throw "compile failed with exit code $LASTEXITCODE" }
35
36 $bytes = [System.IO.File]::ReadAllBytes($Out)
37 if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
38 throw "produced artifact is not a PE (no MZ magic)"
39 }
40
41 Write-Host ("Built plugin_tetris_3d.exe {0} bytes" -f $bytes.Length)
42 & $Out --meta
43 if ($LASTEXITCODE -ne 0) { throw "--meta smoke test failed" }
44}
45finally {
46 Pop-Location
47}