#!/usr/bin/env bash set -euo pipefail # Build selected release artifacts from a Linux host or CI runner. The Docker # image contains Linux/Fyne dependencies for amd64 and arm64, plus the MinGW # cross-compiler used for the Windows GUI executable. Actual build commands live # here rather than in Dockerfile so target selection does not require rebuilding # the image. tag="gitea.mixdep.ru/mix/pysentry-builder" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" repo_root="$(cd "${script_dir}/.." && pwd)" cd "$repo_root" version="$(sed -n 's/^var Version = "\(.*\)"/\1/p' src/core/version.go)" version="${version:-0.0.0-dev}" usage() { cat <&2 usage >&2 exit 1 ;; esac done } run_in_builder() { docker run --rm \ -e "VERSION=${version}" \ -v "${repo_root}:/src" \ -w /src \ "$tag" \ bash -lc "$1" } build_linux_amd64() { run_in_builder 'mkdir -p dist/linux && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w -X github.com/pysentry/pysentry/src/core.Version=${VERSION}" -o "dist/linux/pysentry-${VERSION}-linux-amd64" ./cmd/pysentry' } build_linux_arm64() { run_in_builder 'mkdir -p dist/linux && CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CGO_CFLAGS="--sysroot=/ -I/usr/include/aarch64-linux-gnu" CGO_LDFLAGS="--sysroot=/ -L/usr/lib/aarch64-linux-gnu" PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig go build -trimpath -ldflags "-s -w -X github.com/pysentry/pysentry/src/core.Version=${VERSION}" -o "dist/linux/pysentry-${VERSION}-linux-arm64" ./cmd/pysentry' } build_windows_amd64() { run_in_builder 'mkdir -p dist/windows && x86_64-w64-mingw32-windres -O coff -o cmd/pysentry/rsrc_windows_amd64.syso packaging/windows/pysentry.rc && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w -H=windowsgui -X github.com/pysentry/pysentry/src/core.Version=${VERSION}" -o "dist/windows/pysentry-${VERSION}-windows-amd64.exe" ./cmd/pysentry' } mapfile -t targets < <(choose_targets "$@" | normalize_targets | awk '!seen[$0]++') if [ "${#targets[@]}" -eq 0 ]; then echo "No build targets selected." >&2 exit 1 fi echo "Building Docker builder image: $tag" docker build -f Dockerfile -t "$tag" . for target in "${targets[@]}"; do echo "Building $target..." case "$target" in linux-amd64) build_linux_amd64 ;; linux-arm64) build_linux_arm64 ;; windows-amd64) build_windows_amd64 ;; esac done echo "Built release artifacts:" find dist/linux dist/windows -maxdepth 1 -type f -print 2>/dev/null || true