gnu: Add go-github.com-howeyc-gopass.
[jackhill/guix/guix.git] / gnu / packages / golang.scm
CommitLineData
7a2941a8 1;;; GNU Guix --- Functional package management for GNU
dda785f6 2;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
7a2941a8
MJ
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>
eaca9ff0 9;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
247064c3 10;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
7a2941a8 11;;;
8a610eb6 12;;; This file is part of GNU Guix.
7a2941a8
MJ
13;;;
14;;; GNU Guix is free software; you can redistribute it and/or modify it
15;;; under the terms of the GNU General Public License as published by
16;;; the Free Software Foundation; either version 3 of the License, or (at
17;;; your option) any later version.
18;;;
19;;; GNU Guix is distributed in the hope that it will be useful, but
20;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;;; GNU General Public License for more details.
23;;;
24;;; You should have received a copy of the GNU General Public License
25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27(define-module (gnu packages golang)
28 #:use-module ((guix licenses) #:prefix license:)
29 #:use-module (guix utils)
30 #:use-module (guix download)
d3878e88 31 #:use-module (guix git-download)
7a2941a8
MJ
32 #:use-module (guix packages)
33 #:use-module (guix build-system gnu)
d3878e88 34 #:use-module (guix build-system go)
7a2941a8
MJ
35 #:use-module (gnu packages admin)
36 #:use-module (gnu packages gcc)
37 #:use-module (gnu packages base)
38 #:use-module (gnu packages perl)
39 #:use-module (gnu packages pkg-config)
40 #:use-module (gnu packages pcre)
41 #:use-module (ice-9 match)
42 #:use-module (srfi srfi-1))
43
44;; According to https://golang.org/doc/install/gccgo, gccgo-4.8.2 includes a
45;; complete go-1.1.2 implementation, gccgo-4.9 includes a complete go-1.2
46;; implementation, and gccgo-5 a complete implementation of go-1.4. Ultimately
47;; we hope to build go-1.5+ with a bootstrap process using gccgo-5. As of
48;; go-1.5, go cannot be bootstrapped without go-1.4, so we need to use go-1.4 or
49;; gccgo-5. Mips is not officially supported, but it should work if it is
50;; bootstrapped.
51
52(define-public go-1.4
53 (package
54 (name "go")
55 (version "1.4.3")
56 (source (origin
57 (method url-fetch)
58 (uri (string-append "https://storage.googleapis.com/golang/"
59 name version ".src.tar.gz"))
60 (sha256
61 (base32
62 "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
63 (build-system gnu-build-system)
64 (outputs '("out"
65 "doc"
66 "tests"))
67 (arguments
68 `(#:modules ((ice-9 match)
69 (guix build gnu-build-system)
1d698a8b
ST
70 (guix build utils)
71 (srfi srfi-1))
7a2941a8
MJ
72 #:tests? #f ; Tests are run by the all.bash script.
73 #:phases
74 (modify-phases %standard-phases
75 (delete 'configure)
76 (add-after 'patch-generated-file-shebangs 'chdir
77 (lambda _
78 (chdir "src")))
79 (add-before 'build 'prebuild
80 (lambda* (#:key inputs outputs #:allow-other-keys)
81 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
82 (ld (string-append (assoc-ref inputs "libc") "/lib"))
83 (loader (car (find-files ld "^ld-linux.+")))
84 (net-base (assoc-ref inputs "net-base"))
85 (tzdata-path
86 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
87 (output (assoc-ref outputs "out")))
88
89 ;; Removing net/ tests, which fail when attempting to access
90 ;; network resources not present in the build container.
91 (for-each delete-file
92 '("net/multicast_test.go" "net/parse_test.go"
93 "net/port_test.go"))
94
95 ;; Add libgcc to the RUNPATH.
96 (substitute* "cmd/go/build.go"
97 (("cgoldflags := \\[\\]string\\{\\}")
98 (string-append "cgoldflags := []string{"
99 "\"-rpath=" gcclib "\"}"))
100 (("ldflags := buildLdflags")
101 (string-append
102 "ldflags := buildLdflags\n"
103 "ldflags = append(ldflags, \"-r\")\n"
104 "ldflags = append(ldflags, \"" gcclib "\")\n")))
105
106 (substitute* "os/os_test.go"
107 (("/usr/bin") (getcwd))
108 (("/bin/pwd") (which "pwd")))
109
110 ;; Disable failing tests: these tests attempt to access
111 ;; commands or network resources which are neither available or
112 ;; necessary for the build to succeed.
113 (for-each
114 (match-lambda
115 ((file regex)
116 (substitute* file
117 ((regex all before test_name)
118 (string-append before "Disabled" test_name)))))
119 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
120 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
121 ("os/os_test.go" "(.+)(TestHostname.+)")
122 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
4b0bac4b
LF
123
124 ;; Tzdata 2016g changed the name of the time zone used in this
125 ;; test, and the patch for Go 1.7 does not work for 1.4.3:
126 ;; https://github.com/golang/go/issues/17545
127 ;; https://github.com/golang/go/issues/17276
128 ("time/time_test.go" "(.+)(TestLoadFixed.+)")
f826c8c7 129 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
4b0bac4b 130
7a2941a8
MJ
131 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
132 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
133 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
134 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
135 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
136 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
137 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
138 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
139 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")))
140
141 (substitute* "net/lookup_unix.go"
142 (("/etc/protocols") (string-append net-base "/etc/protocols")))
143 (substitute* "time/zoneinfo_unix.go"
144 (("/usr/share/zoneinfo/") tzdata-path))
145 (substitute* (find-files "cmd" "asm.c")
146 (("/lib/ld-linux.*\\.so\\.[0-9]") loader))
147 #t)))
148
149 (replace 'build
150 (lambda* (#:key inputs outputs #:allow-other-keys)
151 ;; FIXME: Some of the .a files are not bit-reproducible.
152 (let* ((output (assoc-ref outputs "out")))
153 (setenv "CC" (which "gcc"))
154 (setenv "GOOS" "linux")
155 (setenv "GOROOT" (dirname (getcwd)))
156 (setenv "GOROOT_FINAL" output)
04a95a4f
LF
157 ;; Go 1.4's cgo will not work with binutils >= 2.27:
158 ;; https://github.com/golang/go/issues/16906
159 (setenv "CGO_ENABLED" "0")
7a2941a8
MJ
160 (zero? (system* "sh" "all.bash")))))
161
162 (replace 'install
163 (lambda* (#:key outputs inputs #:allow-other-keys)
164 (let* ((output (assoc-ref outputs "out"))
165 (doc_out (assoc-ref outputs "doc"))
166 (bash (string-append (assoc-ref inputs "bash") "bin/bash"))
167 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
168 (tests (string-append
169 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
170 (mkdir-p tests)
171 (copy-recursively "../test" (string-append tests "/test"))
172 (delete-file-recursively "../test")
173 (mkdir-p docs)
174 (copy-recursively "../api" (string-append docs "/api"))
175 (delete-file-recursively "../api")
176 (copy-recursively "../doc" (string-append docs "/doc"))
177 (delete-file-recursively "../doc")
178
179 (for-each (lambda (file)
180 (let ((file (string-append "../" file)))
181 (install-file file docs)
182 (delete-file file)))
183 '("README" "CONTRIBUTORS" "AUTHORS" "PATENTS"
184 "LICENSE" "VERSION" "robots.txt"))
185 (copy-recursively "../" output)
186 #t))))))
187 (inputs
188 `(("tzdata" ,tzdata)
189 ("pcre" ,pcre)
190 ("gcc:lib" ,gcc "lib")))
191 (native-inputs
192 `(("pkg-config" ,%pkg-config)
193 ("which" ,which)
194 ("net-base" ,net-base)
195 ("perl" ,perl)))
196
197 (home-page "https://golang.org/")
198 (synopsis "Compiler and libraries for Go, a statically-typed language")
199 (description "Go, also commonly referred to as golang, is an imperative
247064c3
TGR
200programming language designed primarily for systems programming. Go is a
201compiled, statically typed language in the tradition of C and C++, but adds
202garbage collection, various safety features, and concurrent programming features
203in the style of communicating sequential processes (@dfn{CSP}).")
dda785f6 204 (supported-systems '("x86_64-linux" "i686-linux" "armhf-linux"))
7a2941a8 205 (license license:bsd-3)))
ec91bcb5 206
35131bab 207(define-public go-1.9
ec91bcb5
MJ
208 (package
209 (inherit go-1.4)
210 (name "go")
f3a13a21 211 (version "1.9.3")
ec91bcb5
MJ
212 (source
213 (origin
214 (method url-fetch)
215 (uri (string-append "https://storage.googleapis.com/golang/"
216 name version ".src.tar.gz"))
217 (sha256
218 (base32
f3a13a21 219 "1bj73hrr7jjdg0w6snwkqb5y3yrlks5nrs2lgnkyy0hyx7b0lgaf"))))
ec91bcb5
MJ
220 (arguments
221 (substitute-keyword-arguments (package-arguments go-1.4)
222 ((#:phases phases)
223 `(modify-phases ,phases
224 (replace 'prebuild
225 ;; TODO: Most of this could be factorized with Go 1.4.
226 (lambda* (#:key inputs outputs #:allow-other-keys)
227 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
228 (ld (string-append (assoc-ref inputs "libc") "/lib"))
229 (loader (car (find-files ld "^ld-linux.+")))
230 (net-base (assoc-ref inputs "net-base"))
231 (tzdata-path
232 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
233 (output (assoc-ref outputs "out")))
234
235 ;; Removing net/ tests, which fail when attempting to access
236 ;; network resources not present in the build container.
237 (for-each delete-file
a6169621
P
238 '("net/listen_test.go"
239 "net/parse_test.go"
240 "net/cgo_unix_test.go"))
ec91bcb5
MJ
241
242 (substitute* "os/os_test.go"
243 (("/usr/bin") (getcwd))
a6169621
P
244 (("/bin/pwd") (which "pwd"))
245 (("/bin/sh") (which "sh")))
ec91bcb5
MJ
246
247 ;; Add libgcc to runpath
248 (substitute* "cmd/link/internal/ld/lib.go"
249 (("!rpath.set") "true"))
35131bab 250 (substitute* "cmd/go/internal/work/build.go"
ec91bcb5
MJ
251 (("cgoldflags := \\[\\]string\\{\\}")
252 (string-append "cgoldflags := []string{"
253 "\"-rpath=" gcclib "\""
254 "}"))
255 (("ldflags = setextld\\(ldflags, compiler\\)")
256 (string-append
257 "ldflags = setextld(ldflags, compiler)\n"
258 "ldflags = append(ldflags, \"-r\")\n"
259 "ldflags = append(ldflags, \"" gcclib "\")\n"))
260 (("\"-lgcc_s\", ")
261 (string-append
262 "\"-Wl,-rpath=" gcclib "\", \"-lgcc_s\", ")))
263
264 ;; Disable failing tests: these tests attempt to access
1c797d4b
LF
265 ;; commands or network resources which are neither available
266 ;; nor necessary for the build to succeed.
ec91bcb5
MJ
267 (for-each
268 (match-lambda
269 ((file regex)
270 (substitute* file
271 ((regex all before test_name)
272 (string-append before "Disabled" test_name)))))
273 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
274 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
275 ("os/os_test.go" "(.+)(TestHostname.+)")
276 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
f826c8c7 277 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
ec91bcb5
MJ
278 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
279 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
280 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
281 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
282 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
283 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
284 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
285 ("os/exec/exec_test.go" "(.+)(TestIgnorePipeErrorOnSuccess.+)")
286 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
287 ("os/exec/exec_test.go" "(.+)(TestExtraFiles/areturn.+)")
288 ("cmd/go/go_test.go" "(.+)(TestCoverageWithCgo.+)")
289 ("os/exec/exec_test.go" "(.+)(TestOutputStderrCapture.+)")
290 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")
291 ("os/exec/exec_test.go" "(.+)(TestExtraFilesRace.+)")
292 ("net/lookup_test.go" "(.+)(TestLookupPort.+)")
293 ("syscall/exec_linux_test.go"
17399545 294 "(.+)(TestCloneNEWUSERAndRemapNoRootDisableSetgroups.+)")))
ec91bcb5
MJ
295
296 (substitute* "../misc/cgo/testsanitizers/test.bash"
297 (("(CC=)cc" all var) (string-append var "gcc")))
298
299 ;; fix shebang for testar script
300 ;; note the target script is generated at build time.
a6169621 301 (substitute* "../misc/cgo/testcarchive/carchive_test.go"
ec91bcb5
MJ
302 (("#!/usr/bin/env") (string-append "#!" (which "env"))))
303
304 (substitute* "net/lookup_unix.go"
305 (("/etc/protocols") (string-append net-base "/etc/protocols")))
306 (substitute* "net/port_unix.go"
307 (("/etc/services") (string-append net-base "/etc/services")))
308 (substitute* "time/zoneinfo_unix.go"
309 (("/usr/share/zoneinfo/") tzdata-path))
c04ef86e
P
310 (substitute* (find-files "cmd" "\\.go")
311 (("/lib(64)?/ld-linux.*\\.so\\.[0-9]") loader))
ec91bcb5
MJ
312 #t)))
313 (add-before 'build 'set-bootstrap-variables
314 (lambda* (#:key outputs inputs #:allow-other-keys)
315 ;; Tell the build system where to find the bootstrap Go.
316 (let ((go (assoc-ref inputs "go"))
317 (out (assoc-ref outputs "out")))
318 (setenv "GOROOT_BOOTSTRAP" go)
319 (setenv "PATH"
320 (string-append out "/bin:"
321 (dirname (getcwd)) "/bin:"
322 (getenv "PATH")))
323
324 ;; XXX: The following variables seem unrelated.
325 (setenv "GOGC" "400")
326 (setenv "GO_TEST_TIMEOUT_SCALE" "9999")
327 #t)))
04a95a4f
LF
328
329 (replace 'build
330 (lambda* (#:key inputs outputs #:allow-other-keys)
331 ;; FIXME: Some of the .a files are not bit-reproducible.
332 (let* ((output (assoc-ref outputs "out")))
333 (setenv "CC" (which "gcc"))
334 (setenv "GOOS" "linux")
335 (setenv "GOROOT" (dirname (getcwd)))
336 (setenv "GOROOT_FINAL" output)
337 (setenv "CGO_ENABLED" "1")
338 (zero? (system* "sh" "all.bash")))))
339
ec91bcb5
MJ
340 (replace 'install
341 ;; TODO: Most of this could be factorized with Go 1.4.
342 (lambda* (#:key outputs #:allow-other-keys)
343 (let* ((output (assoc-ref outputs "out"))
344 (doc_out (assoc-ref outputs "doc"))
345 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
346 (src (string-append
347 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
348 (delete-file-recursively "../pkg/bootstrap")
349
350 (mkdir-p src)
351 (copy-recursively "../test" (string-append src "/test"))
352 (delete-file-recursively "../test")
353 (mkdir-p docs)
354 (copy-recursively "../api" (string-append docs "/api"))
355 (delete-file-recursively "../api")
356 (copy-recursively "../doc" (string-append docs "/doc"))
357 (delete-file-recursively "../doc")
358
359 (for-each
360 (lambda (file)
361 (let* ((filein (string-append "../" file))
362 (fileout (string-append docs "/" file)))
363 (copy-file filein fileout)
364 (delete-file filein)))
365 ;; Note the slightly different file names compared to 1.4.
366 '("README.md" "CONTRIBUTORS" "AUTHORS" "PATENTS"
367 "LICENSE" "VERSION" "CONTRIBUTING.md" "robots.txt"))
368
369 (copy-recursively "../" output))))))))
370 (native-inputs
371 `(("go" ,go-1.4)
dda785f6
EF
372 ,@(package-native-inputs go-1.4)))
373 (supported-systems %supported-systems)))
ec91bcb5 374
35131bab 375(define-public go go-1.9)
d3878e88
LF
376
377(define-public go-github-com-alsm-ioprogress
378 (let ((commit "063c3725f436e7fba0c8f588547bee21ffec7ac5")
379 (revision "0"))
380 (package
381 (name "go-github-com-alsm-ioprogress")
382 (version (git-version "0.0.0" revision commit))
383 (source (origin
384 (method git-fetch)
385 (uri (git-reference
386 (url "https://github.com/alsm/ioprogress.git")
387 (commit commit)))
388 (sha256
389 (base32
390 "10ym5qlq77nynmkxbk767f2hfwyxg2k7hrzph05hvgzv833dhivh"))))
391 (build-system go-build-system)
392 (arguments
393 '(#:import-path "github.com/alsm/ioprogress"))
394 (synopsis "Textual progress bars in Go")
395 (description "@code{ioprogress} is a Go library with implementations of
396@code{io.Reader} and @code{io.Writer} that draws progress bars. The primary use
397case for these are for command-line applications but alternate progress bar
398writers can be supplied for alternate environments.")
399 (home-page "https://github.com/alsm/ioprogress")
400 (license license:expat))))
11b12655
LF
401
402(define-public go-github-com-aki237-nscjar
403 (let ((commit "e2df936ddd6050d30dd90c7214c02b5019c42f06")
404 (revision "0"))
405 (package
406 (name "go-github-com-aki237-nscjar")
407 (version (git-version "0.0.0" revision commit))
408 (source (origin
409 (method git-fetch)
410 (uri (git-reference
411 (url "https://github.com/aki237/nscjar.git")
412 (commit commit)))
413 (sha256
414 (base32
415 "03y7zzq12qvhsq86lb06sgns8xrkblbn7i7wd886wk3zr5574b96"))))
416 (build-system go-build-system)
417 (arguments
418 '(#:import-path "github.com/aki237/nscjar"))
419 (synopsis "Handle Netscape / Mozilla cookies")
420 (description "@code{nscjar} is a Go library used to parse and output
421Netscape/Mozilla's old-style cookie files. It also implements a simple cookie
422jar struct to manage the cookies added to the cookie jar.")
423 (home-page "https://github.com/aki237/nscjar")
424 (license license:expat))))
12f496ba
LF
425
426(define-public go-github-com-davidjpeacock-cli
427 (let ((commit "8ba6f23b6e36d03666a14bd9421f5e3efcb59aca")
428 (revision "0"))
429 (package
430 (name "go-github-com-davidjpeacock-cli")
431 (version (git-version "1.19.1" revision commit))
432 (source (origin
433 (method git-fetch)
434 (uri (git-reference
435 (url "https://github.com/davidjpeacock/cli.git")
436 (commit commit)))
437 (sha256
438 (base32
439 "01s53ny3p0fdx64rnwcnmjj4xpc5adihnh6islsfq5z1ph2phhnj"))))
440 (build-system go-build-system)
441 (arguments
442 '(#:import-path "github.com/davidjpeacock/cli"))
443 (synopsis "Build command-line interfaces in Go")
444 (description "@code{cli} is a package for building command line
445interfaces in Go. The goal is to enable developers to write fast and
446distributable command line applications in an expressive way.")
447 (home-page "https://github.com/davidjpeacock/cli")
448 (license license:expat))))