From 74d92d428d6d93eab1481ce59613639ed42d97ac Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Sun, 10 Apr 2016 08:32:54 +0000
Subject: [PATCH 2/2] Bug 20023: Upgrade Go to 1.7.3.

Go 1.7 has a necessary fix for macOS Sierra that is not in Go 1.6.3 or
earlier:
https://github.com/golang/go/commit/2da5633eb9091608047881953f75b489a3134cdc
meek was unstable on macOS Sierra when compiled with Go 1.4.3 or 1.6.3.
Reported by tordevSZ0: https://bugs.torproject.org/20250.

We need to use the Mac OS X 10.7 SDK (not 10.6) to build Go 1.7 and
later:
https://bugs.torproject.org/20023#comment:6

We add -std=gnu99 to CFLAGS when building Go. A piece of new C code uses
c99 features. Other code uses "asm", which requires gnu99.
https://bugs.torproject.org/20023#comment:6
https://trac.macports.org/ticket/52506

We hack one of the source files with sed to remove -D__MAC_OS_X_VERSION_MAX_ALLOWED=1060,
which otherwise causes the build to fail, thinking a couple of functions
are unavailable.
https://github.com/golang/go/issues/17732
---
 gitian/descriptors/mac/gitian-pluggable-transports.yml | 12 +++++++-----
 gitian/versions                                        |  4 ++--
 gitian/versions.alpha                                  |  4 ++--
 gitian/versions.beta                                   |  4 ++--
 gitian/versions.nightly                                |  4 ++--
 5 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/gitian/descriptors/mac/gitian-pluggable-transports.yml b/gitian/descriptors/mac/gitian-pluggable-transports.yml
index 33b134e..519a3ee 100644
--- a/gitian/descriptors/mac/gitian-pluggable-transports.yml
+++ b/gitian/descriptors/mac/gitian-pluggable-transports.yml
@@ -48,6 +48,7 @@ files:
 - "go14.tar.gz"
 - "go.tar.gz"
 - "apple-uni-sdk-10.6_20110407-0.flosoft1_i386.deb"
+- "MacOSX10.7.sdk.tar.gz"
 - "multiarch-darwin11-cctools127.2-gcc42-5666.3-llvmgcc42-2336.1-Linux-120724.tar.xz"
 - "dzip.sh"
 - "gmp-mac64-utils.zip"
@@ -82,6 +83,8 @@ script: |
   export PATH="/usr/sbin:/sbin:$PATH"
   sudo dpkg -i *.deb
   tar xaf multiarch-darwin*tar.xz
+  # The 10.7 SDK is needed for Go: https://bugs.torproject.org/20023#comment:6
+  tar xaf MacOSX10.7.sdk.tar.gz
   export PATH="$PATH:$HOME/build/apple-osx/bin/"
   if [ "z$INCLUDE_FTE" = "z1" ]; then
     unzip -d $INSTDIR gmp-mac64-utils.zip
@@ -99,10 +102,6 @@ script: |
   export CXX=$HOME/build/apple-osx/bin/i686-apple-darwin11-g++
   # http://bugs.python.org/issue9437
   export LDSHARED="$CC -pthread -shared"
-  # XXX Clean up these flags?
-  export CFLAGS="-m64 -I/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/include/ -I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I.  -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/ -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/system/ -F/usr/lib/apple/SDKs/MacOSX10.6.sdk/System/Library/Frameworks -mmacosx-version-min=10.5 -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/i686-apple-darwin10/4.2.1$FTE_EXTRA_CFLAGS"
-  export CXXFLAGS="-m64 -I/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/include/ -I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/ -I.  -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/ -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/system/ -F/usr/lib/apple/SDKs/MacOSX10.6.sdk/System/Library/Frameworks -mmacosx-version-min=10.5 -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/i686-apple-darwin10/4.2.1$FTE_EXTRA_CFLAGS"
-  export LDFLAGS="-L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/ -L/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib/system/ -F/usr/lib/apple/SDKs/MacOSX10.6.sdk/System/Library/Frameworks -mmacosx-version-min=10.5"
 
   # Building go 1.4.x
   # This is needed to bootstrap the go that we actually use
@@ -122,7 +121,7 @@ script: |
   # https://github.com/golang/go/issues/15457
   CC_FOR_TARGET="$(pwd)/cc-for-target"
   echo "#!/bin/sh" > "$CC_FOR_TARGET"
-  echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
+  echo "exec $CC $CFLAGS $LDFLAGS -isysroot $HOME/build/MacOSX10.7.sdk -std=gnu99 \"\$@\"" >> "$CC_FOR_TARGET"
   chmod +x "$CC_FOR_TARGET"
   # http://golang.org/doc/install/source#environment
   export GOPATH="$HOME/go"
@@ -130,6 +129,9 @@ script: |
   export GOARCH=386
   tar xvf go.tar.gz
   cd go/src
+  # Remove a preprocessor directive that causes problems when building with the 10.7 SDK.
+  # https://github.com/golang/go/issues/17732
+  sed -i -e '/^#cgo CFLAGS:/s/-D__MAC_OS_X_VERSION_MAX_ALLOWED=1060//' crypto/x509/root_cgo_darwin.go
   CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
   cd ../..
   export PATH="$PATH:$PWD/go/bin"
diff --git a/gitian/versions b/gitian/versions
index dfcd675..64da546 100755
--- a/gitian/versions
+++ b/gitian/versions
@@ -62,7 +62,7 @@ SETUPTOOLS_VER=1.4
 PARSLEY_VER=1.2
 # We need a Go 1.4 to bootstrap later versions; see https://golang.org/doc/install/source#go14
 GO14_VER=1.4.3
-GO_VER=1.6.3
+GO_VER=1.7.3
 NSIS_VER=2.51
 
 ## File names for the source packages
@@ -114,7 +114,7 @@ PY2EXE_HASH=610a8800de3d973ed5ed4ac505ab42ad058add18a68609ac09e6cf3598ef056c
 SETUPTOOLS_HASH=75d288687066ed124311d6ca5f40ffa92a0e81adcd7fff318c6e84082713cf39
 PARSLEY_HASH=50d30cee70770fd44db7cea421cb2fb75af247c3a1cd54885c06b30a7c85dd23
 GO14_HASH=9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
-GO_HASH=6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772345b00
+GO_HASH=79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895af1ef44
 NSIS_HASH=43d4c9209847e35eb6e2c7cd5a7586e1445374c056c2c7899e40a080e17a1be7
 NSIS_DEBIAN_HASH=1dee6957b4a4b8dfe69bcf28bc7f301a13b96b3fa5a394e36c8926ae781e774a
 GCC_HASH=b7dafdf89cbb0e20333dbf5b5349319ae06e3d1a30bf3515b5488f7e89dca5ad
diff --git a/gitian/versions.alpha b/gitian/versions.alpha
index e60e314..c5c6479 100755
--- a/gitian/versions.alpha
+++ b/gitian/versions.alpha
@@ -62,7 +62,7 @@ SETUPTOOLS_VER=1.4
 PARSLEY_VER=1.2
 # We need a Go 1.4 to bootstrap later versions; see https://golang.org/doc/install/source#go14
 GO14_VER=1.4.3
-GO_VER=1.6.3
+GO_VER=1.7.3
 NSIS_VER=2.51
 
 ## File names for the source packages
@@ -114,7 +114,7 @@ PY2EXE_HASH=610a8800de3d973ed5ed4ac505ab42ad058add18a68609ac09e6cf3598ef056c
 SETUPTOOLS_HASH=75d288687066ed124311d6ca5f40ffa92a0e81adcd7fff318c6e84082713cf39
 PARSLEY_HASH=50d30cee70770fd44db7cea421cb2fb75af247c3a1cd54885c06b30a7c85dd23
 GO14_HASH=9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
-GO_HASH=6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772345b00
+GO_HASH=79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895af1ef44
 NSIS_HASH=43d4c9209847e35eb6e2c7cd5a7586e1445374c056c2c7899e40a080e17a1be7
 NSIS_DEBIAN_HASH=1dee6957b4a4b8dfe69bcf28bc7f301a13b96b3fa5a394e36c8926ae781e774a
 GCC_HASH=b7dafdf89cbb0e20333dbf5b5349319ae06e3d1a30bf3515b5488f7e89dca5ad
diff --git a/gitian/versions.beta b/gitian/versions.beta
index c985e30..7f7b500 100755
--- a/gitian/versions.beta
+++ b/gitian/versions.beta
@@ -49,7 +49,7 @@ SETUPTOOLS_VER=1.4
 PARSLEY_VER=1.2
 # We need a Go 1.4 to bootstrap later versions; see https://golang.org/doc/install/source#go14
 GO14_VER=1.4.3
-GO_VER=1.6.3
+GO_VER=1.7.3
 
 ## File names for the source packages
 OPENSSL_PACKAGE=openssl-${OPENSSL_VER}.tar.gz
@@ -96,7 +96,7 @@ PY2EXE_HASH=610a8800de3d973ed5ed4ac505ab42ad058add18a68609ac09e6cf3598ef056c
 SETUPTOOLS_HASH=75d288687066ed124311d6ca5f40ffa92a0e81adcd7fff318c6e84082713cf39
 PARSLEY_HASH=50d30cee70770fd44db7cea421cb2fb75af247c3a1cd54885c06b30a7c85dd23
 GO14_HASH=9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
-GO_HASH=6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772345b00
+GO_HASH=79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895af1ef44
 STIXMATHFONT_HASH=e3b0f712e2644438eee2d0dcd2b10b2d54f1b972039de95b2f8e800bae1adbd8
 NOTOEMOJIFONT_HASH=415dc6290378574135b64c808dc640c1df7531973290c4970c51fdeb849cb0c5
 NOTOJPFONT_HASH=3e8146c4ce0945f255cb9dbc12b392380af80bd117e0a60eae555c99c7e618da
diff --git a/gitian/versions.nightly b/gitian/versions.nightly
index 0c489c9..5373b02 100755
--- a/gitian/versions.nightly
+++ b/gitian/versions.nightly
@@ -69,7 +69,7 @@ SETUPTOOLS_VER=1.4
 PARSLEY_VER=1.2
 # We need a Go 1.4 to bootstrap later versions; see https://golang.org/doc/install/source#go14
 GO14_VER=1.4.3
-GO_VER=1.6.3
+GO_VER=1.7.3
 NSIS_VER=2.51
 
 ## File names for the source packages
@@ -121,7 +121,7 @@ PY2EXE_HASH=610a8800de3d973ed5ed4ac505ab42ad058add18a68609ac09e6cf3598ef056c
 SETUPTOOLS_HASH=75d288687066ed124311d6ca5f40ffa92a0e81adcd7fff318c6e84082713cf39
 PARSLEY_HASH=50d30cee70770fd44db7cea421cb2fb75af247c3a1cd54885c06b30a7c85dd23
 GO14_HASH=9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
-GO_HASH=6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772345b00
+GO_HASH=79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895af1ef44
 NSIS_HASH=43d4c9209847e35eb6e2c7cd5a7586e1445374c056c2c7899e40a080e17a1be7
 NSIS_DEBIAN_HASH=1dee6957b4a4b8dfe69bcf28bc7f301a13b96b3fa5a394e36c8926ae781e774a
 GCC_HASH=b7dafdf89cbb0e20333dbf5b5349319ae06e3d1a30bf3515b5488f7e89dca5ad
-- 
2.9.3

