添加打包脚本

This commit is contained in:
JACKYMYPERSON
2025-09-27 18:24:55 +08:00
parent 653a067737
commit beff323e57
3 changed files with 43 additions and 0 deletions

43
package.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# 设置目标文件夹和项目名称
target_dir="./opt/ttk"
project_name="ttk"
# 创建目标文件夹(若不存在)
mkdir -p "$target_dir"
# 定义目标平台列表格式GOOS/GOARCH
platforms=(
"linux/amd64" # Linux 64位
"darwin/amd64" # MacIntel芯片64位
# 如需支持Mac Apple Silicon可添加darwin/arm64
)
# 遍历每个平台进行打包
for platform in "${platforms[@]}"; do
# 解析平台信息
IFS='/' read -r goos goarch <<< "$platform"
# 设置平台相关的环境变量
export CGO_ENABLED=0 # 禁用CGO确保纯静态编译跨平台兼容
export GOOS="$goos"
export GOARCH="$goarch"
# 生成输出文件名Mac需加.dmg后缀Linux用可执行文件
if [ "$goos" = "darwin" ]; then
output_file="${project_name}-${goos}-${goarch}.dmg"
else
output_file="${project_name}-${goos}-${goarch}"
fi
# 执行打包命令
echo "正在打包 $platform 平台..."
env GOOS="$goos" GOARCH="$goarch" CGO_ENABLED=0 go build -o "$target_dir/$output_file" .
# 检查打包结果
if [ $? -eq 0 ]; then
echo "$platform 平台打包成功,文件路径:$target_dir/$output_file"
else
echo "$platform 平台打包失败"
fi
done