git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #18546 from LnL7/darwin-go-1.7

go: fix darwin build

commit5ea6d5fa726ec6a443310afc6167e05789eaae66 authorDaiderd Jordan <daiderd@gmail.com> dateWed 14 Sep 2016, 21:07 (10 years ago) parent4d25b23db7adbf
2 files changed+115−43
pkgs/development/compilers/go/1.7.nix+33−43 pkgs/development/compilers/go/cacert-1.7.patch+82
pkgs/development/compilers/go/1.7.nix+33−43
@@ -1,9 +1,17 @@
1−{ stdenv, lib, fetchFromGitHub, tzdata, iana_etc, go_bootstrap, runCommand
1+{ stdenv, fetchFromGitHub, tzdata, iana_etc, go_bootstrap, runCommand, writeScriptBin
22, perl, which, pkgconfig, patch, fetchpatch
3−, pcre
3+, pcre, cacert
44, Security, Foundation, bash }:
55
66let
7+
8+ inherit (stdenv.lib) optional optionals optionalString;
9+
10+ clangHack = writeScriptBin "clang" ''
11+ #!${stdenv.shell}
12+ exec ${stdenv.cc}/bin/clang "$@" 2> >(sed '/ld: warning:.*ignoring unexpected dylib file/ d' 1>&2)
13+ '';
14+
715 goBootstrap = runCommand "go-bootstrap" {} ''
816 mkdir $out
917 cp -rf ${go_bootstrap}/* $out/
@@ -11,6 +19,7 @@ let
1119 find $out -name "*.c" -delete
1220 cp -rf $out/bin/* $out/share/go/bin/
1321 '';
22+
1423in
1524
1625stdenv.mkDerivation rec {
@@ -27,28 +36,11 @@ stdenv.mkDerivation rec {
2736 # perl is used for testing go vet
2837 nativeBuildInputs = [ perl which pkgconfig patch ];
2938 buildInputs = [ pcre ];
30− propagatedBuildInputs = lib.optionals stdenv.isDarwin [
31− Security Foundation
32− ];
39+ propagatedBuildInputs = optionals stdenv.isDarwin [ Security Foundation ];
3340
3441 hardeningDisable = [ "all" ];
3542
36− # I'm not sure what go wants from its 'src', but the go installation manual
37− # describes an installation keeping the src.
38− preUnpack = ''
39− topdir=$PWD
40− mkdir -p $out/share
41− cd $out/share
42− '';
43−
4443 prePatch = ''
45− # Ensure that the source directory is named go
46− cd ..
47− if [ ! -d go ]; then
48− mv * go
49− fi
50−
51− cd go
5244 patchShebangs ./ # replace /bin/bash
5345
5446 # This source produces shell script at run time,
@@ -81,9 +73,9 @@ stdenv.mkDerivation rec {
8173 # Disable cgo lookup tests not works, they depend on resolver
8274 rm src/net/cgo_unix_test.go
8375
84− '' + lib.optionalString stdenv.isLinux ''
76+ '' + optionalString stdenv.isLinux ''
8577 sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
86− '' + lib.optionalString stdenv.isDarwin ''
78+ '' + optionalString stdenv.isDarwin ''
8779 substituteInPlace src/race.bash --replace \
8880 "sysctl machdep.cpu.extfeatures | grep -qv EM64T" true
8981 sed -i 's,strings.Contains(.*sysctl.*,true {,' src/cmd/dist/util.go
@@ -93,6 +85,7 @@ stdenv.mkDerivation rec {
9385 sed -i '/TestChdirAndGetwd/areturn' src/os/os_test.go
9486 sed -i '/TestRead0/areturn' src/os/os_test.go
9587 sed -i '/TestNohup/areturn' src/os/signal/signal_test.go
88+ sed -i '/TestCurrent/areturn' src/os/user/user_test.go
9689 sed -i '/TestSystemRoots/areturn' src/crypto/x509/root_darwin_test.go
9790
9891 sed -i '/TestGoInstallRebuildsStalePackagesInOtherGOPATH/areturn' src/cmd/go/go_test.go
@@ -106,20 +99,11 @@ stdenv.mkDerivation rec {
10699 touch $TMPDIR/group $TMPDIR/hosts $TMPDIR/passwd
107100
108101 sed -i '1 a\exit 0' misc/cgo/errors/test.bash
109−
110− mkdir $topdir/dirtyhacks
111− cat <<EOF > $topdir/dirtyhacks/clang
112− #!${bash}/bin/bash
113− $(type -P clang) "\$@" 2> >(sed '/ld: warning:.*ignoring unexpected dylib file/ d' 1>&2)
114− exit $?
115− EOF
116− chmod +x $topdir/dirtyhacks/clang
117− PATH=$topdir/dirtyhacks:$PATH
118102 '';
119103
120− patches = [
121− ./remove-tools-1.7.patch
122− ];
104+ patches = [ ./remove-tools-1.7.patch ./cacert-1.7.patch ];
105+
106+ SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
123107
124108 GOOS = if stdenv.isDarwin then "darwin" else "linux";
125109 GOARCH = if stdenv.isDarwin then "amd64"
@@ -127,7 +111,7 @@ stdenv.mkDerivation rec {
127111 else if stdenv.system == "x86_64-linux" then "amd64"
128112 else if stdenv.isArm then "arm"
129113 else throw "Unsupported system";
130− GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
114+ GOARM = optionalString (stdenv.system == "armv5tel-linux") "5";
131115 GO386 = 387; # from Arch: don't assume sse2 on i686
132116 CGO_ENABLED = 1;
133117 GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
@@ -136,19 +120,25 @@ stdenv.mkDerivation rec {
136120 # just want the generic `cc` here.
137121 CC = if stdenv.isDarwin then "clang" else "cc";
138122
123+ configurePhase = ''
124+ mkdir -p $out/share/go/bin
125+ export GOROOT=$out/share/go
126+ export GOBIN=$GOROOT/bin
127+ export PATH=$GOBIN:$PATH
128+ '';
129+
130+ postConfigure = optionalString stdenv.isDarwin ''
131+ export PATH=${clangHack}/bin:$PATH
132+ '';
133+
139134 installPhase = ''
140− mkdir -p "$out/bin"
141− export GOROOT="$(pwd)/"
142− export GOBIN="$out/bin"
143− export PATH="$GOBIN:$PATH"
144− cd ./src
145− echo Building
146− ./all.bash
135+ cp -r . $GOROOT
136+ ( cd $GOROOT/src && ./all.bash )
147137 '';
148138
149139 preFixup = ''
150140 rm -r $out/share/go/pkg/bootstrap
151− rmdir $out/bin && mv $out/share/go/bin $out/bin
141+ mv $out/share/go/bin $out/bin
152142 '';
153143
154144 setupHook = ./setup-hook.sh;
pkgs/development/compilers/go/cacert-1.7.patchnew file+82
@@ -0,0 +1,82 @@
1+diff --git a/src/crypto/x509/root_cgo_darwin.go b/src/crypto/x509/root_cgo_darwin.go
2+index a4b33c7..9700b75 100644
3+--- a/src/crypto/x509/root_cgo_darwin.go
4++++ b/src/crypto/x509/root_cgo_darwin.go
5+@@ -151,11 +151,20 @@ int FetchPEMRoots(CFDataRef *pemRoots) {
6+ import "C"
7+ import (
8+ "errors"
9++ "io/ioutil"
10++ "os"
11+ "unsafe"
12+ )
13+
14+ func loadSystemRoots() (*CertPool, error) {
15+ roots := NewCertPool()
16++ if file := os.Getenv("SSL_CERT_FILE"); file != "" {
17++ data, err := ioutil.ReadFile(file)
18++ if err == nil {
19++ roots.AppendCertsFromPEM(data)
20++ return roots, nil
21++ }
22++ }
23+
24+ var data C.CFDataRef = nil
25+ err := C.FetchPEMRoots(&data)
26+diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
27+index 78de56c..05eada4 100644
28+--- a/src/crypto/x509/root_darwin.go
29++++ b/src/crypto/x509/root_darwin.go
30+@@ -6,20 +6,31 @@
31+
32+ package x509
33+
34+-import "os/exec"
35++import (
36++ "io/ioutil"
37++ "os"
38++ "os/exec"
39++)
40+
41+ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
42+ return nil, nil
43+ }
44+
45+ func execSecurityRoots() (*CertPool, error) {
46++ roots := NewCertPool()
47++ if file := os.Getenv("SSL_CERT_FILE"); file != "" {
48++ data, err := ioutil.ReadFile(file)
49++ if err == nil {
50++ roots.AppendCertsFromPEM(data)
51++ return roots, nil
52++ }
53++ }
54+ cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain")
55+ data, err := cmd.Output()
56+ if err != nil {
57+ return nil, err
58+ }
59+
60+- roots := NewCertPool()
61+ roots.AppendCertsFromPEM(data)
62+ return roots, nil
63+ }
64+diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go
65+index 7bcb3d6..3986e1a 100644
66+--- a/src/crypto/x509/root_unix.go
67++++ b/src/crypto/x509/root_unix.go
68+@@ -24,6 +24,14 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
69+
70+ func loadSystemRoots() (*CertPool, error) {
71+ roots := NewCertPool()
72++ if file := os.Getenv("SSL_CERT_FILE"); file != "" {
73++ data, err := ioutil.ReadFile(file)
74++ if err == nil {
75++ roots.AppendCertsFromPEM(data)
76++ return roots, nil
77++ }
78++ }
79++
80+ var firstErr error
81+ for _, file := range certFiles {
82+ data, err := ioutil.ReadFile(file)