-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild.ps1
More file actions
174 lines (152 loc) · 5.97 KB
/
Copy pathbuild.ps1
File metadata and controls
174 lines (152 loc) · 5.97 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
#!/usr/bin/env pwsh
# PowerShell build script for mcpproxy
param(
[string]$Version = "",
[switch]$BuildTray,
[switch]$OnlyCurrentPlatform
)
# Enable strict mode
$ErrorActionPreference = "Stop"
# Get version from git tag, or use default
if ([string]::IsNullOrEmpty($Version)) {
try {
$Version = git describe --tags --abbrev=0 2>$null
if ([string]::IsNullOrEmpty($Version)) {
$Version = "v0.1.0-dev"
}
}
catch {
$Version = "v0.1.0-dev"
}
}
# Get commit hash
try {
$Commit = git rev-parse --short HEAD 2>$null
if ([string]::IsNullOrEmpty($Commit)) {
$Commit = "unknown"
}
}
catch {
$Commit = "unknown"
}
# Get current date in UTC
$Date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
Write-Host "Building mcpproxy version: $Version" -ForegroundColor Green
Write-Host "Commit: $Commit" -ForegroundColor Green
Write-Host "Date: $Date" -ForegroundColor Green
Write-Host ""
$LDFLAGS = "-X main.version=$Version -X main.commit=$Commit -X main.date=$Date -X github.com/smart-mcp-proxy/mcpproxy-go/internal/httpapi.buildVersion=$Version -s -w"
# Array to track built binaries
$BuiltBinaries = @()
# Build for current platform (with CGO for tray support if needed)
Write-Host "Building for current platform..." -ForegroundColor Cyan
go build -ldflags $LDFLAGS -o mcpproxy.exe ./cmd/mcpproxy
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build for current platform"
exit $LASTEXITCODE
}
$BuiltBinaries += "mcpproxy.exe"
if (!$OnlyCurrentPlatform) {
# Build for Linux (with CGO disabled to avoid systray issues)
Write-Host "Building for Linux..." -ForegroundColor Cyan
$env:CGO_ENABLED = "0"
$env:GOOS = "linux"
$env:GOARCH = "amd64"
go build -ldflags $LDFLAGS -o mcpproxy-linux-amd64 ./cmd/mcpproxy
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build for Linux"
exit $LASTEXITCODE
}
$BuiltBinaries += "mcpproxy-linux-amd64"
# Build for Windows (with CGO disabled to avoid systray issues)
Write-Host "Building for Windows..." -ForegroundColor Cyan
$env:CGO_ENABLED = "0"
$env:GOOS = "windows"
$env:GOARCH = "amd64"
go build -ldflags $LDFLAGS -o mcpproxy-windows-amd64.exe ./cmd/mcpproxy
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build for Windows"
exit $LASTEXITCODE
}
$BuiltBinaries += "mcpproxy-windows-amd64.exe"
# Reset environment variables
Remove-Item Env:CGO_ENABLED -ErrorAction SilentlyContinue
Remove-Item Env:GOOS -ErrorAction SilentlyContinue
Remove-Item Env:GOARCH -ErrorAction SilentlyContinue
# Build for macOS (skip on Windows as cross-compilation for macOS systray is problematic)
Write-Host "Skipping macOS builds (running on Windows - systray dependencies prevent cross-compilation)" -ForegroundColor Yellow
} else {
Write-Host "Skipping cross-platform builds (OnlyCurrentPlatform flag is set)" -ForegroundColor Yellow
}
# Build tray binaries if requested
if ($BuildTray) {
Write-Host ""
Write-Host "Building mcpproxy-tray binaries..." -ForegroundColor Magenta
# Build tray for current platform (Windows with CGO)
Write-Host "Building tray for Windows..." -ForegroundColor Cyan
$env:CGO_ENABLED = "1"
$env:GOOS = "windows"
$env:GOARCH = "amd64"
go build -ldflags $LDFLAGS -o mcpproxy-tray.exe ./cmd/mcpproxy-tray
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to build tray for Windows"
} else {
Write-Host "✓ Windows tray binary built successfully" -ForegroundColor Green
$BuiltBinaries += "mcpproxy-tray.exe"
}
if (!$OnlyCurrentPlatform) {
# Build tray for macOS (requires macOS host for proper CGO compilation)
Write-Host "Attempting to build tray for macOS..." -ForegroundColor Cyan
$env:CGO_ENABLED = "1"
$env:GOOS = "darwin"
$env:GOARCH = "amd64"
go build -ldflags $LDFLAGS -o mcpproxy-tray-darwin-amd64 ./cmd/mcpproxy-tray
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to build tray for macOS (cross-compilation from Windows requires proper CGO toolchain)"
} else {
Write-Host "✓ macOS tray binary built successfully" -ForegroundColor Green
$BuiltBinaries += "mcpproxy-tray-darwin-amd64"
}
# Build tray for macOS ARM64
Write-Host "Attempting to build tray for macOS ARM64..." -ForegroundColor Cyan
$env:CGO_ENABLED = "1"
$env:GOOS = "darwin"
$env:GOARCH = "arm64"
go build -ldflags $LDFLAGS -o mcpproxy-tray-darwin-arm64 ./cmd/mcpproxy-tray
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to build tray for macOS ARM64 (cross-compilation from Windows requires proper CGO toolchain)"
} else {
Write-Host "✓ macOS ARM64 tray binary built successfully" -ForegroundColor Green
$BuiltBinaries += "mcpproxy-tray-darwin-arm64"
}
} else {
Write-Host "Skipping cross-platform tray builds (OnlyCurrentPlatform flag is set)" -ForegroundColor Yellow
}
# Reset environment variables
Remove-Item Env:CGO_ENABLED -ErrorAction SilentlyContinue
Remove-Item Env:GOOS -ErrorAction SilentlyContinue
Remove-Item Env:GOARCH -ErrorAction SilentlyContinue
}
Write-Host ""
Write-Host "Build complete!" -ForegroundColor Green
Write-Host "Built binaries:" -ForegroundColor Green
# Display only the binaries built in this run
$BuiltFiles = @()
foreach ($binary in $BuiltBinaries) {
if (Test-Path $binary) {
$fileInfo = Get-Item $binary
$BuiltFiles += [PSCustomObject]@{
Name = $fileInfo.Name
'Size (MB)' = [math]::Round($fileInfo.Length / 1MB, 2)
LastWriteTime = $fileInfo.LastWriteTime
}
}
}
if ($BuiltFiles.Count -gt 0) {
$BuiltFiles | Format-Table -AutoSize
} else {
Write-Host " No binaries were built" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Test version info:" -ForegroundColor Cyan
& .\mcpproxy.exe --version