21 lines
803 B
PowerShell
21 lines
803 B
PowerShell
# 离线构建脚本:本机无法访问任何 Go 模块源,全部依赖取自本地模块缓存
|
||
$ErrorActionPreference = 'Stop'
|
||
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
$env:GOFLAGS = '-mod=mod'
|
||
$env:GOPROXY = 'off'
|
||
$env:GOSUMDB = 'off'
|
||
$env:GOCACHE = Join-Path $root '.gocache'
|
||
$env:GOTMPDIR = Join-Path $root '.gotmp'
|
||
New-Item -ItemType Directory -Force -Path $env:GOCACHE, $env:GOTMPDIR | Out-Null
|
||
|
||
Push-Location $root
|
||
try {
|
||
Write-Host '正在编译…' -ForegroundColor Cyan
|
||
go build -trimpath -ldflags '-s -w' -o daili.exe .
|
||
if ($LASTEXITCODE -ne 0) { throw "编译失败(退出码 $LASTEXITCODE)" }
|
||
$f = Get-Item daili.exe
|
||
Write-Host ("编译完成: {0} {1:N1} MB" -f $f.Name, ($f.Length / 1MB)) -ForegroundColor Green
|
||
} finally {
|
||
Pop-Location
|
||
}
|