forked from ratel-online/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
63 lines (48 loc) · 1.66 KB
/
Copy pathbuild.ps1
File metadata and controls
63 lines (48 loc) · 1.66 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
# ==============================
# Go Multi-platform Build Script
# ==============================
$projectName = "ratel-server"
$mainFile = "main.go"
$targetDir = "target"
# Create output directory
if (!(Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir | Out-Null
Write-Host "Created directory: $targetDir" -ForegroundColor DarkGray
}
# 目标平台列表
$platforms = @(
@{ os = "windows"; arch = "amd64" },
@{ os = "windows"; arch = "386" },
@{ os = "windows"; arch = "arm64" },
@{ os = "linux"; arch = "amd64" },
@{ os = "linux"; arch = "386" },
@{ os = "linux"; arch = "arm64" },
@{ os = "linux"; arch = "arm" },
@{ os = "darwin"; arch = "amd64" },
@{ os = "darwin"; arch = "arm64" }
)
Write-Host "`nStarting Go multi-platform build: $projectName`n" -ForegroundColor Cyan
foreach ($p in $platforms) {
$goos = $p.os
$goarch = $p.arch
$ext = if ($goos -eq "windows") { ".exe" } else { "" }
$outputName = "$projectName-$goos-$goarch$ext"
$outputPath = Join-Path $targetDir $outputName
Write-Host "> Building $goos/$goarch ..." -NoNewline
# Environment variables
$env:GOOS = $goos
$env:GOARCH = $goarch
$env:CGO_ENABLED = "0"
go build -trimpath -ldflags "-s -w" `
-o $outputPath $mainFile 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host " Success -> $outputName" -ForegroundColor Green
} else {
Write-Host " Failed" -ForegroundColor Red
}
}
# 清理环境变量
$env:GOOS = ""
$env:GOARCH = ""
$env:CGO_ENABLED = ""
Write-Host "`nAll platforms build completed. Output directory: $targetDir" -ForegroundColor Yellow