Skip to content

Commit ed9a7cc

Browse files
committed
added a quick windows build script
1 parent c56e9c6 commit ed9a7cc

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

build.ps1

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Terminal Intelligence Build Script for Windows
2+
param(
3+
[string]$Target = "build"
4+
)
5+
6+
$BINARY_NAME = "ti"
7+
$VERSION = "0.1.0"
8+
$BUILD_DIR = "build"
9+
10+
# Get build number from git
11+
try {
12+
$gitCount = git rev-list --count HEAD 2>$null
13+
if ($LASTEXITCODE -eq 0) {
14+
$BUILD_NUMBER = [int]$gitCount + 1
15+
} else {
16+
$BUILD_NUMBER = 1
17+
}
18+
} catch {
19+
$BUILD_NUMBER = 1
20+
}
21+
22+
$LDFLAGS = "-s -w -X main.version=$VERSION -X main.buildNumber=$BUILD_NUMBER"
23+
24+
function Build-Current {
25+
Write-Host "Building $BINARY_NAME for current platform..." -ForegroundColor Cyan
26+
if (!(Test-Path $BUILD_DIR)) {
27+
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
28+
}
29+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME.exe" .
30+
if ($LASTEXITCODE -eq 0) {
31+
Write-Host "Build complete: $BUILD_DIR/$BINARY_NAME.exe" -ForegroundColor Green
32+
} else {
33+
Write-Host "Build failed!" -ForegroundColor Red
34+
exit 1
35+
}
36+
}
37+
38+
function Build-Windows {
39+
Write-Host "Building $BINARY_NAME for Windows..." -ForegroundColor Cyan
40+
if (!(Test-Path $BUILD_DIR)) {
41+
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
42+
}
43+
$env:GOOS = "windows"
44+
$env:GOARCH = "amd64"
45+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME-windows-amd64.exe" .
46+
Write-Host "Build complete: $BUILD_DIR/$BINARY_NAME-windows-amd64.exe" -ForegroundColor Green
47+
}
48+
49+
function Build-Linux {
50+
Write-Host "Building $BINARY_NAME for Linux..." -ForegroundColor Cyan
51+
if (!(Test-Path $BUILD_DIR)) {
52+
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
53+
}
54+
$env:GOOS = "linux"
55+
$env:GOARCH = "amd64"
56+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME-linux-amd64" .
57+
$env:GOARCH = "arm64"
58+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME-linux-aarch64" .
59+
Write-Host "Build complete: $BUILD_DIR/$BINARY_NAME-linux-amd64 and $BUILD_DIR/$BINARY_NAME-linux-aarch64" -ForegroundColor Green
60+
}
61+
62+
function Build-Darwin {
63+
Write-Host "Building $BINARY_NAME for macOS..." -ForegroundColor Cyan
64+
if (!(Test-Path $BUILD_DIR)) {
65+
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
66+
}
67+
$env:GOOS = "darwin"
68+
$env:GOARCH = "amd64"
69+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME-darwin-amd64" .
70+
$env:GOARCH = "arm64"
71+
go build -ldflags="$LDFLAGS" -o "$BUILD_DIR/$BINARY_NAME-darwin-arm64" .
72+
Write-Host "Build complete: $BUILD_DIR/$BINARY_NAME-darwin-amd64 and $BUILD_DIR/$BINARY_NAME-darwin-arm64" -ForegroundColor Green
73+
}
74+
75+
function Build-All {
76+
Build-Windows
77+
Build-Linux
78+
Build-Darwin
79+
Write-Host "All platform builds complete!" -ForegroundColor Green
80+
}
81+
82+
function Run-Tests {
83+
Write-Host "Running tests..." -ForegroundColor Cyan
84+
go test ./... -v
85+
}
86+
87+
function Run-Clean {
88+
Write-Host "Cleaning build artifacts..." -ForegroundColor Cyan
89+
if (Test-Path $BUILD_DIR) {
90+
Remove-Item -Recurse -Force $BUILD_DIR
91+
}
92+
if (Test-Path "coverage.out") {
93+
Remove-Item "coverage.out"
94+
}
95+
if (Test-Path "coverage.html") {
96+
Remove-Item "coverage.html"
97+
}
98+
Write-Host "Clean complete" -ForegroundColor Green
99+
}
100+
101+
function Show-Help {
102+
Write-Host "Terminal Intelligence (TI) Build Script" -ForegroundColor Cyan
103+
Write-Host ""
104+
Write-Host "Usage: .\build.ps1 [target]" -ForegroundColor Yellow
105+
Write-Host ""
106+
Write-Host "Targets:" -ForegroundColor Yellow
107+
Write-Host " build - Build for current platform (default)"
108+
Write-Host " windows - Build for Windows (amd64)"
109+
Write-Host " linux - Build for Linux (amd64 and arm64)"
110+
Write-Host " darwin - Build for macOS (amd64 and arm64)"
111+
Write-Host " all - Build for all platforms"
112+
Write-Host " test - Run all tests"
113+
Write-Host " clean - Remove build artifacts"
114+
Write-Host " help - Show this help message"
115+
}
116+
117+
# Execute target
118+
switch ($Target.ToLower()) {
119+
"build" { Build-Current }
120+
"windows" { Build-Windows }
121+
"linux" { Build-Linux }
122+
"darwin" { Build-Darwin }
123+
"all" { Build-All }
124+
"test" { Run-Tests }
125+
"clean" { Run-Clean }
126+
"help" { Show-Help }
127+
default {
128+
Write-Host "Unknown target: $Target" -ForegroundColor Red
129+
Show-Help
130+
exit 1
131+
}
132+
}

0 commit comments

Comments
 (0)