-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-windows.ps1
More file actions
139 lines (120 loc) · 5.06 KB
/
Copy pathbuild-windows.ps1
File metadata and controls
139 lines (120 loc) · 5.06 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
# build-windows.ps1 — Build vcli.exe on Windows using MSYS2 UCRT64
#
# Run from PowerShell (as normal user, NOT Administrator):
# Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
# .\build-windows.ps1
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$MSYS2_DIR = "C:\msys64"
$UCRT64_GCC = "$MSYS2_DIR\ucrt64\bin\gcc.exe"
$UCRT64_BIN = "$MSYS2_DIR\ucrt64\bin"
$PACMAN = "$MSYS2_DIR\usr\bin\pacman.exe"
# Use MSYS2's own bash explicitly — NOT any other bash on PATH (e.g. Cygwin, Git)
$MSYS2_BASH = "$MSYS2_DIR\usr\bin\bash.exe"
Write-Host ""
Write-Host "=== VoidCache Windows Build ===" -ForegroundColor Cyan
Write-Host ""
# ── Step 1: Check MSYS2 ───────────────────────────────────────────────────────
if (-not (Test-Path $MSYS2_BASH)) {
Write-Host "[1/4] MSYS2 not found at $MSYS2_DIR. Installing via winget..." -ForegroundColor Yellow
$winget = Get-Command winget -ErrorAction SilentlyContinue
if (-not $winget) {
Write-Host "ERROR: winget not found. Install from https://aka.ms/getwinget" -ForegroundColor Red
Write-Host "Or install MSYS2 manually from https://www.msys2.org/ to C:\msys64" -ForegroundColor Red
exit 1
}
winget install --id MSYS2.MSYS2 --silent --accept-package-agreements --accept-source-agreements
Start-Sleep -Seconds 5
if (-not (Test-Path $MSYS2_BASH)) {
Write-Host "ERROR: MSYS2 install failed or not at C:\msys64" -ForegroundColor Red
exit 1
}
}
Write-Host "[1/4] MSYS2 found at $MSYS2_DIR" -ForegroundColor Green
# ── Step 2: Install UCRT64 gcc + openssl via pacman ───────────────────────────
Write-Host "[2/4] Installing UCRT64 gcc and OpenSSL (wepoll+mman are bundled)..." -ForegroundColor Yellow
# Run pacman through MSYS2's OWN bash with --login to get the right environment
# CRITICAL: use $MSYS2_BASH explicitly, never rely on PATH-resolved bash
$packages = "mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-openssl make"
$pacmanCmd = "pacman -S --noconfirm --needed $packages"
& $MSYS2_BASH --login -c $pacmanCmd
if ($LASTEXITCODE -ne 0) {
Write-Host "WARNING: pacman reported errors (may be harmless if packages already installed)" -ForegroundColor Yellow
}
Write-Host "[2/4] Packages ready." -ForegroundColor Green
# ── Step 3: Verify we have the RIGHT gcc (UCRT64, not Cygwin) ────────────────
if (-not (Test-Path $UCRT64_GCC)) {
Write-Host "ERROR: UCRT64 gcc not found at $UCRT64_GCC" -ForegroundColor Red
Write-Host "Run manually in MSYS2 UCRT64 terminal: pacman -S mingw-w64-ucrt-x86_64-gcc" -ForegroundColor Red
exit 1
}
$gccVersion = & $UCRT64_GCC --version 2>&1 | Select-Object -First 1
Write-Host "[3/4] Compiler: $gccVersion" -ForegroundColor Green
# ── Step 4: Build directly with UCRT64 gcc — no bash, no make, no PATH issues ─
Write-Host "[4/4] Building vcli.exe..." -ForegroundColor Yellow
$SRC = Split-Path -Parent $MyInvocation.MyCommand.Path
$OPENSSL = "$MSYS2_DIR\ucrt64"
$Sources = @(
"src\voidcache.c",
"net\proto.c",
"net\auth.c",
"net\commands.c",
"net\server.c",
"net\cluster.c",
"cli\vcli.c",
"compat\wepoll.c",
"compat\mman.c"
) | ForEach-Object { Join-Path $SRC $_ }
$Flags = @(
"-O2", "-std=c11",
"-Iinclude", "-Inet", "-Icompat",
"-I$OPENSSL\include",
"-D_WIN32_WINNT=0x0A00",
"-DVCACHE_WINDOWS",
"-Wno-unused-function", "-Wno-unused-parameter"
)
$Libs = @(
"-L$OPENSSL\lib",
"-lssl", "-lcrypto",
"-lpthread",
"-lws2_32", "-lbcrypt",
"-lm"
)
$OutExe = Join-Path $SRC "vcli.exe"
$GccArgs = $Flags + $Sources + @("-o", $OutExe) + $Libs
Write-Host " $UCRT64_GCC $($GccArgs -join ' ')" -ForegroundColor DarkGray
Write-Host ""
& $UCRT64_GCC @GccArgs
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "Build FAILED. See errors above." -ForegroundColor Red
exit 1
}
# ── Copy required DLLs next to the binary ────────────────────────────────────
Write-Host ""
Write-Host "Copying runtime DLLs..." -ForegroundColor Yellow
$dlls = @(
"libssl-3-x64.dll",
"libcrypto-3-x64.dll",
"libgcc_s_seh-1.dll",
"libwinpthread-1.dll",
"libstdc++-6.dll"
)
foreach ($dll in $dlls) {
$src = Join-Path $UCRT64_BIN $dll
if (Test-Path $src) {
Copy-Item $src $SRC -Force
Write-Host " Copied $dll" -ForegroundColor DarkGray
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host " Build complete! vcli.exe is ready." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "Test (cluster must be running):" -ForegroundColor White
Write-Host " .\vcli.exe -h localhost -p 6379 PING" -ForegroundColor Cyan
Write-Host ""
Write-Host "Interactive shell:" -ForegroundColor White
Write-Host " .\vcli.exe -h localhost -p 6379" -ForegroundColor Cyan
Write-Host ""