-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ps1
More file actions
113 lines (99 loc) · 5.08 KB
/
build.ps1
File metadata and controls
113 lines (99 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<#
.SYNOPSIS
Build CE-Handwire.dll (debug and/or release).
Works both interactively (human) and non-interactively (Claude Code Bash tool).
.PARAMETER Config
debug | release | both (default: both)
.EXAMPLE
.\build.ps1 # build debug + release
.\build.ps1 debug # debug only (faster, useful during iteration)
.\build.ps1 -Config release # release only
#>
param(
[Parameter(Position = 0)]
[ValidateSet('debug', 'release', 'both')]
[string]$Config = 'both'
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# ── UTF-8 everywhere ──────────────────────────────────────────────────────
# Prevents garbled output when called from Git Bash / piped to a tool.
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# ── Paths ─────────────────────────────────────────────────────────────────
$VS_ROOT = 'C:\Program Files\Microsoft Visual Studio\18\Community'
$VCVARSALL = "$VS_ROOT\VC\Auxiliary\Build\vcvarsall.bat"
$CMAKE = "$VS_ROOT\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
foreach ($p in $VCVARSALL, $CMAKE) {
if (-not (Test-Path $p)) { Write-Error "Not found: $p"; exit 1 }
}
# ── Set up VS x64 environment (silent — no banner, no cmd.exe noise) ──────
# Strategy: write a temp .bat that sources vcvarsall then dumps env with SET,
# capture the output in this PS process, apply each var. cmake is then called
# directly in PS — never through a cmd wrapper — so PS never wraps cmake
# stderr into localized ErrorRecord text.
$tmp = [IO.Path]::GetTempFileName() -replace '\.tmp$', '.bat'
try {
@(
'@echo off'
"call `"$VCVARSALL`" amd64 >nul 2>&1"
'chcp 65001 >nul' # switch code page to UTF-8 before SET output
'set'
) | Set-Content $tmp -Encoding ASCII
cmd.exe /c $tmp | Where-Object { $_ -match '^[^=]+=' } | ForEach-Object {
$eq = $_.IndexOf('=')
[Environment]::SetEnvironmentVariable(
$_.Substring(0, $eq),
$_.Substring($eq + 1),
'Process'
)
}
} finally {
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
}
# ── Zydis dependency guard ────────────────────────────────────────────────
# CMakeLists.txt prefers the sibling repo D:/Github/Zydis; if absent it falls
# back to docs/zydis (submodule). That fallback requires docs/zydis/dependencies/
# zycore to be checked out, but CE-Handwire's .gitmodules does not register
# zycore directly — so a plain `git submodule update --init` from the root
# won't reach it.
#
# Fix: when the sibling is missing, run `git submodule update --init --recursive
# -- docs/zydis` from the repo root. Git follows the submodule chain inside
# docs/zydis and pins zycore to the exact commit docs/zydis records, keeping
# docs/zydis clean.
$siblingZydis = [IO.Path]::GetFullPath("$PSScriptRoot/../Zydis/CMakeLists.txt")
if (-not (Test-Path $siblingZydis)) {
Write-Host "Sibling Zydis not found — initialising docs/zydis/zycore..." -ForegroundColor Yellow
git -C $PSScriptRoot submodule update --init --recursive -- docs/zydis
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: failed to initialise docs/zydis submodule tree." -ForegroundColor Red
exit 1
}
}
# ── Build helper ──────────────────────────────────────────────────────────
function Invoke-Preset([string]$preset) {
Write-Host "=== Configure ($preset) ===" -ForegroundColor Cyan
& $CMAKE --preset $preset
if ($LASTEXITCODE -ne 0) { throw "cmake --preset $preset exited $LASTEXITCODE" }
Write-Host "=== Build ($preset) ===" -ForegroundColor Cyan
& $CMAKE --build --preset $preset
if ($LASTEXITCODE -ne 0) { throw "cmake --build --preset $preset exited $LASTEXITCODE" }
Write-Host "=== $preset OK ===" -ForegroundColor Green
}
# ── Run ───────────────────────────────────────────────────────────────────
Push-Location $PSScriptRoot
try {
if ($Config -in 'debug', 'both') { Invoke-Preset 'x64-debug' }
if ($Config -in 'release', 'both') { Invoke-Preset 'x64-release' }
Write-Host "`nAll builds succeeded." -ForegroundColor Green
if ($Config -in 'debug', 'both') { Write-Host " Debug: build\x64-debug\CE-Handwire.dll" }
if ($Config -in 'release', 'both') { Write-Host " Release: build\x64-release\CE-Handwire.dll" }
exit 0
} catch {
Write-Host "`nBUILD FAILED: $_" -ForegroundColor Red
exit 1
} finally {
Pop-Location
}