Skip to content

Commit e6c154a

Browse files
committed
feat(build): build script for Windows PowerShell
1 parent fe4b8f9 commit e6c154a

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

scripts/build.ps1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env pwsh
2+
# PowerShell build script for mcpproxy
3+
4+
param(
5+
[string]$Version = ""
6+
)
7+
8+
# Enable strict mode
9+
$ErrorActionPreference = "Stop"
10+
11+
# Get version from git tag, or use default
12+
if ([string]::IsNullOrEmpty($Version)) {
13+
try {
14+
$Version = git describe --tags --abbrev=0 2>$null
15+
if ([string]::IsNullOrEmpty($Version)) {
16+
$Version = "v0.1.0-dev"
17+
}
18+
}
19+
catch {
20+
$Version = "v0.1.0-dev"
21+
}
22+
}
23+
24+
# Get commit hash
25+
try {
26+
$Commit = git rev-parse --short HEAD 2>$null
27+
if ([string]::IsNullOrEmpty($Commit)) {
28+
$Commit = "unknown"
29+
}
30+
}
31+
catch {
32+
$Commit = "unknown"
33+
}
34+
35+
# Get current date in UTC
36+
$Date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
37+
38+
Write-Host "Building mcpproxy version: $Version" -ForegroundColor Green
39+
Write-Host "Commit: $Commit" -ForegroundColor Green
40+
Write-Host "Date: $Date" -ForegroundColor Green
41+
Write-Host ""
42+
43+
$LDFLAGS = "-X main.version=$Version -X main.commit=$Commit -X main.date=$Date -s -w"
44+
45+
# Build for current platform (with CGO for tray support if needed)
46+
Write-Host "Building for current platform..." -ForegroundColor Cyan
47+
go build -ldflags $LDFLAGS -o mcpproxy.exe ./cmd/mcpproxy
48+
if ($LASTEXITCODE -ne 0) {
49+
Write-Error "Failed to build for current platform"
50+
exit $LASTEXITCODE
51+
}
52+
53+
# Build for Linux (with CGO disabled to avoid systray issues)
54+
Write-Host "Building for Linux..." -ForegroundColor Cyan
55+
$env:CGO_ENABLED = "0"
56+
$env:GOOS = "linux"
57+
$env:GOARCH = "amd64"
58+
go build -ldflags $LDFLAGS -o mcpproxy-linux-amd64 ./cmd/mcpproxy
59+
if ($LASTEXITCODE -ne 0) {
60+
Write-Error "Failed to build for Linux"
61+
exit $LASTEXITCODE
62+
}
63+
64+
# Build for Windows (with CGO disabled to avoid systray issues)
65+
Write-Host "Building for Windows..." -ForegroundColor Cyan
66+
$env:CGO_ENABLED = "0"
67+
$env:GOOS = "windows"
68+
$env:GOARCH = "amd64"
69+
go build -ldflags $LDFLAGS -o mcpproxy-windows-amd64.exe ./cmd/mcpproxy
70+
if ($LASTEXITCODE -ne 0) {
71+
Write-Error "Failed to build for Windows"
72+
exit $LASTEXITCODE
73+
}
74+
75+
# Reset environment variables
76+
Remove-Item Env:CGO_ENABLED -ErrorAction SilentlyContinue
77+
Remove-Item Env:GOOS -ErrorAction SilentlyContinue
78+
Remove-Item Env:GOARCH -ErrorAction SilentlyContinue
79+
80+
# Build for macOS (skip on Windows as cross-compilation for macOS systray is problematic)
81+
Write-Host "Skipping macOS builds (running on Windows - systray dependencies prevent cross-compilation)" -ForegroundColor Yellow
82+
83+
Write-Host ""
84+
Write-Host "Build complete!" -ForegroundColor Green
85+
Write-Host "Available binaries:" -ForegroundColor Green
86+
Get-ChildItem -Path . -Filter "mcpproxy*" | Select-Object Name, Length, LastWriteTime | Format-Table -AutoSize
87+
88+
Write-Host ""
89+
Write-Host "Test version info:" -ForegroundColor Cyan
90+
& .\mcpproxy.exe --version
91+

0 commit comments

Comments
 (0)