<# .SYNOPSIS Set up the rexglue-sdk developer environment. .NOTES Copyright (c) 2026 Tom Clay All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license text. #> function Invoke-ReXSetup { [CmdletBinding()] param( [string]$RepoRoot ) $ErrorActionPreference = "Stop" if (-not $RepoRoot) { $RepoRoot = Get-ReXRoot } $RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot) Write-Host "=== ReXGlue Developer Environment Setup ===" Write-Host "Repo root: $RepoRoot" Write-Host "" # -- Install pre-commit hook ----------------------------------------------- $hookDst = Join-Path $RepoRoot ".git/hooks/pre-commit" $hooksDir = Split-Path $hookDst if (-not (Test-Path $hooksDir)) { New-Item -ItemType Directory -Path $hooksDir -Force | Out-Null } # Resolve pwsh path and bake it into the hook so MSYS2 bash can find it. $pwshCmd = Get-Command pwsh -ErrorAction SilentlyContinue if (-not $pwshCmd) { Write-Host "[WARN] pwsh not found — cannot install pre-commit hook" } else { $pwshPath = $pwshCmd.Source # On Windows, express pwsh path using $PROGRAMFILES so Git Bash # can resolve it without MSYS2 path-escaping issues. if ($IsWindows) { $pfPrefix = $env:ProgramFiles if ($pwshPath.StartsWith($pfPrefix, [System.StringComparison]::OrdinalIgnoreCase)) { $remainder = ($pwshPath.Substring($pfPrefix.Length)) -replace '\\', '/' $pwshExpr = "`"`$PROGRAMFILES$remainder`"" } else { $p = $pwshPath -replace '\\', '/' $drive = $p[0].ToString().ToLower() $pwshExpr = '"/' + $drive + $p.Substring(2) + '"' } } else { $pwshExpr = $pwshPath } $hookLines = @( '#!/bin/sh' '# Auto-generated by Invoke-ReXSetup. Do not edit.' 'REPO_ROOT="$(git rev-parse --show-toplevel)"' "exec $pwshExpr -NoProfile -NonInteractive -File ""`$REPO_ROOT/scripts/git/hook-pre-commit.ps1""" ) $hookLines -join "`n" | Set-Content -Path $hookDst -NoNewline Write-Host "[OK] Pre-commit hook installed (pwsh: $pwshExpr)" } # -- Install VS Developer PowerShell profile (Windows only) ---------------- if ($IsWindows) { $profileSrc = Join-Path $RepoRoot "scripts/vs/rexglue-devprompt.ps1" $profileDst = Join-Path $RepoRoot ".vs/rexglue-devprompt.ps1" if (Test-Path $profileSrc) { $vsDir = Split-Path $profileDst if (-not (Test-Path $vsDir)) { New-Item -ItemType Directory -Path $vsDir -Force | Out-Null } Copy-Item -Path $profileSrc -Destination $profileDst -Force Write-Host "[OK] VS Developer PowerShell profile installed to .vs/" } else { Write-Host "[WARN] Profile source not found: $profileSrc" } } # -- Verify toolchain ------------------------------------------------------ Write-Host "" Write-Host "Toolchain:" $required = @("pwsh", "clang++", "clang-format", "cmake", "ninja") $optional = @("clang-tidy", "cmake-format") foreach ($tool in $required) { $cmd = Get-Command $tool -ErrorAction SilentlyContinue if ($cmd) { $ver = & $tool --version 2>&1 | Select-Object -First 1 Write-Host " [OK] ${tool}: $ver" } else { Write-Host " [MISS] $tool (required)" } } foreach ($tool in $optional) { $cmd = Get-Command $tool -ErrorAction SilentlyContinue if ($cmd) { $ver = & $tool --version 2>&1 | Select-Object -First 1 Write-Host " [OK] ${tool}: $ver" } else { Write-Host " [SKIP] $tool (optional, not found)" } } # -- Summary --------------------------------------------------------------- Write-Host "" Write-Host "Setup complete." Write-Host " Configure: rex-configure (or cmake --preset )" Write-Host " Build: rex-build -Config Debug" Write-Host " Test: rex-test" Write-Host " Format: rex-format" Write-Host " Lint: rex-lint" Write-Host "" }