diff mbox

[WIP] go@1.4 go@1.5 go@1.6 compilers

Message ID 87r3czxmtz.fsf@mailerver.i-did-not-set--mail-host-address--so-tickle-me
State New
Headers show

Commit Message

Matthew Jordan May 18, 2016, 6:06 p.m. UTC
Good Day everyone,

Thanks to the initial work done by "Efraim Flashner
<efraim@flashner.co.il>" and a little encouragement ("tweeaking" lol)
from Ludovic Courtès <ludo@gnu.org> I have done some work on the golang
compiler package.

The good news is I have been able to build go minor versions 4, 5 and 6.
Go 4 and 5 build ok with some tests disabled.

The bad news is, go 6 on the other hand seems to be a bit more
stubborn. (After this I'll never say bad thing ever against the GNU
Build System/Autotools ever! ^_^). I'll probably research the problem
later when I have some more time to do so.
Sections/Contents
--- Summary/Short version
--- More detailed version

================================================================================

--- Summary/Short version (see "--- More detailed version" for details)

================================================================================

=============> Note: some of the commands may be biased towards the
zsh shell

Results;

go-1.4 builds sucessfully with all.bash script.
go-1.5 builds successfully with all.bash script.
go-1.6 build successfully with make.bash script.

Main problem affecting the three mentioned minor versions;

$ go version
go: error while loading shared libraries: libgcc_s.so.1: cannot open
shared object file: No such file or directory

Solved manually by
$ export LD_LIBRARY_PATH=$LIBRARY_PATH

$ go version
go version go1.6.2 linux/amd64

I suspect that not having LD_LIBRARY_PATH is also affecting the package
build, namely
the following snippets from the package code;

(delete 'validate-runpath)

(setenv "LD_LIBRARY_PATH" (getenv "LIBRARY_PATH"))

I have taken a look at the code related to gcc@4.9 lib output.  I know
I can add the following snippet;

(search-path-specification
(variable "LD_LIBRARY_PATH")
(files '("lib" "lib64")))

to the search-path-specification list for a given package.  Just when
looking at gcc@4.9 it's quite different. I'm wondering what would be
considered the correct way to accomplish this in the upstream package.

Problem affecting the minor version 6;

$ less $BUILD_LOG
...
which: no go_linux_amd64_exec
...
<End of log>

================================================================================

--- More detailed version

================================================================================

Using or testing out go-1.6.2;

$ export GUIX_BUILD_OPTIONS="--keep-failed --verbosity=3"
$ BUILD_LOG=${HOME}/tmp/logs/pre-guix-build.log
$ ./pre-inst-env guix build go@1.6.2 &>/dev/stdout &>${BUILD_LOG}
$ ./pre-inst-env guix environment --ad-hoc go@1.6.2
$ eval `./pre-inst-env guix environment --search-paths --ad-hoc
go@1.6.2`

$ go version
go: error while loading shared libraries: libgcc_s.so.1: cannot open
shared object file: No such file or directory

$ export LD_LIBRARY_PATH=$LIBRARY_PATH
$ go version
go version go1.6.2 linux/amd64

Build/run hello world
$ mkdir ~/tmp/go-hello-world && \
cd ~/tmp/go-hello-world
$ cat <<EOF > hello-world.go
package main

import "fmt"

func main() {
            fmt.Println("hello world")
            }
            EOF

Run the hello world
$ go run hello-world.go


Build and run the hello world
$ go build hello-world.go
$ ./hello-world


Build/run hello world with C code import
$ rm ./* # just cleaning up
$ cat <<EOF > hello.c
#include "hello.h"

void hello()
{
    printf("%s\n", "Hello World!");
    }
    EOF

$ cat <<EOF > hello.h
#ifndef _HELLO_H_
#define _HELLO_H_

#include <stdio.h>

void hello();

#endif /* _HELLO_H_ */
EOF

$ cat <<EOF > hello.go
package main

/*
#include <stdlib.h>
#include "hello.h"
*/
import "C"

func main() {
     C.hello()
     }
     EOF

$ go build
$ ./go-hello-world

Both hello world programs built and ran sucessfully. I have gotten
similar results with go-1.4.3. I haven't done this with go@1.5.4 but I
would expect similar results there also.

Main problem affecting the three mentioned minor versions;

$ go version
go: error while loading shared libraries: libgcc_s.so.1: cannot open
shared object file: No such file or directory

Solved manually by
$ export LD_LIBRARY_PATH=$LIBRARY_PATH

$ go version
go version go1.6.2 linux/amd64

I suspect that not having LD_LIBRARY_PATH is also affecting the package
build, namely
the following snippets from the package code;

(delete 'validate-runpath)

(setenv "LD_LIBRARY_PATH" (getenv "LIBRARY_PATH"))

I have taken a look at the code related to gcc@4.9 lib output.  I know
I can add the following snippet;

(search-path-specification
(variable "LD_LIBRARY_PATH")
(files '("lib" "lib64")))

to the search-path-specification list for a given package.  Just when
looking at gcc@4.9 it's quite different. I'm wondering what would be
considered the correct way to accomplish this in the upstream package.

Problem affecting the minor version 6;

$ less $BUILD_LOG
...
##### ../misc/cgo/testsovar

##### ../misc/cgo/testcarchive
which: no go_linux_amd64_exec in
(/tmp/guix-build-go-1.6.drv-0/go/bin:/gnu/store/sb1h89qyg17j4776qhjz0ximg8p1vqgc-go-1.6/bin:/tmp/guix-build-go-1.6.drv-0/go/src..//bin:/g
nu/store/avrs0mngdhwl4l1xn4r98j3bilrxlvmf-go-1.4.3/bin:/gnu/store/527yzcdcga89cpzm9mf9b786yz8sr99z-gcc-4.9.3/bin:/gnu/store/wbdfz4mjzr8kv5vds1a9h5f40ljjfaj2-rc-1.7.4/bin:
/gnu/store/abgjh1qaxd5fmg24d4wl3p1q8naskz4p-perl-5.22.1/bin:/gnu/store/ggmmcw327ny831gqd7zvi3hpl5fm23mn-tar-1.28/bin:/gnu/store/304ljrrivn98ds6zsv3lcrp5c8qyl8d5-gzip-1.6/
bin:/gnu/store/b3bmn7z2f68v76331k1vk47wv5d4g5xd-bzip2-1.0.6/bin:/gnu/store/z8vgpay1q450ndgil902xxxz5mq0b1qr-xz-5.2.2/bin:/gnu/store/knws2xhs2507r0f9qc3b45dn1fxmpi5g-file-
5.25/bin:/gnu/store/p2c0vfazcl5xzg1pjjcanzmdwvli4fnv-diffutils-3.3/bin:/gnu/store/fhwvc4i82dxfipkl5nqc54s6rfp7jjq9-patch-2.7.5/bin:/gnu/store/5n82r6pa03fzxkph4i589ycm2kay
7kid-sed-4.2.2/bin:/gnu/store/wimqywg0v6xjgrpfpnr2hb6r93qm5272-findutils-4.6.0/bin:/gnu/store/01q81q7lxwpkykghl4yc7d4g4yvpbbi6-gawk-4.1.3/bin:/gnu/store/jfj94hba68b4py44l
0imw1052qmp90dj-grep-2.22/bin:/gnu/store/34j2zmi69mqwrslpyizbi9mcxmn2hzgb-coreutils-8.24/bin:/gnu/store/jwg90sxflq78ikvggf3hkwyk39ikrnik-make-4.1/bin:/gnu/store/b1yqjimbd
h5bf9jnizd4h7yf110744j2-bash-4.3.42/bin:/gnu/store/sfxymqv7ggsg900yyaipg90r3sg42638-ld-wrapper-0/bin:/gnu/store/7s1ikfk5dyhq4s7p8jaas4yrr14d77dq-binutils-2.25.1/bin:/gnu/
store/sjvcirri2bg7q5hlrkaywhmxllik0cfx-gcc-4.9.3/bin:/gnu/store/8m00x5x8ykmar27s9248cmhnkdb2n54a-glibc-2.22/bin:/gnu/store/8m00x5x8ykmar27s9248cmhnkdb2n54a-glibc-2.22/sbi
n:/gnu/store/cf2pqc3xg14qpcpjc32xd65r51lsrd16-which-2.21/bin:/gnu/store/qyyb05g8zp914ds6ania5pkrkqfgn31v-pkg-config-0.29/bin:/gnu/store/yvbr4gi6phn3rnwvynscwgcddqf9cd8f-p
cre-8.38/bin:/gnu/store/5fx3vscv9pqjr1k0vyaqnpqlvvzl8rff-glibc-2.22/bin:/gnu/store/5fx3vscv9pqjr1k0vyaqnpqlvvzl8rff-glibc-2.22/sbin)
PASS
PASS
PASS
PASS
PASS
PASS

##### ../misc/cgo/testcshared
ok
...
<End of log>

A couple more test are run after and some are skipped but the test
ultimately fails.

Comments

Leo Famulari May 19, 2016, 10:04 p.m. UTC | #1
On Wed, May 18, 2016 at 02:06:32PM -0400, Matthew Jordan wrote:
> Thanks to the initial work done by "Efraim Flashner
> <efraim@flashner.co.il>" and a little encouragement ("tweeaking" lol)
> from Ludovic Courtès <ludo@gnu.org> I have done some work on the golang
> compiler package.

I'm very happy to see more work being done to bring Golang into Guix!

> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2015, 2016 Efraim Flashner <efraim@flashner.co.il>
> +;;; Copyright © 2016 Matthew Jordan <matthewjordandevops@yandex.com>
> +;;;
> +;;; This file is an addendum GNU Guix.

We should remember to update this line when we are ready to merge the
patch.

> +(define-public go-1.4

[...]

> +               ;; Disable the unix socket test
> +               (system* "sed" "-i" "/TestShutdownUnix/areturn" "net/net_test.go")

Later, I think we should replace the use of `sed` with more uses of
(substitute).

> +(define-public go-1.5

> +    (native-inputs
> +     `(("gccgo" ,go-1.4)
> +       ,@(alist-delete "gccgo" (package-native-inputs go-1.4))))))

Is there a reason to call go-1.4 'gccgo' here? Is it an artifact of
copy-pasting the go-1.4 package definition, which uses 'gccgo' in the
pre-build and build phases?

> Sections/Contents
> --- Summary/Short version
> --- More detailed version
> 
> ================================================================================
> 
> --- Summary/Short version (see "--- More detailed version" for details)
> 
> ================================================================================
> 
> =============> Note: some of the commands may be biased towards the
> zsh shell
> 
> Results;
> 
> go-1.4 builds sucessfully with all.bash script.
> go-1.5 builds successfully with all.bash script.
> go-1.6 build successfully with make.bash script.
> 
> Main problem affecting the three mentioned minor versions;
> 
> $ go version
> go: error while loading shared libraries: libgcc_s.so.1: cannot open
> shared object file: No such file or directory

This is the big problem with all of our attempts so far.

> Solved manually by
> $ export LD_LIBRARY_PATH=$LIBRARY_PATH

As Ricardo said in another thread, we should really figure out how to
make this unecessary.
diff mbox

Patch

From a13b0cdcad51eb25153919c5498a5d686d9f70cc Mon Sep 17 00:00:00 2001
From: Matthew Jordan <matthewjordandevops@yandex.com>
Date: Tue, 17 May 2016 11:47:28 -0400
Subject: [PATCH] gnu: Add go.

* gnu/packages/golang.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Modified file.

Co-authored by: Efraim Flashner <efraim@flashner.co.il>
---
 gnu/local.mk            |   1 +
 gnu/packages/golang.scm | 379 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 380 insertions(+)
 create mode 100644 gnu/packages/golang.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 4bbded9..346ed5a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -147,6 +147,7 @@  GNU_SYSTEM_MODULES =				\
   gnu/packages/gnustep.scm			\
   gnu/packages/gnuzilla.scm			\
   gnu/packages/gnu-pw-mgr.scm			\
+  gnu/packages/golang.scm			\
   gnu/packages/gperf.scm			\
   gnu/packages/gprolog.scm			\
   gnu/packages/gps.scm				\
diff --git a/gnu/packages/golang.scm b/gnu/packages/golang.scm
new file mode 100644
index 0000000..c2e95a8
--- /dev/null
+++ b/gnu/packages/golang.scm
@@ -0,0 +1,379 @@ 
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015, 2016 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2016 Matthew Jordan <matthewjordandevops@yandex.com>
+;;;
+;;; This file is an addendum GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages golang)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix utils)
+  #:use-module (guix download)
+  #:use-module (guix packages)
+  #:use-module (guix build-system gnu)
+  #:use-module (gnu packages admin)
+  #:use-module (gnu packages rc)
+  #:use-module (gnu packages gcc)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages pcre)
+  #:use-module (srfi srfi-1))
+
+;; According to https://golang.org/doc/install/gccgo, gccgo-4.8.2 includes a
+;; complete go-1.1.2 implementation, gccgo-4.9 includes a complete go-1.2
+;; implementation, and gccgo-5 a complete implementation of go-1.4.  Ultimately
+;; we hope to build go-1.5+ with a bootstrap process using gccgo-5.  As of
+;; go-1.5, go cannot be bootstrapped without go-1.4, so we need to use go-1.4 or
+;; gccgo-5.  Mips is not officially supported, but it should work if it is
+;; bootstrapped.
+
+(define-public go-1.4
+  (package
+    (name "go")
+    (version "1.4.3")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://storage.googleapis.com/golang/"
+                           name version ".src.tar.gz"))
+       (sha256
+        (base32
+         "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
+    (build-system gnu-build-system)
+    (outputs '("out"
+               "doc"
+               "tests"))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (delete 'configure)
+         ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+         (delete 'validate-runpath)
+         (add-after 'patch-generated-file-shebangs 'chdir
+           (lambda _ (chdir "src")))
+         (add-before 'build 'prebuild
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (ld (string-append
+                         (assoc-ref inputs "glibc") "/lib"))
+                    (loader (car (find-files ld "^ld-linux.+")))
+                    (libgcc (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (net-base (assoc-ref inputs "net-base"))
+                    (tzdata-path
+                     (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
+                    (output (assoc-ref outputs "out")))
+               ;; Disabling net/ tests
+               (for-each
+                (lambda (srcfile)
+                  (let ((srcfile (string-append "net/" srcfile)))
+                  (if (file-exists? srcfile)
+                      (delete-file srcfile))))
+                '("multicast_test.go" "parse_test.go" "port_test.go"))
+               (substitute* "os/os_test.go"
+                 (("/usr/bin") (getcwd))
+                 (("/bin/pwd") (which "pwd")))
+               ;; Disable the unix socket test
+               (system* "sed" "-i" "/TestShutdownUnix/areturn" "net/net_test.go")
+               ;; Disable network timeout test
+               (system* "sed" "-i" "/TestDialTimeout/areturn" "net/dial_test.go")
+               ;; Disable the hostname test
+               (system* "sed" "-i" "/TestHostname/areturn" "os/os_test.go")
+               ;; ParseInLocation fails the test
+               (system* "sed" "-i" "/TestParseInSydney/areturn" "time/format_test.go")
+               (system* "sed" "-i" "/TestEcho/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCommandRelativeName/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatStdin/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatGoodAndBadFile/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestExitStatus/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPipes/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestStdinClose/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPassFD(/areturn" "syscall/syscall_unix_test.go")
+               (system* "sed" "-i" "/TestExtraFiles/areturn" "os/exec/exec_test.go")
+               (substitute* "net/lookup_unix.go"
+                 (("/etc/protocols") (string-append net-base "/etc/protocols")))
+               (substitute* "time/zoneinfo_unix.go"
+                 (("/usr/share/zoneinfo/") tzdata-path))
+               (substitute*
+                   (find-files "cmd" "asm.c")
+                 (("/lib/ld-linux.*\\.so\\.[0-9]") loader)))))
+         (replace 'build
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (output (assoc-ref outputs "out")))
+               (setenv "CC" (which "gcc"))
+               (setenv "GOOS" "linux")
+               (setenv "GOROOT" (getcwd))
+               (setenv "GOROOT_BOOTSTRAP" gccgo)
+               (setenv "GOROOT_FINAL" output)
+               ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+               (setenv "LD_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
+               (setenv "CGO_ENABLED" "1")
+               (zero? (system* "sh" "all.bash")))))
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((output (assoc-ref outputs "out"))
+                    (docs   (assoc-ref outputs "doc"))
+                    (tests  (assoc-ref outputs "tests")))
+               (copy-recursively "../test" tests)
+               (delete-file-recursively "../test")
+               (copy-recursively "../api" (string-append docs "/api"))
+               (delete-file-recursively "../api")
+               (copy-recursively "../doc" (string-append docs "/doc"))
+               (delete-file-recursively "../doc")
+               (copy-recursively "../" output)))))
+       #:tests? #f))
+    (inputs
+     `(("which" ,which)
+       ("tzdata" ,tzdata)
+       ("pkg-config" ,%pkg-config)
+       ("pcre" ,pcre)))
+    (native-inputs
+     `(("gccgo" ,gccgo-4.9)
+       ("gcc:out" ,gcc-4.9 "out")
+       ("net-base" ,net-base)
+       ("rc" ,rc)
+       ("perl" ,perl)))
+    (propagated-inputs
+     `(("gcc:lib" ,gcc-4.9 "lib")
+       ("glibc" ,glibc)))
+    (home-page "https://golang.org/")
+    (synopsis "Compiled, statically typed language developed by Google")
+    (description "Go, also commonly referred to as golang, is a programming
+ language developed at Google.  Designed primarily for systems programming, it
+ is a compiled, statically typed language in the tradition of C and C++, with
+garbage collection, various safety features and in the style of communicating
+sequential processes (CSP) concurrent programming features added.")
+    (license license:bsd-3)))
+
+(define-public go-1.5
+  (package
+    (inherit go-1.4)
+    (name "go")
+    (version "1.5.4")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://storage.googleapis.com/golang/"
+                           name version ".src.tar.gz"))
+       (sha256
+        (base32
+         "14xwn2pr3g4i1h8qpyrjjdmq1pgvzkagk4aqsp841hfxwyyclah0"))))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (delete 'configure)
+         ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+         (delete 'validate-runpath)
+         (add-after 'patch-generated-file-shebangs 'chdir
+           (lambda _ (chdir "src")))
+         (add-before 'build 'prebuild
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (ld (string-append
+                         (assoc-ref inputs "glibc") "/lib"))
+                    (loader (car (find-files ld "^ld-linux.+")))
+                    (libgcc (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (net-base (assoc-ref inputs "net-base"))
+                    (tzdata-path
+                     (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
+                    (output (assoc-ref outputs "out")))
+               ;; Disabling net/ tests
+               (for-each
+                (lambda (srcfile)
+                  (let ((srcfile (string-append "net/" srcfile)))
+                    (if (file-exists? srcfile)
+                        (delete-file srcfile))))
+                '("multicast_test.go" "parse_test.go" "port_test.go"))
+               (substitute* "os/os_test.go"
+                 (("/usr/bin") (getcwd))
+                 (("/bin/pwd") (which "pwd")))
+               ;; Disable the unix socket test
+               (system* "sed" "-i" "/TestShutdownUnix/areturn" "net/net_test.go")
+               ;; Disable network timeout test
+               (system* "sed" "-i" "/TestDialTimeout/areturn" "net/dial_test.go")
+               ;; Disable the hostname test
+               (system* "sed" "-i" "/TestHostname/areturn" "os/os_test.go")
+               ;; ParseInLocation fails the test
+               (system* "sed" "-i" "/TestParseInSydney/areturn" "time/format_test.go")
+               (system* "sed" "-i" "/TestEcho/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCommandRelativeName/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatStdin/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatGoodAndBadFile/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestExitStatus/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPipes/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestStdinClose/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestIgnorePipeErrorOnSuccess/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPassFD(/areturn" "syscall/syscall_unix_test.go")
+               (system* "sed" "-i" "/TestExtraFiles/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestIPv4MulticastListener(/areturn" "net/listen_test.go")
+               (system* "sed" "-i" "/TestCloneNEWUSERAndRemapNoRootDisableSetgroups/areturn" "syscall/exec_linux_test.go")
+
+               (substitute* "net/lookup_unix.go"
+                 (("/etc/protocols") (string-append net-base "/etc/protocols")))
+               (substitute* "time/zoneinfo_unix.go"
+                 (("/usr/share/zoneinfo/") tzdata-path))
+               (substitute*
+                   (find-files "cmd" "asm.c")
+                 (("/lib/ld-linux.*\\.so\\.[0-9]") loader)))))
+         (replace 'build
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (output (assoc-ref outputs "out")))
+               (setenv "CC" (which "gcc"))
+               (setenv "GOOS" "linux")
+               (setenv "GOROOT" (getcwd))
+               (setenv "GOROOT_BOOTSTRAP" gccgo)
+               (setenv "GOROOT_FINAL" output)
+               ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+               (setenv "LD_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
+               (setenv "CGO_ENABLED" "1")
+               (zero? (system* "sh" "all.bash")))))
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((output (assoc-ref outputs "out"))
+                    (docs   (assoc-ref outputs "doc"))
+                    (tests  (assoc-ref outputs "tests")))
+               (copy-recursively "../test" tests)
+               (delete-file-recursively "../test")
+               (copy-recursively "../api" (string-append docs "/api"))
+               (delete-file-recursively "../api")
+               (copy-recursively "../doc" (string-append docs "/doc"))
+               (delete-file-recursively "../doc")
+               (copy-recursively "../" output)))))
+       #:tests? #f))
+    (native-inputs
+     `(("gccgo" ,go-1.4)
+       ,@(alist-delete "gccgo" (package-native-inputs go-1.4))))))
+
+(define-public go
+  (package
+    (inherit go-1.4)
+    (name "go")
+    (version "1.6.2")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://storage.googleapis.com/golang/"
+                           name version ".src.tar.gz"))
+       (sha256
+        (base32
+         "1k5wy5ijll5aacj1m6xxnjfjw6x9f255ml3f1jiicw031mshnyvq")))) ;; 1.6.2
+         ;; "0ipivhc34df8h439h5d81m0h1jz0gsy71m67ljrgk6rswj6cwv59")))) ;; 1.6
+         ;; "0gqrlzd6c2k9rqiq7zr4pzq8dcj4zakjc2gmzj52kcjixv6m6jqx")))) ;; 1.6.1
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (delete 'configure)
+         ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+         (delete 'validate-runpath)
+         (add-after 'patch-generated-file-shebangs 'chdir
+           (lambda _ (chdir "src")))
+         (add-before 'build 'prebuild
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (ld (string-append
+                         (assoc-ref inputs "glibc") "/lib"))
+                    (loader (car (find-files ld "^ld-linux.+")))
+                    (libgcc (string-append (assoc-ref inputs "gcc:lib") "/lib"))
+                    (net-base (assoc-ref inputs "net-base"))
+                    (tzdata-path
+                     (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
+                    (output (assoc-ref outputs "out")))
+               (for-each
+                (lambda (srcfile)
+                  (let ((srcfile (string-append "net/" srcfile)))
+                    (if (file-exists? srcfile)
+                        (delete-file srcfile))))
+                '("listen_test.go" "parse_test.go"))
+               ;; '("multicast_test.go" "parse_test.go" "port_test.go"))
+               ;; (delete-file "syscall/exec_linux_test.go")
+               (substitute* "os/os_test.go"
+                 (("/usr/bin") (getcwd))
+                 (("/bin/pwd") (which "pwd")))
+               ;; Disable the unix socket test
+               (system* "sed" "-i" "/TestShutdownUnix/areturn" "net/net_test.go")
+               ;; Disable network timeout test
+               (system* "sed" "-i" "/TestDialTimeout/areturn" "net/dial_test.go")
+               ;; Disable the hostname test
+               (system* "sed" "-i" "/TestHostname/areturn" "os/os_test.go")
+               ;; ParseInLocation fails the test
+               (system* "sed" "-i" "/TestParseInSydney/areturn" "time/format_test.go")
+               (system* "sed" "-i" "/TestEcho/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCommandRelativeName/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatStdin/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestCatGoodAndBadFile/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestExitStatus/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPipes/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestStdinClose/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestIgnorePipeErrorOnSuccess/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" "/TestPassFD(/areturn" "syscall/syscall_unix_test.go")
+               (system* "sed" "-i" "/TestExtraFiles/areturn" "os/exec/exec_test.go")
+               ;; (system* "sed" "-i" "/TestIPv4MulticastListener(/areturn" "net/listen_test.go")
+               (system* "sed" "-i" "/TestCloneNEWUSERAndRemapNoRootDisableSetgroups/areturn" "syscall/exec_linux_test.go")
+               (system* "sed" "-i" "/TestLookupPort/areturn" "net/lookup_test.go")
+               (system* "sed" "-i" "/TestOutputStderrCapture/areturn" "os/exec/exec_test.go")
+               (system* "sed" "-i" ",src/cmd/api/run.go,ireturn nil" "cmd/dist/test.go")
+               (system* "sed" "-i" ",TestCoverageWithCgo,areturn" "cmd/go/go_test.go")
+
+               ;; fix shebang for testar script
+               (substitute* "../misc/cgo/testcarchive/test.bash"
+                 (("#!/usr/bin/env") (string-append "#!" (which "env"))))
+               (substitute* "net/lookup_unix.go"
+                 (("/etc/protocols") (string-append net-base "/etc/protocols")))
+               (substitute* "net/port_unix.go"
+                 (("/etc/services") (string-append net-base "/etc/services")))
+               (substitute* "time/zoneinfo_unix.go"
+                 (("/usr/share/zoneinfo/") tzdata-path))
+               (substitute*
+                   (find-files "cmd" "asm.c")
+                 (("/lib/ld-linux.*\\.so\\.[0-9]") loader)))))
+         (replace 'build
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((gccgo  (assoc-ref inputs "gccgo"))
+                    (output (assoc-ref outputs "out")))
+               (setenv "CC" "gcc")
+               (setenv "GOOS" "linux")
+               (setenv "GOROOT" (string-append (getcwd) "../"))
+               (setenv "GOROOT_BOOTSTRAP" gccgo)
+               (setenv "GOROOT_FINAL" output)
+               (setenv "GOGC" "400")
+               (setenv "PATH"
+                       (string-append
+                        (getenv "GOROOT_FINAL") "/bin:"
+                        (getenv "GOROOT") "/bin:" (getenv "PATH")))
+               ;; figure out how to set LD_LIBRARY_PATH in gcc@4.9:lib
+               (setenv "LD_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
+               (setenv "CGO_ENABLED" "1")
+               (zero? (system* "sh" "make.bash")))))
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((output (assoc-ref outputs "out"))
+                    (docs   (assoc-ref outputs "doc"))
+                    (tests  (assoc-ref outputs "tests")))
+               (copy-recursively "../test" tests)
+               (delete-file-recursively "../test")
+               (copy-recursively "../api" (string-append docs "/api"))
+               (delete-file-recursively "../api")
+               (copy-recursively "../doc" (string-append docs "/doc"))
+               (delete-file-recursively "../doc")
+               (copy-recursively "../" output)))))
+       #:tests? #f))
+    (native-inputs
+     `(("gccgo" ,go-1.4)
+       ,@(alist-delete "gccgo" (package-native-inputs go-1.4))))))
-- 
2.7.4