mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
build(release): use native golang toolchain for official release builds (#37828)
Official releases are built by Golang toolchain with CGO disabled. For packagers who need to cross-compile with CGO, use "build" target with proper TAGS/LDFLAGS/CGO_CFLAGS to make "$(EXECUTABLE)" target run the "go build" command. By the way, drop i386 arch support --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
GO="${GO:-go}"
|
||||
RELEASE_LDFLAGS="-s -w $LDFLAGS"
|
||||
RELEASE_TAGS="bindata $TAGS"
|
||||
RELEASE_PATH_PREFIX="${DIST}/binaries/gitea-${VERSION##*/}"
|
||||
|
||||
RELEASE_PLATFORMS_DEFAULT=(
|
||||
linux/amd64 linux/arm-5 linux/arm-6 linux/arm64 linux/riscv64 \
|
||||
windows/amd64 windows/arm64 \
|
||||
darwin/amd64 darwin/arm64 \
|
||||
freebsd/amd64
|
||||
)
|
||||
|
||||
RELEASE_PLATFORMS_GOGIT=(windows/amd64 windows/arm64)
|
||||
|
||||
build() {
|
||||
echo "building ${*} ..."
|
||||
local target="${1:?}"
|
||||
local variant="${2:-}"
|
||||
|
||||
local goos="${target%%/*}"
|
||||
local goarch="${target##*/}"
|
||||
local goarm=""
|
||||
if [[ "$goarch" == arm-* ]]; then
|
||||
goarm="${goarch#arm-}"
|
||||
goarch="arm"
|
||||
fi
|
||||
|
||||
local tags="${RELEASE_TAGS}"
|
||||
local suffix
|
||||
if [[ "$variant" == "gogit" ]]; then
|
||||
tags="gogit${tags:+ ${tags}}"
|
||||
suffix="-gogit-${target//\//-}"
|
||||
else
|
||||
suffix="-${target//\//-}"
|
||||
fi
|
||||
|
||||
local output="${RELEASE_PATH_PREFIX}${suffix}"
|
||||
local args=()
|
||||
if [[ "$goos" == "windows" ]]; then
|
||||
output="${output}.exe"
|
||||
fi
|
||||
args+=(-tags "$tags")
|
||||
args+=(-ldflags "$RELEASE_LDFLAGS")
|
||||
echo " args: ${args[*]}"
|
||||
echo " output: ${output}"
|
||||
# must disable CGO (host compiler & linker) to get host-independent static builds
|
||||
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" GOARM="$goarm" "$GO" build "${args[@]}" -o "$output" .
|
||||
}
|
||||
|
||||
main() {
|
||||
# When building release binaries, some TAGS (bindata) are needed by the release script,
|
||||
# so here it needs to use the TAGS to generate the assets (embed bindata).
|
||||
echo "generating assets with tags=${RELEASE_TAGS}"
|
||||
"$GO" generate -tags "${RELEASE_TAGS}" ./...
|
||||
local platform="${1:-}"
|
||||
for target in "${RELEASE_PLATFORMS_DEFAULT[@]}"; do
|
||||
if [[ -z "$platform" || "$target" == "$platform/"* ]]; then
|
||||
build "$target"
|
||||
fi
|
||||
done
|
||||
|
||||
for target in "${RELEASE_PLATFORMS_GOGIT[@]}"; do
|
||||
if [[ -z "$platform" || "$target" == "$platform/"* ]]; then
|
||||
build "$target" "gogit"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user