setup_go_for_macos1013.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. VERSION="1.25.9"
  4. PATCH_COMMITS=(
  5. "afe69d3cec1c6dcf0f1797b20546795730850070"
  6. "1ed289b0cf87dc5aae9c6fe1aa5f200a83412938"
  7. )
  8. CURL_ARGS=(
  9. -fL
  10. --silent
  11. --show-error
  12. )
  13. if [[ -n "${GITHUB_TOKEN:-}" ]]; then
  14. CURL_ARGS+=(-H "Authorization: Bearer ${GITHUB_TOKEN}")
  15. fi
  16. mkdir -p "$HOME/go"
  17. cd "$HOME/go"
  18. wget "https://dl.google.com/go/go${VERSION}.darwin-arm64.tar.gz"
  19. tar -xzf "go${VERSION}.darwin-arm64.tar.gz"
  20. #cp -a go go_bootstrap
  21. mv go go_osx
  22. cd go_osx
  23. # these patch URLs only work on golang1.25.x
  24. # that means after golang1.26 release it must be changed
  25. # see: https://github.com/SagerNet/go/commits/release-branch.go1.25/
  26. # revert:
  27. # 33d3f603c1: "cmd/link/internal/ld: use 12.0.0 OS/SDK versions for macOS linking"
  28. # 937368f84e: "crypto/x509: change how we retrieve chains on darwin"
  29. for patch_commit in "${PATCH_COMMITS[@]}"; do
  30. curl "${CURL_ARGS[@]}" "https://github.com/SagerNet/go/commit/${patch_commit}.diff" | patch --verbose -p 1
  31. done
  32. # Rebuild is not needed: we build with CGO_ENABLED=1, so Apple's external
  33. # linker handles LC_BUILD_VERSION via MACOSX_DEPLOYMENT_TARGET, and the
  34. # stdlib (crypto/x509) is compiled from patched src automatically.
  35. #cd src
  36. #GOROOT_BOOTSTRAP="$HOME/go/go_bootstrap" ./make.bash
  37. #cd ../..
  38. #rm -rf go_bootstrap "go${VERSION}.darwin-arm64.tar.gz"