scorpiox-bot-plugin-nvtop
←build.ps1text
53 lines · 1 KBHEADBlameDownload
1# build.ps1 - Windows MinGW-w64 static build for plugin_nvtop
2#
3# Usage (from the repo root, PowerShell):
4# powershell -ExecutionPolicy Bypass -File build.ps1
5#
6# Produces .\plugin_nvtop.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# This plugin needs no extra Win32 import libraries.
9
10$ErrorActionPreference = "Stop"
11$ScriptDir = $PSScriptRoot
12Push-Location $ScriptDir
13try {
14 $Src = Join-Path $ScriptDir "src\plugin_nvtop.c"
15 $Out = Join-Path $ScriptDir "plugin_nvtop.exe"
16 $Cc = "x86_64-w64-mingw32-gcc"
17
18 if (-not (Test-Path $Src)) { throw "source not found: $Src" }
19
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_nvtop.exe with $Cc"
31 & $Cc -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings -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_nvtop.exe `"`$env:LOCALAPPDATA\scorpiox\plugins\`""
50}
51finally {
52 Pop-Location
53}