44 lines
1.7 KiB
PowerShell
44 lines
1.7 KiB
PowerShell
# 年糕历险记 构建脚本(Windows)
|
||
# 用法:pwsh -File scripts/build.ps1 [-Release]
|
||
# 自动定位 C 工具链(tools/ 下的 zig 或 mingw64/w64devkit),构建 GL 客户端与服务器。
|
||
param([switch]$Release)
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
$root = Split-Path $PSScriptRoot -Parent
|
||
$tools = Join-Path $root "tools"
|
||
|
||
# 定位 C 编译器(GLFW 需要 CGO):优先 zig(zig cc),其次 mingw64/w64devkit 的 gcc
|
||
$cc = $null
|
||
$zig = Get-ChildItem $tools -Recurse -Filter zig.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||
if ($zig) {
|
||
$cc = "$($zig.FullName) cc"
|
||
Write-Host "== 使用 zig 作为 C 编译器: $($zig.FullName) =="
|
||
} else {
|
||
$gcc = Get-ChildItem $tools -Recurse -Filter gcc.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||
if ($gcc) {
|
||
$cc = $gcc.FullName
|
||
$env:Path = "$(Split-Path $gcc.FullName);$env:Path"
|
||
Write-Host "== 使用 gcc: $($gcc.FullName) =="
|
||
} else {
|
||
Write-Host "== 未找到 C 工具链:请把 zig(或 MinGW)放到 tools/ 后重试。"
|
||
Write-Host " 下载:https://ziglang.org/download/(zig-x86_64-windows-*.zip)"
|
||
Write-Host " 或: https://github.com/brechtsanders/winlibs_mingw/releases(winlibs zip)"
|
||
exit 1
|
||
}
|
||
}
|
||
$env:CC = $cc
|
||
$env:CGO_ENABLED = "1"
|
||
|
||
$tags = "gl"
|
||
if (-not $Release) { $tags = "$tags dev" }
|
||
|
||
Push-Location $root
|
||
try {
|
||
New-Item -ItemType Directory -Force -Path bin | Out-Null
|
||
go build -tags $tags -trimpath -ldflags "-s -w" -o bin/mc-client.exe ./cmd/client
|
||
go build -trimpath -ldflags "-s -w" -o bin/mc-server.exe ./cmd/server
|
||
} finally {
|
||
Pop-Location
|
||
}
|
||
Write-Host "== 构建完成:bin/mc-client.exe bin/mc-server.exe =="
|