build_dist.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 [ "$#" -ge 1 ] && [ "$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="${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. if [ ! -z "${TAGS:-}" ]; then
  33. echo "set either --extra-small or \$TAGS, but not both"
  34. exit 1
  35. fi
  36. shift
  37. ldflags="$ldflags -w -s"
  38. tags="${tags:+$tags,},$(GOOS= GOARCH= $go run ./cmd/featuretags --min --add=osrouter)"
  39. ;;
  40. --min)
  41. # --min is like --extra-small but even smaller, removing all features,
  42. # even if it results in a useless binary (e.g. removing both netstack +
  43. # osrouter). It exists for benchmarking purposes only.
  44. shift
  45. ldflags="$ldflags -w -s"
  46. tags="${tags:+$tags,},$(GOOS= GOARCH= $go run ./cmd/featuretags --min)"
  47. ;;
  48. --box)
  49. if [ ! -z "${TAGS:-}" ]; then
  50. echo "set either --box or \$TAGS, but not both"
  51. exit 1
  52. fi
  53. shift
  54. tags="${tags:+$tags,}ts_include_cli"
  55. ;;
  56. *)
  57. break
  58. ;;
  59. esac
  60. done
  61. exec $go build ${tags:+-tags=$tags} -trimpath -ldflags "$ldflags" "$@"