-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
300 lines (254 loc) · 11.3 KB
/
Copy pathsetup.ps1
File metadata and controls
300 lines (254 loc) · 11.3 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<#
.SYNOPSIS
OpenWizz one-shot setup — run this once after cloning.
.DESCRIPTION
Installs and verifies every dependency required to build OpenWizz:
1. Git (required to clone/update vcpkg)
2. .NET 10 SDK (required for OpenWizz.UI and tests)
3. Visual Studio 2022/2026 C++ workload (v145 toolset + Windows 10 SDK)
4. vcpkg (cloned into ./vcpkg and bootstrapped)
5. zstd (x64-windows-static via vcpkg manifest)
6. vcpkg MSBuild integration (vcpkg integrate install)
7. NuGet packages (dotnet restore)
After a successful run you can open OpenWizz.sln in Visual Studio and build.
.PARAMETER Force
Re-clone/re-bootstrap vcpkg and reinstall zstd even if already present.
.PARAMETER SkipPrereqCheck
Skip the Git / .NET / VS prerequisite checks (useful in CI where they
are guaranteed to exist).
.EXAMPLE
# Normal first-time setup
.\setup.ps1
# Force full reinstall of vcpkg + zstd
.\setup.ps1 -Force
#>
[CmdletBinding()]
param(
[switch]$Force,
[switch]$SkipPrereqCheck
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Root = $PSScriptRoot
$VcpkgDir = Join-Path $Root "vcpkg"
$VcpkgExe = Join-Path $VcpkgDir "vcpkg.exe"
$Triplet = "x64-windows-static"
$InstallRoot = Join-Path $Root "vcpkg_installed"
$ZstdLib = Join-Path $InstallRoot "$Triplet\lib\zstd.lib"
$ZstdH = Join-Path $InstallRoot "$Triplet\include\zstd.h"
# ── Helpers ──────────────────────────────────────────────────────────────────
function Write-Header([string]$t) {
Write-Host ""
Write-Host ("=" * 58) -ForegroundColor Cyan
Write-Host " $t" -ForegroundColor Cyan
Write-Host ("=" * 58) -ForegroundColor Cyan
Write-Host ""
}
function Write-OK ([string]$m) { Write-Host " [OK] $m" -ForegroundColor Green }
function Write-Warn([string]$m) { Write-Host " [!!] $m" -ForegroundColor Yellow }
function Write-Err ([string]$m) { Write-Host " [ERR] $m" -ForegroundColor Red }
function Write-Info([string]$m) { Write-Host " $m" -ForegroundColor Gray }
$script:Failures = 0
function Fail([string]$m) { Write-Err $m; $script:Failures++ }
# ── Step 1 – Prerequisites ────────────────────────────────────────────────────
if (-not $SkipPrereqCheck) {
Write-Header "Step 1 – Prerequisites"
# Git
try {
$gitVer = (git --version 2>&1) -replace "git version ",""
Write-OK "Git $gitVer"
} catch {
Fail "Git not found. Install from https://git-scm.com"
}
# .NET SDK >= 10
try {
$sdks = dotnet --list-sdks 2>&1
$net10 = $sdks | Where-Object { $_ -match "^10\." }
if ($net10) {
Write-OK ".NET 10 SDK: $($net10 | Select-Object -Last 1)"
} else {
Fail ".NET 10 SDK not found. Install from https://dotnet.microsoft.com/download/dotnet/10.0"
Write-Info "Installed SDKs: $($sdks -join ', ')"
}
} catch {
Fail ".NET SDK not found. Install from https://dotnet.microsoft.com/download"
}
# VS 2022/2026 / MSVC v145 toolset
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vsWhere) {
$vsInfo = & $vsWhere -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -property displayName 2>&1
if ($vsInfo) {
$vsVer = & $vsWhere -latest -property catalog_productDisplayVersion 2>&1
Write-OK "Visual Studio: $vsInfo ($vsVer)"
} else {
Fail "Visual Studio 2022 or 2026 with C++ Desktop workload not found."
Write-Info "Install 'Desktop development with C++' from https://visualstudio.microsoft.com"
}
} else {
Write-Warn "vswhere.exe not found — cannot verify VS installation. Continuing anyway."
}
if ($script:Failures -gt 0) {
Write-Host ""
Write-Err "$($script:Failures) prerequisite(s) missing — install them then re-run setup.ps1."
exit 1
}
}
# ── Step 2 – vcpkg ───────────────────────────────────────────────────────────
Write-Header "Step 2 – vcpkg"
if ((Test-Path $VcpkgExe) -and -not $Force) {
$v = & $VcpkgExe version 2>&1 | Select-Object -First 1
Write-OK "vcpkg already installed: $v"
Write-Info "Use -Force to re-bootstrap."
} else {
# Clone if directory absent
if (-not (Test-Path $VcpkgDir)) {
Write-Info "Cloning vcpkg from GitHub..."
git clone https://github.com/microsoft/vcpkg.git $VcpkgDir
Write-OK "Cloned vcpkg."
} elseif ($Force) {
Write-Info "Updating vcpkg..."
Push-Location $VcpkgDir
try { git pull } finally { Pop-Location }
Write-OK "vcpkg updated."
}
# Bootstrap
Write-Info "Bootstrapping vcpkg..."
$bootstrap = Join-Path $VcpkgDir "bootstrap-vcpkg.bat"
if (-not (Test-Path $bootstrap)) {
Fail "bootstrap-vcpkg.bat not found at $bootstrap — vcpkg clone may be incomplete."
exit 1
}
Push-Location $VcpkgDir
try { cmd /c "bootstrap-vcpkg.bat -disableMetrics" } finally { Pop-Location }
if (Test-Path $VcpkgExe) {
$v = & $VcpkgExe version 2>&1 | Select-Object -First 1
Write-OK "vcpkg ready: $v"
} else {
Fail "Bootstrap completed but vcpkg.exe not found — check bootstrap output above."
exit 1
}
}
# ── Step 3 – zstd (via vcpkg manifest) ───────────────────────────────────────
Write-Header "Step 3 – zstd ($Triplet)"
$needInstall = $Force -or (-not (Test-Path $ZstdLib)) -or (-not (Test-Path $ZstdH))
if (-not $needInstall) {
$sizeKb = [math]::Round((Get-Item $ZstdLib).Length / 1KB, 0)
Write-OK "zstd.lib already installed ($sizeKb KB)"
Write-OK "zstd.h header present"
} else {
if ($Force -and (Test-Path $InstallRoot)) {
Write-Warn "Force flag: wiping vcpkg_installed for a clean reinstall..."
Remove-Item $InstallRoot -Recurse -Force
Write-OK "Removed old vcpkg_installed."
}
Write-Info "Running vcpkg install (triplet: $Triplet)..."
Push-Location $Root
try {
& $VcpkgExe install `
--triplet $Triplet `
--x-install-root "vcpkg_installed" `
--x-manifest-root "." `
--clean-buildtrees `
--no-print-usage
if ($LASTEXITCODE -ne 0) {
Fail "vcpkg install exited with code $LASTEXITCODE."
exit 1
}
} catch {
Fail "vcpkg install threw an exception: $_"
exit 1
} finally {
Pop-Location
}
# Belt-and-suspenders: remove any residual buildtrees to stop VS picking
# up zstd's bundled .sln files and showing them in Solution Explorer.
$bt = Join-Path $VcpkgDir "buildtrees\zstd"
if (Test-Path $bt) {
Remove-Item $bt -Recurse -Force -ErrorAction SilentlyContinue
Write-Info "Cleaned up residual buildtrees\zstd."
}
# Verify
if (Test-Path $ZstdLib) {
$sizeKb = [math]::Round((Get-Item $ZstdLib).Length / 1KB, 0)
Write-OK "zstd.lib installed ($sizeKb KB)"
} else {
Fail "zstd.lib not found at $ZstdLib after install."
}
if (Test-Path $ZstdH) {
Write-OK "zstd.h header installed"
} else {
Fail "zstd.h not found at $ZstdH after install."
}
}
# Also clean any orphan vcpkg_installed inside src/native/lib/ (wrong-dir run artifact)
$orphan = Join-Path $Root "src\native\lib\vcpkg_installed"
if (Test-Path $orphan) {
Write-Warn "Removing orphan vcpkg_installed from src/native/lib/..."
Remove-Item $orphan -Recurse -Force -ErrorAction SilentlyContinue
Write-OK "Removed."
}
# ── Step 4 – vcpkg MSBuild integration ───────────────────────────────────────
Write-Header "Step 4 – vcpkg MSBuild Integration"
if (Test-Path $VcpkgExe) {
Write-Info "Running: vcpkg integrate install..."
# $ErrorActionPreference = "Stop" can fire on vcpkg warnings sent to stderr.
# Capture output without throwing, then check the real exit code.
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
$integrateOutput = & $VcpkgExe integrate install --vcpkg-root $VcpkgDir 2>&1
$integrateExit = $LASTEXITCODE
$ErrorActionPreference = $prevEAP
$integrateOutput | ForEach-Object { Write-Info "$_" }
if ($integrateExit -ne 0) {
Fail "vcpkg integrate install exited with code $integrateExit."
} else {
Write-OK "vcpkg MSBuild integration installed (include/lib paths auto-configured)."
}
} else {
Write-Warn "vcpkg.exe not found — skipping MSBuild integration (run step 2 first)."
}
# ── Step 5 – NuGet restore ───────────────────────────────────────────────────
Write-Header "Step 5 – NuGet Packages (dotnet restore)"
$UiProject = Join-Path $Root "src\dotnet\OpenWizz.UI\OpenWizz.UI.csproj"
$TestProject = Join-Path $Root "tests\dotnet\OpenWizz.Tests\OpenWizz.Tests.csproj"
foreach ($proj in @($UiProject, $TestProject)) {
if (Test-Path $proj) {
$name = Split-Path $proj -Leaf
Write-Info "Restoring $name..."
try {
dotnet restore $proj --locked-mode 2>&1 | ForEach-Object { Write-Info $_ }
if ($LASTEXITCODE -ne 0) {
Fail "dotnet restore failed for $name (exit code $LASTEXITCODE)."
} else {
Write-OK "$name — NuGet packages restored."
}
} catch {
Fail "dotnet restore threw an exception for ${name}: $_"
}
} else {
Write-Warn "Project not found, skipping restore: $proj"
}
}
# ── Step 6 – Validate project references ─────────────────────────────────────
Write-Header "Step 6 – Validate vcxproj source references"
$checkScript = Join-Path $Root "scripts\check-project-refs.ps1"
if (Test-Path $checkScript) {
& $checkScript -Root $Root
} else {
Write-Warn "check-project-refs.ps1 not found — skipping validation."
}
# ── Summary ───────────────────────────────────────────────────────────────────
Write-Header "Setup Complete"
if ($script:Failures -eq 0) {
Write-OK "Everything is installed and ready."
Write-Host ""
Write-Host " Next steps:" -ForegroundColor White
Write-Host " 1. Open OpenWizz.sln in Visual Studio 2022 or 2026" -ForegroundColor Gray
Write-Host " 2. Set configuration: x64 | Debug (or Release)" -ForegroundColor Gray
Write-Host " 3. Build Solution (Ctrl+Shift+B)" -ForegroundColor Gray
Write-Host " 4. Run tests: .\scripts\RunAllTests.ps1" -ForegroundColor Gray
Write-Host ""
} else {
Write-Err "$($script:Failures) error(s) during setup — see above."
exit 1
}