代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
set -e
# Environment variable options:
# - PLATFORMS: Platforms to build for (e.g. "windows/amd64,linux/amd64,darwin/amd64")
export CLI_VERSION=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD)
export LC_ALL=C
export LC_DATE=C
make_ldflags() {
local ldflags="-s -w -X 'github.com/yomorun/yomo/cli.Version=$CLI_VERSION'"
echo "$ldflags"
}
build_for_platform() {
local platform="$1"
local ldflags="$2"
local GOOS="${platform%/*}"
local GOARCH="${platform#*/}"
if [[ -z "$GOOS" || -z "$GOARCH" ]]; then
echo "Invalid platform $platform" >&2
return 1
fi
echo "Building $GOOS/$GOARCH"
local output="yomo"
if [[ "$GOOS" = "windows" ]]; then
output="$output.exe"
fi
# compress to .tar.gz file
local binfile="build/yomo-$GOARCH-$GOOS.tar.gz"
local exit_val=0
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -o "build/$output" -ldflags "$ldflags" -trimpath ./cmd/yomo/main.go || exit_val=$?
# compress compiled binary to .zip
# zip -r -j "$binfile" "$output"
tar -C build -czvf "$binfile" "$output"
rm -rf $output
if [[ "$exit_val" -ne 0 ]]; then
echo "Error: failed to build $GOOS/$GOARCH" >&2
return $exit_val
fi
}
if [ -z "$PLATFORMS" ]; then
PLATFORMS="$(go env GOOS)/$(go env GOARCH)"
fi
platforms=(${PLATFORMS//,/ })
ldflags="$(make_ldflags)"
mkdir -p build
rm -rf build/*
echo "Starting build..."
for platform in "${platforms[@]}"; do
build_for_platform "$platform" "$ldflags"
done
echo "Build complete."
ls -lh build/ | awk '{print $9, $5}'
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。