-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·39 lines (27 loc) · 953 Bytes
/
Copy pathbuild.sh
File metadata and controls
executable file
·39 lines (27 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# 删除dist
rm -rf ./dist
# 创建dist目录
mkdir -p dist
# 定义平台数组
platforms=("darwin/amd64" "darwin/arm64" "linux/386" "linux/arm" "linux/amd64" "linux/arm64" "windows/386" "windows/arm" "windows/amd64" "windows/arm64")
# 循环编译并重命名可执行文件
for platform in "${platforms[@]}"
do
# 分割平台字符串
IFS='/' read -r -a platform_info <<< "$platform"
# 构建平台
GOOS=${platform_info[0]} GOARCH=${platform_info[1]}
# 构建可执行文件名
output_name="live-server-${GOOS}_${GOARCH}"
# Windows平台特殊处理,添加.exe后缀
if [ "$GOOS" == "windows" ]; then
output_name="$output_name.exe"
fi
# 编译
CGO_ENABLED=0 GOOS=${platform_info[0]} GOARCH=${platform_info[1]} go build -o "dist/$output_name" .
# 赋予可执行权限
chmod +x "dist/$output_name"
echo "Built $output_name"
done
echo "Build process completed!"