Repository navigation
Expand file tree
/
Copy pathsetup-and-run.ps1
More file actions
300 lines (227 loc) · 7.14 KB
/
Copy pathsetup-and-run.ps1
File metadata and controls
300 lines (227 loc) · 7.14 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
300
param(
[switch]$NoLaunch
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
function Step([string]$Message) {
Write-Host "`n==> $Message" -ForegroundColor Cyan
}
function Ok([string]$Message) {
Write-Host "[OK] $Message" -ForegroundColor Green
}
function Refresh-Path {
$machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine")
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$env:Path = "$machinePath;$userPath;$env:USERPROFILE\.cargo\bin"
}
function Has([string]$Name) {
return $null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
}
function Run {
param(
[Parameter(Mandatory = $true)]
[string]$Executable,
[Parameter()]
[string[]]$Arguments = @()
)
& $Executable @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed ($LASTEXITCODE): $Executable $($Arguments -join ' ')"
}
}
function WingetInstall {
param(
[Parameter(Mandatory = $true)]
[string]$Id,
[Parameter()]
[string[]]$ExtraArguments = @()
)
if (-not (Has "winget")) {
throw "winget is missing. Install/update 'App Installer' from Microsoft Store and rerun."
}
Step "Installing $Id"
$wingetArguments = @(
"install",
"--id", $Id,
"-e",
"--accept-package-agreements",
"--accept-source-agreements"
) + $ExtraArguments
Run -Executable "winget" -Arguments $wingetArguments
Refresh-Path
}
function Ensure-Node {
if (-not (Has "node") -or -not (Has "npm")) {
WingetInstall -Id "OpenJS.NodeJS.LTS" -ExtraArguments @("--silent")
}
Refresh-Path
if (-not (Has "node") -or -not (Has "npm")) {
throw "Node/npm was installed but is not visible yet. Open a new PowerShell window and rerun this script."
}
Ok "Node $(node --version), npm $(npm --version)"
}
function Ensure-Python {
if (-not (Has "py") -and -not (Has "python")) {
WingetInstall -Id "Python.Python.3.12" -ExtraArguments @("--silent")
}
Refresh-Path
if (-not (Has "py") -and -not (Has "python")) {
throw "Python was installed but is not visible yet. Open a new PowerShell window and rerun this script."
}
if (Has "py") {
Ok "$(py --version)"
} else {
Ok "$(python --version)"
}
}
function Ensure-Rust {
Refresh-Path
if (Has "cargo" -and Has "rustc") {
Ok "$(cargo --version)"
Ok "$(rustc --version)"
return
}
if (-not (Has "rustup")) {
WingetInstall -Id "Rustlang.Rustup" -ExtraArguments @("--silent")
Refresh-Path
}
if (-not (Has "rustup")) {
$rustupPath = Join-Path $env:USERPROFILE ".cargo\bin\rustup.exe"
if (Test-Path $rustupPath) {
$env:Path = "$(Split-Path $rustupPath);$env:Path"
}
}
if (-not (Has "rustup")) {
throw "rustup is not available after installation. Open a new PowerShell window and rerun this script."
}
Step "Installing Rust stable-msvc toolchain"
Run -Executable "rustup" -Arguments @(
"toolchain",
"install",
"stable-msvc"
)
Run -Executable "rustup" -Arguments @(
"default",
"stable-msvc"
)
Refresh-Path
if (-not (Has "cargo") -or -not (Has "rustc")) {
throw "Rust was installed but cargo/rustc is not visible yet. Open a new PowerShell window and rerun this script."
}
Ok "$(cargo --version)"
Ok "$(rustc --version)"
}
function Have-VCTools {
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswhere)) {
return $false
}
$result = & $vswhere `
-latest `
-products * `
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
-property installationPath 2>$null
return -not [string]::IsNullOrWhiteSpace(($result | Out-String))
}
function Ensure-VCTools {
if (Have-VCTools) {
Ok "Visual Studio C++ Build Tools"
return
}
WingetInstall -Id "Microsoft.VisualStudio.2022.BuildTools" -ExtraArguments @(
"--override",
"--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
)
if (-not (Have-VCTools)) {
throw "C++ Build Tools were not detected after installation. Reboot Windows if requested and rerun."
}
Ok "Visual Studio C++ Build Tools"
}
function Build-Sidecar {
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[string]$Directory
)
$buildScript = Join-Path $Directory "build.ps1"
if (-not (Test-Path $buildScript)) {
throw "Missing build script: $buildScript"
}
Step "Building $Name"
Push-Location $Directory
try {
& powershell.exe `
-NoProfile `
-ExecutionPolicy Bypass `
-File ".\build.ps1"
if ($LASTEXITCODE -ne 0) {
throw "$Name build failed."
}
}
finally {
Pop-Location
}
Ok "$Name"
}
$root = $PSScriptRoot
if ([string]::IsNullOrWhiteSpace($root)) {
throw "Could not determine repository root."
}
Set-Location $root
Write-Host "========================================" -ForegroundColor DarkCyan
Write-Host " KNeuron - Windows first-run bootstrap" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor DarkCyan
if (-not (Test-Path ".\package.json")) {
throw "Put this script in the KNeuron repository root."
}
Step "Checking/installing system dependencies"
Refresh-Path
Ensure-Node
Ensure-Python
Ensure-Rust
Ensure-VCTools
Step "Installing JavaScript dependencies"
if (Test-Path ".\package-lock.json") {
Run -Executable "npm" -Arguments @("ci")
} else {
Run -Executable "npm" -Arguments @("install")
}
Ok "Node dependencies"
Build-Sidecar `
-Name "BrainAccess bridge" `
-Directory (Join-Path $root "brainaccess-sidecar")
Build-Sidecar `
-Name "SSVEP classifier" `
-Directory (Join-Path $root "ssvep-sidecar")
Build-Sidecar `
-Name "BrainLink bridge" `
-Directory (Join-Path $root "brainlink-sidecar")
Step "Verifying sidecars"
$expectedBinaries = @(
"brainaccess-bridge-x86_64-pc-windows-msvc.exe",
"ssvep-classifier-x86_64-pc-windows-msvc.exe",
"brainlink-bridge-x86_64-pc-windows-msvc.exe"
)
foreach ($binaryName in $expectedBinaries) {
$binaryPath = Join-Path $root "src-tauri\binaries\$binaryName"
if (-not (Test-Path $binaryPath)) {
throw "Expected sidecar not found: $binaryPath"
}
$sizeMb = [math]::Round((Get-Item $binaryPath).Length / 1MB, 2)
Ok "$binaryName ($sizeMb MB)"
}
if (-not (Test-Path ".\public\neuorrun\Build")) {
Write-Warning "Neuorrun WebGL build is missing. Keep public/neuorrun/Build in the repository or build it separately."
} else {
Ok "Neuorrun WebGL build"
}
Write-Host "`nKNeuron setup completed successfully." -ForegroundColor Green
if (-not $NoLaunch) {
Step "Starting KNeuron"
Run -Executable "npm" -Arguments @("run", "tauri:dev")
} else {
Write-Host ""
Write-Host "Run later with:"
Write-Host " npm run tauri:dev"
}