build.sh 650 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. go build \
  11. -o $artifact \
  12. -buildmode pie \
  13. -ldflags "\
  14. -w -s \
  15. -X main.Version=$(git describe --tags | head -1) \
  16. -X main.Build=$(date --utc --iso-8601=s)"
  17. sha256sum ./$artifact > $artifact.sha256sum
  18. }
  19. function main() {
  20. local -r targets="linux amd64
  21. linux arm64
  22. darwin amd64
  23. darwin arm64
  24. windows amd64"
  25. local -a target
  26. while read line
  27. do
  28. read -a target <<< $line
  29. build ${target[0]} ${target[1]}
  30. done < <(echo "$targets")
  31. }
  32. main $@