build.sh 684 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #/bin/bash
  2. set -euo pipefail
  3. function build() {
  4. export GOOS=$1
  5. export GOARCH=$2
  6. local artifact=dump2sql-$GOOS-$GOARCH
  7. if [ $GOOS == windows ]
  8. then artifact=$artifact.exe
  9. fi
  10. echo "Building $artifact..."
  11. go build \
  12. -o $artifact \
  13. -buildmode pie \
  14. -ldflags "\
  15. -w -s \
  16. -X main.Version=$(git describe --tags | head -1) \
  17. -X main.Build=$(date -u --iso-8601=seconds)"
  18. sha256sum ./$artifact > $artifact.sha256sum
  19. }
  20. function main() {
  21. local -r targets="linux amd64
  22. linux arm64
  23. darwin amd64
  24. darwin arm64
  25. windows amd64"
  26. local -a target
  27. while read line
  28. do
  29. read -a target <<< $line
  30. build ${target[0]} ${target[1]}
  31. done < <(echo "$targets")
  32. }
  33. main $@