Files
yoyo/build.sh
titor 5b7475860a
Some checks failed
Release / build (push) Has been cancelled
fix: build.sh 添加 -buildvcs=false 避免VCS错误
2026-04-08 02:24:48 +08:00

94 lines
2.6 KiB
Bash
Executable File
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.
#!/bin/bash
set -e
cd "$(dirname "$0")"
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
show_help() {
echo "YOYO 编译脚本"
echo ""
echo "用法:"
echo " ./build.sh 构建当前平台,输出 yoyo"
echo " ./build.sh <平台> 交叉编译指定平台"
echo " ./build.sh -h 显示帮助"
echo ""
echo "参数:"
echo " -h 显示帮助信息"
echo " -o <文件名> 指定输出文件名"
echo ""
echo "支持的平台:"
echo " linux/amd64, linux/arm64"
echo " darwin/amd64, darwin/arm64"
echo " windows/amd64"
echo ""
echo "示例:"
echo " ./build.sh # 构建当前平台"
echo " ./build.sh linux/amd64 # 编译 Linux x64"
echo " ./build.sh darwin/arm64 # 编译 macOS ARM"
echo " ./build.sh windows/amd64 -o app.exe # 编译 Windows x64自定义输出名"
echo ""
echo "输出文件名格式: yoo-<os>-<arch>[.exe]"
echo " yoo-linux-amd64"
echo " yoo-darwin-arm64"
echo " yoo-windows-amd64.exe"
}
OUTPUT_NAME="yoyo"
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-o|--output)
OUTPUT_NAME="$2"
shift 2
;;
linux/amd64)
GOOS=linux GOARCH=amd64
PLATFORM="linux-amd64"
shift
;;
linux/arm64)
GOOS=linux GOARCH=arm64
PLATFORM="linux-arm64"
shift
;;
darwin/amd64)
GOOS=darwin GOARCH=amd64
PLATFORM="darwin-amd64"
shift
;;
darwin/arm64)
GOOS=darwin GOARCH=arm64
PLATFORM="darwin-arm64"
shift
;;
windows/amd64)
GOOS=windows GOARCH=amd64
PLATFORM="windows-amd64"
if [[ "$OUTPUT_NAME" == "yoyo" ]]; then
OUTPUT_NAME="yoo-windows-amd64.exe"
fi
shift
;;
*)
echo "未知平台: $1"
show_help
exit 1
;;
esac
done
echo "Building yoyo version: $VERSION"
if [ -n "$GOOS" ]; then
echo "Target: $PLATFORM"
go build -buildvcs=false -ldflags "-s -w -X github.com/titor/fanyi/internal/logo.version=${VERSION}" -o "$OUTPUT_NAME" ./cmd/yoyo
else
go build -buildvcs=false -ldflags "-s -w -X github.com/titor/fanyi/internal/logo.version=${VERSION}" -o "$OUTPUT_NAME" ./cmd/yoyo
fi
echo "Build complete: ./$OUTPUT_NAME"