chore: M0 项目骨架(年糕历险记)——配置/日志/主循环/数据文件/构建脚本
This commit is contained in:
40
scripts/build.ps1
Normal file
40
scripts/build.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
# 年糕历险记 构建脚本(Windows)
|
||||
# 用法:pwsh -File scripts/build.ps1 [-Release]
|
||||
# 自动准备便携 MinGW-w64(GLFW 需要 CGO),然后构建 client/server。
|
||||
param([switch]$Release)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$root = Split-Path $PSScriptRoot -Parent
|
||||
$tools = Join-Path $root "tools"
|
||||
$mingw = Join-Path $tools "mingw64"
|
||||
$gcc = Join-Path $mingw "bin\gcc.exe"
|
||||
|
||||
if (-not (Test-Path $gcc)) {
|
||||
Write-Host "== 未找到 C 编译器(GLFW 需要),下载便携 MinGW-w64 =="
|
||||
New-Item -ItemType Directory -Force -Path $tools | Out-Null
|
||||
$url = "https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-19.1.1-12.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-14.2.0-mingw-w64ucrt-12.0.0-r1.zip"
|
||||
$zip = Join-Path $env:TEMP "winlibs-mingw.zip"
|
||||
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing
|
||||
Expand-Archive -Path $zip -DestinationPath $tools -Force
|
||||
Remove-Item $zip -Force
|
||||
if (-not (Test-Path $gcc)) {
|
||||
throw "MinGW 准备失败:请手动安装 mingw-w64 并重试,或检查网络。"
|
||||
}
|
||||
}
|
||||
|
||||
$env:CC = $gcc
|
||||
$env:Path = "$(Join-Path $mingw 'bin');$env:Path"
|
||||
|
||||
$tags = ""
|
||||
$ldflags = "-s -w"
|
||||
if (-not $Release) { $tags = "-tags dev" }
|
||||
|
||||
Push-Location $root
|
||||
try {
|
||||
New-Item -ItemType Directory -Force -Path bin | Out-Null
|
||||
go build $tags -trimpath -ldflags $ldflags -o bin/mc-client.exe ./cmd/client
|
||||
go build $tags -trimpath -ldflags $ldflags -o bin/mc-server.exe ./cmd/server
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
Write-Host "== 构建完成:bin/mc-client.exe bin/mc-server.exe =="
|
||||
Reference in New Issue
Block a user