Files
mfd-monitor-agent/scripts/build-windows.ps1
codex 877e4cf41d docs(agent): 统一中文注释并补充部署文档
将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、
示例配置,并完善构建脚本对 VERSION 注入的说明。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 02:30:49 +00:00

33 lines
1.3 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 构建 mfd-monitor-agent 单二进制产物(Windows 目标)。
#
# 环境变量:
# OUT_DIR 输出目录,默认 <仓库根>\dist
# VERSION 写入二进制的版本号,默认 0.1.0(通过 -ldflags -X main.version)
# GOOS_TARGET 目标 GOOS,默认 windows
# GOARCH_TARGET 目标 GOARCH,默认 amd64
# OUTPUT_NAME 输出文件名,默认 agent-<GOOS>-<GOARCH>.exe
# CGO_ENABLED 是否启用 CGO,默认 0
#
$ErrorActionPreference = "Stop"
$RootDir = Resolve-Path (Join-Path $PSScriptRoot "..")
$OutDir = if ($env:OUT_DIR) { $env:OUT_DIR } else { Join-Path $RootDir "dist" }
$Version = if ($env:VERSION) { $env:VERSION } else { "0.1.0" }
$GoosTarget = if ($env:GOOS_TARGET) { $env:GOOS_TARGET } else { "windows" }
$GoarchTarget = if ($env:GOARCH_TARGET) { $env:GOARCH_TARGET } else { "amd64" }
$OutputName = if ($env:OUTPUT_NAME) { $env:OUTPUT_NAME } else { "agent-$GoosTarget-$GoarchTarget.exe" }
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
$env:CGO_ENABLED = if ($env:CGO_ENABLED) { $env:CGO_ENABLED } else { "0" }
$env:GOOS = $GoosTarget
$env:GOARCH = $GoarchTarget
go build `
-trimpath `
-ldflags "-s -w -X main.version=$Version" `
-o (Join-Path $OutDir $OutputName) `
./cmd/agent
Write-Host "built $(Join-Path $OutDir $OutputName)"