gnu: perl-test-harness: Update to 3.39.
[jackhill/guix/guix.git] / gnu / packages / golang.scm
CommitLineData
7a2941a8
MJ
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>
ec91bcb5 5;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
c04ef86e 6;;; Copyright © 2016, 2017 Petter <petter@mykolab.ch>
17399545 7;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
c04ef86e 8;;; Copyright © 2017 Sergei Trofimovich <slyfox@inbox.ru>
7a2941a8 9;;;
8a610eb6 10;;; This file is part of GNU Guix.
7a2941a8
MJ
11;;;
12;;; GNU Guix is free software; you can redistribute it and/or modify it
13;;; under the terms of the GNU General Public License as published by
14;;; the Free Software Foundation; either version 3 of the License, or (at
15;;; your option) any later version.
16;;;
17;;; GNU Guix is distributed in the hope that it will be useful, but
18;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;;; GNU General Public License for more details.
21;;;
22;;; You should have received a copy of the GNU General Public License
23;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25(define-module (gnu packages golang)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (guix utils)
28 #:use-module (guix download)
29 #:use-module (guix packages)
30 #:use-module (guix build-system gnu)
31 #:use-module (gnu packages admin)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages base)
34 #:use-module (gnu packages perl)
35 #:use-module (gnu packages pkg-config)
36 #:use-module (gnu packages pcre)
37 #:use-module (ice-9 match)
38 #:use-module (srfi srfi-1))
39
40;; According to https://golang.org/doc/install/gccgo, gccgo-4.8.2 includes a
41;; complete go-1.1.2 implementation, gccgo-4.9 includes a complete go-1.2
42;; implementation, and gccgo-5 a complete implementation of go-1.4. Ultimately
43;; we hope to build go-1.5+ with a bootstrap process using gccgo-5. As of
44;; go-1.5, go cannot be bootstrapped without go-1.4, so we need to use go-1.4 or
45;; gccgo-5. Mips is not officially supported, but it should work if it is
46;; bootstrapped.
47
48(define-public go-1.4
49 (package
50 (name "go")
51 (version "1.4.3")
52 (source (origin
53 (method url-fetch)
54 (uri (string-append "https://storage.googleapis.com/golang/"
55 name version ".src.tar.gz"))
56 (sha256
57 (base32
58 "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
59 (build-system gnu-build-system)
60 (outputs '("out"
61 "doc"
62 "tests"))
63 (arguments
64 `(#:modules ((ice-9 match)
65 (guix build gnu-build-system)
1d698a8b
ST
66 (guix build utils)
67 (srfi srfi-1))
7a2941a8
MJ
68 #:tests? #f ; Tests are run by the all.bash script.
69 #:phases
70 (modify-phases %standard-phases
71 (delete 'configure)
72 (add-after 'patch-generated-file-shebangs 'chdir
73 (lambda _
74 (chdir "src")))
75 (add-before 'build 'prebuild
76 (lambda* (#:key inputs outputs #:allow-other-keys)
77 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
78 (ld (string-append (assoc-ref inputs "libc") "/lib"))
79 (loader (car (find-files ld "^ld-linux.+")))
80 (net-base (assoc-ref inputs "net-base"))
81 (tzdata-path
82 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
83 (output (assoc-ref outputs "out")))
84
85 ;; Removing net/ tests, which fail when attempting to access
86 ;; network resources not present in the build container.
87 (for-each delete-file
88 '("net/multicast_test.go" "net/parse_test.go"
89 "net/port_test.go"))
90
91 ;; Add libgcc to the RUNPATH.
92 (substitute* "cmd/go/build.go"
93 (("cgoldflags := \\[\\]string\\{\\}")
94 (string-append "cgoldflags := []string{"
95 "\"-rpath=" gcclib "\"}"))
96 (("ldflags := buildLdflags")
97 (string-append
98 "ldflags := buildLdflags\n"
99 "ldflags = append(ldflags, \"-r\")\n"
100 "ldflags = append(ldflags, \"" gcclib "\")\n")))
101
102 (substitute* "os/os_test.go"
103 (("/usr/bin") (getcwd))
104 (("/bin/pwd") (which "pwd")))
105
106 ;; Disable failing tests: these tests attempt to access
107 ;; commands or network resources which are neither available or
108 ;; necessary for the build to succeed.
109 (for-each
110 (match-lambda
111 ((file regex)
112 (substitute* file
113 ((regex all before test_name)
114 (string-append before "Disabled" test_name)))))
115 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
116 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
117 ("os/os_test.go" "(.+)(TestHostname.+)")
118 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
4b0bac4b
LF
119
120 ;; Tzdata 2016g changed the name of the time zone used in this
121 ;; test, and the patch for Go 1.7 does not work for 1.4.3:
122 ;; https://github.com/golang/go/issues/17545
123 ;; https://github.com/golang/go/issues/17276
124 ("time/time_test.go" "(.+)(TestLoadFixed.+)")
f826c8c7 125 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
4b0bac4b 126
7a2941a8
MJ
127 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
128 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
129 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
130 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
131 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
132 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
133 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
134 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
135 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")))
136
137 (substitute* "net/lookup_unix.go"
138 (("/etc/protocols") (string-append net-base "/etc/protocols")))
139 (substitute* "time/zoneinfo_unix.go"
140 (("/usr/share/zoneinfo/") tzdata-path))
141 (substitute* (find-files "cmd" "asm.c")
142 (("/lib/ld-linux.*\\.so\\.[0-9]") loader))
143 #t)))
144
145 (replace 'build
146 (lambda* (#:key inputs outputs #:allow-other-keys)
147 ;; FIXME: Some of the .a files are not bit-reproducible.
148 (let* ((output (assoc-ref outputs "out")))
149 (setenv "CC" (which "gcc"))
150 (setenv "GOOS" "linux")
151 (setenv "GOROOT" (dirname (getcwd)))
152 (setenv "GOROOT_FINAL" output)
04a95a4f
LF
153 ;; Go 1.4's cgo will not work with binutils >= 2.27:
154 ;; https://github.com/golang/go/issues/16906
155 (setenv "CGO_ENABLED" "0")
7a2941a8
MJ
156 (zero? (system* "sh" "all.bash")))))
157
158 (replace 'install
159 (lambda* (#:key outputs inputs #:allow-other-keys)
160 (let* ((output (assoc-ref outputs "out"))
161 (doc_out (assoc-ref outputs "doc"))
162 (bash (string-append (assoc-ref inputs "bash") "bin/bash"))
163 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
164 (tests (string-append
165 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
166 (mkdir-p tests)
167 (copy-recursively "../test" (string-append tests "/test"))
168 (delete-file-recursively "../test")
169 (mkdir-p docs)
170 (copy-recursively "../api" (string-append docs "/api"))
171 (delete-file-recursively "../api")
172 (copy-recursively "../doc" (string-append docs "/doc"))
173 (delete-file-recursively "../doc")
174
175 (for-each (lambda (file)
176 (let ((file (string-append "../" file)))
177 (install-file file docs)
178 (delete-file file)))
179 '("README" "CONTRIBUTORS" "AUTHORS" "PATENTS"
180 "LICENSE" "VERSION" "robots.txt"))
181 (copy-recursively "../" output)
182 #t))))))
183 (inputs
184 `(("tzdata" ,tzdata)
185 ("pcre" ,pcre)
186 ("gcc:lib" ,gcc "lib")))
187 (native-inputs
188 `(("pkg-config" ,%pkg-config)
189 ("which" ,which)
190 ("net-base" ,net-base)
191 ("perl" ,perl)))
192
193 (home-page "https://golang.org/")
194 (synopsis "Compiler and libraries for Go, a statically-typed language")
195 (description "Go, also commonly referred to as golang, is an imperative
196programming language. Designed primarily for systems programming, it is a
197compiled, statically typed language in the tradition of C and C++, with
198garbage collection, various safety features and in the style of communicating
199sequential processes (CSP) concurrent programming features added.")
200 (license license:bsd-3)))
ec91bcb5 201
c04ef86e 202(define-public go-1.8
ec91bcb5
MJ
203 (package
204 (inherit go-1.4)
205 (name "go")
1c797d4b 206 (version "1.8.3")
ec91bcb5
MJ
207 (source
208 (origin
209 (method url-fetch)
210 (uri (string-append "https://storage.googleapis.com/golang/"
211 name version ".src.tar.gz"))
212 (sha256
213 (base32
1c797d4b 214 "19lzv4lqixj3v2gjaff0fdbbmgsq5r8lrfd61z2zvp778wjflpaz"))))
ec91bcb5
MJ
215 (arguments
216 (substitute-keyword-arguments (package-arguments go-1.4)
217 ((#:phases phases)
218 `(modify-phases ,phases
219 (replace 'prebuild
220 ;; TODO: Most of this could be factorized with Go 1.4.
221 (lambda* (#:key inputs outputs #:allow-other-keys)
222 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
223 (ld (string-append (assoc-ref inputs "libc") "/lib"))
224 (loader (car (find-files ld "^ld-linux.+")))
225 (net-base (assoc-ref inputs "net-base"))
226 (tzdata-path
227 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
228 (output (assoc-ref outputs "out")))
229
230 ;; Removing net/ tests, which fail when attempting to access
231 ;; network resources not present in the build container.
232 (for-each delete-file
a6169621
P
233 '("net/listen_test.go"
234 "net/parse_test.go"
235 "net/cgo_unix_test.go"))
ec91bcb5
MJ
236
237 (substitute* "os/os_test.go"
238 (("/usr/bin") (getcwd))
a6169621
P
239 (("/bin/pwd") (which "pwd"))
240 (("/bin/sh") (which "sh")))
ec91bcb5
MJ
241
242 ;; Add libgcc to runpath
243 (substitute* "cmd/link/internal/ld/lib.go"
244 (("!rpath.set") "true"))
245 (substitute* "cmd/go/build.go"
246 (("cgoldflags := \\[\\]string\\{\\}")
247 (string-append "cgoldflags := []string{"
248 "\"-rpath=" gcclib "\""
249 "}"))
250 (("ldflags = setextld\\(ldflags, compiler\\)")
251 (string-append
252 "ldflags = setextld(ldflags, compiler)\n"
253 "ldflags = append(ldflags, \"-r\")\n"
254 "ldflags = append(ldflags, \"" gcclib "\")\n"))
255 (("\"-lgcc_s\", ")
256 (string-append
257 "\"-Wl,-rpath=" gcclib "\", \"-lgcc_s\", ")))
258
259 ;; Disable failing tests: these tests attempt to access
1c797d4b
LF
260 ;; commands or network resources which are neither available
261 ;; nor necessary for the build to succeed.
ec91bcb5
MJ
262 (for-each
263 (match-lambda
264 ((file regex)
265 (substitute* file
266 ((regex all before test_name)
267 (string-append before "Disabled" test_name)))))
268 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
269 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
270 ("os/os_test.go" "(.+)(TestHostname.+)")
271 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
f826c8c7 272 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
ec91bcb5
MJ
273 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
274 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
275 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
276 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
277 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
278 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
279 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
280 ("os/exec/exec_test.go" "(.+)(TestIgnorePipeErrorOnSuccess.+)")
281 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
282 ("os/exec/exec_test.go" "(.+)(TestExtraFiles/areturn.+)")
283 ("cmd/go/go_test.go" "(.+)(TestCoverageWithCgo.+)")
284 ("os/exec/exec_test.go" "(.+)(TestOutputStderrCapture.+)")
285 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")
286 ("os/exec/exec_test.go" "(.+)(TestExtraFilesRace.+)")
287 ("net/lookup_test.go" "(.+)(TestLookupPort.+)")
288 ("syscall/exec_linux_test.go"
17399545 289 "(.+)(TestCloneNEWUSERAndRemapNoRootDisableSetgroups.+)")))
ec91bcb5
MJ
290
291 (substitute* "../misc/cgo/testsanitizers/test.bash"
292 (("(CC=)cc" all var) (string-append var "gcc")))
293
294 ;; fix shebang for testar script
295 ;; note the target script is generated at build time.
a6169621 296 (substitute* "../misc/cgo/testcarchive/carchive_test.go"
ec91bcb5
MJ
297 (("#!/usr/bin/env") (string-append "#!" (which "env"))))
298
299 (substitute* "net/lookup_unix.go"
300 (("/etc/protocols") (string-append net-base "/etc/protocols")))
301 (substitute* "net/port_unix.go"
302 (("/etc/services") (string-append net-base "/etc/services")))
303 (substitute* "time/zoneinfo_unix.go"
304 (("/usr/share/zoneinfo/") tzdata-path))
c04ef86e
P
305 (substitute* (find-files "cmd" "\\.go")
306 (("/lib(64)?/ld-linux.*\\.so\\.[0-9]") loader))
ec91bcb5
MJ
307 #t)))
308 (add-before 'build 'set-bootstrap-variables
309 (lambda* (#:key outputs inputs #:allow-other-keys)
310 ;; Tell the build system where to find the bootstrap Go.
311 (let ((go (assoc-ref inputs "go"))
312 (out (assoc-ref outputs "out")))
313 (setenv "GOROOT_BOOTSTRAP" go)
314 (setenv "PATH"
315 (string-append out "/bin:"
316 (dirname (getcwd)) "/bin:"
317 (getenv "PATH")))
318
319 ;; XXX: The following variables seem unrelated.
320 (setenv "GOGC" "400")
321 (setenv "GO_TEST_TIMEOUT_SCALE" "9999")
322 #t)))
04a95a4f
LF
323
324 (replace 'build
325 (lambda* (#:key inputs outputs #:allow-other-keys)
326 ;; FIXME: Some of the .a files are not bit-reproducible.
327 (let* ((output (assoc-ref outputs "out")))
328 (setenv "CC" (which "gcc"))
329 (setenv "GOOS" "linux")
330 (setenv "GOROOT" (dirname (getcwd)))
331 (setenv "GOROOT_FINAL" output)
332 (setenv "CGO_ENABLED" "1")
333 (zero? (system* "sh" "all.bash")))))
334
ec91bcb5
MJ
335 (replace 'install
336 ;; TODO: Most of this could be factorized with Go 1.4.
337 (lambda* (#:key outputs #:allow-other-keys)
338 (let* ((output (assoc-ref outputs "out"))
339 (doc_out (assoc-ref outputs "doc"))
340 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
341 (src (string-append
342 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
343 (delete-file-recursively "../pkg/bootstrap")
344
345 (mkdir-p src)
346 (copy-recursively "../test" (string-append src "/test"))
347 (delete-file-recursively "../test")
348 (mkdir-p docs)
349 (copy-recursively "../api" (string-append docs "/api"))
350 (delete-file-recursively "../api")
351 (copy-recursively "../doc" (string-append docs "/doc"))
352 (delete-file-recursively "../doc")
353
354 (for-each
355 (lambda (file)
356 (let* ((filein (string-append "../" file))
357 (fileout (string-append docs "/" file)))
358 (copy-file filein fileout)
359 (delete-file filein)))
360 ;; Note the slightly different file names compared to 1.4.
361 '("README.md" "CONTRIBUTORS" "AUTHORS" "PATENTS"
362 "LICENSE" "VERSION" "CONTRIBUTING.md" "robots.txt"))
363
364 (copy-recursively "../" output))))))))
365 (native-inputs
366 `(("go" ,go-1.4)
367 ,@(package-native-inputs go-1.4)))))
368
c04ef86e 369(define-public go go-1.8)