Files
mcp-memory/build.ps1
T

108 lines
4.7 KiB
PowerShell

$ErrorActionPreference = 'Stop'
Write-Host "Building mcp-memory (server and stub) for Windows..." -ForegroundColor Cyan
& rustup run stable cargo build --release --workspace --exclude mcp-memory-linux-nvim
if ($LASTEXITCODE -ne 0) {
Write-Error "Windows build failed!"
exit $LASTEXITCODE
}
Write-Host "Building mcp-memory (server and stub) for Linux (WSL)..." -ForegroundColor Cyan
wsl.exe -d Ubuntu -e bash -c 'cd /mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory && export PATH="$HOME/.cargo/bin:$PATH" && cargo build --release --workspace --exclude mcp-memory-win-nvim'
if ($LASTEXITCODE -ne 0) {
Write-Error "Linux build failed!"
exit $LASTEXITCODE
}
Write-Host "`nBuild successful! Gracefully shutting down running servers..." -ForegroundColor Green
$serverExe = "C:\Users\reazul.ashraf\.local\bin\mcp-memory-server.exe"
if (Test-Path $serverExe) {
& $serverExe --exit 2>$null
}
try {
$tokenPath = "C:\Users\reazul.ashraf\.gemini\mcp_memory\admin.token"
$headers = @{}
if (Test-Path $tokenPath) {
$headers["Authorization"] = "Bearer $(Get-Content -Path $tokenPath -Raw)".Trim()
}
Invoke-RestMethod -Uri "https://127.0.0.1:3000/shutdown" -Method Post -Headers $headers -SkipCertificateCheck -ErrorAction Stop | Out-Null
} catch {
# The response often ends prematurely because the server abruptly kills its own process during shutdown. This is expected.
}
Start-Sleep -Seconds 2
function Get-ExeVersion {
param([string]$Path, [string]$EnvName)
if ($EnvName -eq 'WSL') {
$checkCmd = "if [ -x ""$Path"" ]; then $Path --version; else echo 'Not Found'; fi"
$output = wsl.exe -d Ubuntu -e bash -c $checkCmd
} else {
if (Test-Path $Path) {
$output = & $Path --version 2>&1
} else {
$output = 'Not Found'
}
}
if ([string]::IsNullOrWhiteSpace($output)) { return "No Output / Errored" }
return $output.Trim()
}
function Deploy-If-Needed {
param([string]$Source, [string]$Dest, [string]$EnvName)
$sourceVerPath = $Source
if ($EnvName -eq 'WSL') {
$sourceVerPath = wsl.exe -d Ubuntu -e wslpath -u $Source
}
$sourceVer = Get-ExeVersion -Path $sourceVerPath -EnvName $EnvName
$destVer = Get-ExeVersion -Path $Dest -EnvName $EnvName
if ($sourceVer -eq $destVer -and $sourceVer -ne "Not Found") {
Write-Host " Skip: $($Dest) is already up-to-date ($sourceVer)" -ForegroundColor DarkGray
return
}
Write-Host " Update: $($Dest) ($destVer -> $sourceVer)" -ForegroundColor Yellow
if ($EnvName -eq 'WSL') {
# Translate source path to WSL path
$wslSource = wsl.exe -d Ubuntu -e wslpath -u $Source
wsl.exe -d Ubuntu -e bash -c "mv $Dest ${Dest}.\$(date +%s).old 2>/dev/null || true; cp $wslSource $Dest && chmod +x $Dest"
} else {
if (Test-Path $Dest) {
$rand = Get-Random
Move-Item -Path $Dest -Destination "${Dest}.${rand}.old" -Force -ErrorAction SilentlyContinue
}
Copy-Item -Path $Source -Destination $Dest -Force
}
$newDestVer = Get-ExeVersion -Path $Dest -EnvName $EnvName
if ($newDestVer -eq $sourceVer) {
Write-Host " Success: $($Dest) verified as $newDestVer" -ForegroundColor Green
} else {
Write-Error " Failed: $($Dest) version mismatch after copy! Expected $sourceVer, got $newDestVer"
}
}
Write-Host "`nDeploying and verifying binaries..." -ForegroundColor Cyan
$winBase = "C:\Users\reazul.ashraf\.local\bin"
$wslBase = "/home/riz/.local/bin"
$winTarget = "target\release"
$wslTarget = "target\release"
Deploy-If-Needed -Source "$winTarget\mcp-memory-server.exe" -Dest "$winBase\mcp-memory-server.exe" -EnvName "Win"
Deploy-If-Needed -Source "$winTarget\mcp-memory-stub.exe" -Dest "$winBase\mcp-memory-stub.exe" -EnvName "Win"
Deploy-If-Needed -Source "$winTarget\mcp-memory-win-nvim.exe" -Dest "$winBase\mcp-memory-win-nvim.exe" -EnvName "Win"
# Note: Source is local windows path, but Deploy-If-Needed translates it to wslpath
Deploy-If-Needed -Source "$wslTarget\mcp-memory-server" -Dest "$wslBase/mcp-memory-server" -EnvName "WSL"
Deploy-If-Needed -Source "$wslTarget\mcp-memory-stub" -Dest "$wslBase/mcp-memory-stub" -EnvName "WSL"
Deploy-If-Needed -Source "$wslTarget\mcp-memory-linux-nvim" -Dest "$wslBase/mcp-memory-linux-nvim" -EnvName "WSL"
Write-Host "`nCopying instructions.md..." -ForegroundColor Cyan
Copy-Item instructions.md "C:\Users\reazul.ashraf\.gemini\antigravity-cli\mcp\memory\instructions.md" -Force
wsl.exe -d Ubuntu -e bash -c "mkdir -p /home/riz/.gemini/antigravity-cli/mcp/memory && cp $(wsl.exe -d Ubuntu -e wslpath -u instructions.md) /home/riz/.gemini/antigravity-cli/mcp/memory/instructions.md"
Write-Host "`nBuild and deployment complete!" -ForegroundColor Green