gnu: ccache: Update to 3.2.5.
[jackhill/guix/guix.git] / gnu / packages / golang.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
3 ;;; Copyright © 2016 Matthew Jordan <matthewjordandevops@yandex.com>
4 ;;; Copyright © 2016 Andy Wingo <wingo@igalia.com>
5 ;;;
6 ;;; This file is an addendum GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu packages golang)
22 #:use-module ((guix licenses) #:prefix license:)
23 #:use-module (guix utils)
24 #:use-module (guix download)
25 #:use-module (guix packages)
26 #:use-module (guix build-system gnu)
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages gcc)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages perl)
31 #:use-module (gnu packages pkg-config)
32 #:use-module (gnu packages pcre)
33 #:use-module (ice-9 match)
34 #:use-module (srfi srfi-1))
35
36 ;; According to https://golang.org/doc/install/gccgo, gccgo-4.8.2 includes a
37 ;; complete go-1.1.2 implementation, gccgo-4.9 includes a complete go-1.2
38 ;; implementation, and gccgo-5 a complete implementation of go-1.4. Ultimately
39 ;; we hope to build go-1.5+ with a bootstrap process using gccgo-5. As of
40 ;; go-1.5, go cannot be bootstrapped without go-1.4, so we need to use go-1.4 or
41 ;; gccgo-5. Mips is not officially supported, but it should work if it is
42 ;; bootstrapped.
43
44 (define-public go-1.4
45 (package
46 (name "go")
47 (version "1.4.3")
48 (source (origin
49 (method url-fetch)
50 (uri (string-append "https://storage.googleapis.com/golang/"
51 name version ".src.tar.gz"))
52 (sha256
53 (base32
54 "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
55 (build-system gnu-build-system)
56 (outputs '("out"
57 "doc"
58 "tests"))
59 (arguments
60 `(#:modules ((ice-9 match)
61 (guix build gnu-build-system)
62 (guix build utils))
63 #:tests? #f ; Tests are run by the all.bash script.
64 #:phases
65 (modify-phases %standard-phases
66 (delete 'configure)
67 (add-after 'patch-generated-file-shebangs 'chdir
68 (lambda _
69 (chdir "src")))
70 (add-before 'build 'prebuild
71 (lambda* (#:key inputs outputs #:allow-other-keys)
72 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
73 (ld (string-append (assoc-ref inputs "libc") "/lib"))
74 (loader (car (find-files ld "^ld-linux.+")))
75 (net-base (assoc-ref inputs "net-base"))
76 (tzdata-path
77 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
78 (output (assoc-ref outputs "out")))
79
80 ;; Removing net/ tests, which fail when attempting to access
81 ;; network resources not present in the build container.
82 (for-each delete-file
83 '("net/multicast_test.go" "net/parse_test.go"
84 "net/port_test.go"))
85
86 ;; Add libgcc to the RUNPATH.
87 (substitute* "cmd/go/build.go"
88 (("cgoldflags := \\[\\]string\\{\\}")
89 (string-append "cgoldflags := []string{"
90 "\"-rpath=" gcclib "\"}"))
91 (("ldflags := buildLdflags")
92 (string-append
93 "ldflags := buildLdflags\n"
94 "ldflags = append(ldflags, \"-r\")\n"
95 "ldflags = append(ldflags, \"" gcclib "\")\n")))
96
97 (substitute* "os/os_test.go"
98 (("/usr/bin") (getcwd))
99 (("/bin/pwd") (which "pwd")))
100
101 ;; Disable failing tests: these tests attempt to access
102 ;; commands or network resources which are neither available or
103 ;; necessary for the build to succeed.
104 (for-each
105 (match-lambda
106 ((file regex)
107 (substitute* file
108 ((regex all before test_name)
109 (string-append before "Disabled" test_name)))))
110 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
111 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
112 ("os/os_test.go" "(.+)(TestHostname.+)")
113 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
114 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
115 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
116 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
117 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
118 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
119 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
120 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
121 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
122 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")))
123
124 (substitute* "net/lookup_unix.go"
125 (("/etc/protocols") (string-append net-base "/etc/protocols")))
126 (substitute* "time/zoneinfo_unix.go"
127 (("/usr/share/zoneinfo/") tzdata-path))
128 (substitute* (find-files "cmd" "asm.c")
129 (("/lib/ld-linux.*\\.so\\.[0-9]") loader))
130 #t)))
131
132 (replace 'build
133 (lambda* (#:key inputs outputs #:allow-other-keys)
134 ;; FIXME: Some of the .a files are not bit-reproducible.
135 (let* ((output (assoc-ref outputs "out")))
136 (setenv "CC" (which "gcc"))
137 (setenv "GOOS" "linux")
138 (setenv "GOROOT" (dirname (getcwd)))
139 (setenv "GOROOT_FINAL" output)
140 (setenv "CGO_ENABLED" "1")
141 (zero? (system* "sh" "all.bash")))))
142
143 (replace 'install
144 (lambda* (#:key outputs inputs #:allow-other-keys)
145 (let* ((output (assoc-ref outputs "out"))
146 (doc_out (assoc-ref outputs "doc"))
147 (bash (string-append (assoc-ref inputs "bash") "bin/bash"))
148 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
149 (tests (string-append
150 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
151 (mkdir-p tests)
152 (copy-recursively "../test" (string-append tests "/test"))
153 (delete-file-recursively "../test")
154 (mkdir-p docs)
155 (copy-recursively "../api" (string-append docs "/api"))
156 (delete-file-recursively "../api")
157 (copy-recursively "../doc" (string-append docs "/doc"))
158 (delete-file-recursively "../doc")
159
160 (for-each (lambda (file)
161 (let ((file (string-append "../" file)))
162 (install-file file docs)
163 (delete-file file)))
164 '("README" "CONTRIBUTORS" "AUTHORS" "PATENTS"
165 "LICENSE" "VERSION" "robots.txt"))
166 (copy-recursively "../" output)
167 #t))))))
168 (inputs
169 `(("tzdata" ,tzdata)
170 ("pcre" ,pcre)
171 ("gcc:lib" ,gcc "lib")))
172 (native-inputs
173 `(("pkg-config" ,%pkg-config)
174 ("which" ,which)
175 ("net-base" ,net-base)
176 ("perl" ,perl)))
177
178 (home-page "https://golang.org/")
179 (synopsis "Compiler and libraries for Go, a statically-typed language")
180 (description "Go, also commonly referred to as golang, is an imperative
181 programming language. Designed primarily for systems programming, it is a
182 compiled, statically typed language in the tradition of C and C++, with
183 garbage collection, various safety features and in the style of communicating
184 sequential processes (CSP) concurrent programming features added.")
185 (license license:bsd-3)))