build_dist.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env sh
  2. #
  3. # Runs `go build` with flags configured for binary distribution. All
  4. # it does differently from `go build` is burn git commit and version
  5. # information into the binaries, so that we can track down user
  6. # issues.
  7. #
  8. # If you're packaging Tailscale for a distro, please consider using
  9. # this script, or executing equivalent commands in your
  10. # distro-specific build system.
  11. set -eu
  12. go="go"
  13. if [ -n "${TS_USE_TOOLCHAIN:-}" ]; then
  14. go="./tool/go"
  15. fi
  16. eval `CGO_ENABLED=0 GOOS=$($go env GOHOSTOS) GOARCH=$($go env GOHOSTARCH) $go run ./cmd/mkversion`
  17. if [ "$1" = "shellvars" ]; then
  18. cat <<EOF
  19. VERSION_MINOR="$VERSION_MINOR"
  20. VERSION_SHORT="$VERSION_SHORT"
  21. VERSION_LONG="$VERSION_LONG"
  22. VERSION_GIT_HASH="$VERSION_GIT_HASH"
  23. EOF
  24. exit 0
  25. fi
  26. tags=""
  27. ldflags="-X tailscale.com/version.longStamp=${VERSION_LONG} -X tailscale.com/version.shortStamp=${VERSION_SHORT}"
  28. # build_dist.sh arguments must precede go build arguments.
  29. while [ "$#" -gt 1 ]; do
  30. case "$1" in
  31. --extra-small)
  32. shift
  33. ldflags="$ldflags -w -s"
  34. tags="${tags:+$tags,}ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube"
  35. ;;
  36. --box)
  37. shift
  38. tags="${tags:+$tags,}ts_include_cli"
  39. ;;
  40. *)
  41. break
  42. ;;
  43. esac
  44. done
  45. exec $go build ${tags:+-tags=$tags} -ldflags "$ldflags" "$@"