build.sh 706 B

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