1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
3 ;;; Copyright © 2016 Matthew Jordan <matthewjordandevops@yandex.com>
4 ;;; Copyright © 2016 Andy Wingo <wingo@igalia.com>
5 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
6 ;;; Copyright © 2016, 2017 Petter <petter@mykolab.ch>
7 ;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
8 ;;; Copyright © 2017 Sergei Trofimovich <slyfox@inbox.ru>
9 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
11 ;;; This file is part of GNU Guix.
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26 (define-module (gnu packages golang)
27 #:use-module ((guix licenses) #:prefix license:)
28 #:use-module (guix utils)
29 #:use-module (guix download)
30 #:use-module (guix packages)
31 #:use-module (guix build-system gnu)
32 #:use-module (gnu packages admin)
33 #:use-module (gnu packages gcc)
34 #:use-module (gnu packages base)
35 #:use-module (gnu packages perl)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (gnu packages pcre)
38 #:use-module (ice-9 match)
39 #:use-module (srfi srfi-1))
41 ;; According to https://golang.org/doc/install/gccgo, gccgo-4.8.2 includes a
42 ;; complete go-1.1.2 implementation, gccgo-4.9 includes a complete go-1.2
43 ;; implementation, and gccgo-5 a complete implementation of go-1.4. Ultimately
44 ;; we hope to build go-1.5+ with a bootstrap process using gccgo-5. As of
45 ;; go-1.5, go cannot be bootstrapped without go-1.4, so we need to use go-1.4 or
46 ;; gccgo-5. Mips is not officially supported, but it should work if it is
55 (uri (string-append "https://storage.googleapis.com/golang/"
56 name version ".src.tar.gz"))
59 "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
60 (build-system gnu-build-system)
65 `(#:modules ((ice-9 match)
66 (guix build gnu-build-system)
69 #:tests? #f ; Tests are run by the all.bash script.
71 (modify-phases %standard-phases
73 (add-after 'patch-generated-file-shebangs 'chdir
76 (add-before 'build 'prebuild
77 (lambda* (#:key inputs outputs #:allow-other-keys)
78 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
79 (ld (string-append (assoc-ref inputs "libc") "/lib"))
80 (loader (car (find-files ld "^ld-linux.+")))
81 (net-base (assoc-ref inputs "net-base"))
83 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
84 (output (assoc-ref outputs "out")))
86 ;; Removing net/ tests, which fail when attempting to access
87 ;; network resources not present in the build container.
89 '("net/multicast_test.go" "net/parse_test.go"
92 ;; Add libgcc to the RUNPATH.
93 (substitute* "cmd/go/build.go"
94 (("cgoldflags := \\[\\]string\\{\\}")
95 (string-append "cgoldflags := []string{"
96 "\"-rpath=" gcclib "\"}"))
97 (("ldflags := buildLdflags")
99 "ldflags := buildLdflags\n"
100 "ldflags = append(ldflags, \"-r\")\n"
101 "ldflags = append(ldflags, \"" gcclib "\")\n")))
103 (substitute* "os/os_test.go"
104 (("/usr/bin") (getcwd))
105 (("/bin/pwd") (which "pwd")))
107 ;; Disable failing tests: these tests attempt to access
108 ;; commands or network resources which are neither available or
109 ;; necessary for the build to succeed.
114 ((regex all before test_name)
115 (string-append before "Disabled" test_name)))))
116 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
117 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
118 ("os/os_test.go" "(.+)(TestHostname.+)")
119 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
121 ;; Tzdata 2016g changed the name of the time zone used in this
122 ;; test, and the patch for Go 1.7 does not work for 1.4.3:
123 ;; https://github.com/golang/go/issues/17545
124 ;; https://github.com/golang/go/issues/17276
125 ("time/time_test.go" "(.+)(TestLoadFixed.+)")
126 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
128 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
129 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
130 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
131 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
132 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
133 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
134 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
135 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
136 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")))
138 (substitute* "net/lookup_unix.go"
139 (("/etc/protocols") (string-append net-base "/etc/protocols")))
140 (substitute* "time/zoneinfo_unix.go"
141 (("/usr/share/zoneinfo/") tzdata-path))
142 (substitute* (find-files "cmd" "asm.c")
143 (("/lib/ld-linux.*\\.so\\.[0-9]") loader))
147 (lambda* (#:key inputs outputs #:allow-other-keys)
148 ;; FIXME: Some of the .a files are not bit-reproducible.
149 (let* ((output (assoc-ref outputs "out")))
150 (setenv "CC" (which "gcc"))
151 (setenv "GOOS" "linux")
152 (setenv "GOROOT" (dirname (getcwd)))
153 (setenv "GOROOT_FINAL" output)
154 ;; Go 1.4's cgo will not work with binutils >= 2.27:
155 ;; https://github.com/golang/go/issues/16906
156 (setenv "CGO_ENABLED" "0")
157 (zero? (system* "sh" "all.bash")))))
160 (lambda* (#:key outputs inputs #:allow-other-keys)
161 (let* ((output (assoc-ref outputs "out"))
162 (doc_out (assoc-ref outputs "doc"))
163 (bash (string-append (assoc-ref inputs "bash") "bin/bash"))
164 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
165 (tests (string-append
166 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
168 (copy-recursively "../test" (string-append tests "/test"))
169 (delete-file-recursively "../test")
171 (copy-recursively "../api" (string-append docs "/api"))
172 (delete-file-recursively "../api")
173 (copy-recursively "../doc" (string-append docs "/doc"))
174 (delete-file-recursively "../doc")
176 (for-each (lambda (file)
177 (let ((file (string-append "../" file)))
178 (install-file file docs)
180 '("README" "CONTRIBUTORS" "AUTHORS" "PATENTS"
181 "LICENSE" "VERSION" "robots.txt"))
182 (copy-recursively "../" output)
187 ("gcc:lib" ,gcc "lib")))
189 `(("pkg-config" ,%pkg-config)
191 ("net-base" ,net-base)
194 (home-page "https://golang.org/")
195 (synopsis "Compiler and libraries for Go, a statically-typed language")
196 (description "Go, also commonly referred to as golang, is an imperative
197 programming language. Designed primarily for systems programming, it is a
198 compiled, statically typed language in the tradition of C and C++, with
199 garbage collection, various safety features and in the style of communicating
200 sequential processes (CSP) concurrent programming features added.")
201 (supported-systems '("x86_64-linux" "i686-linux" "armhf-linux"))
202 (license license:bsd-3)))
204 (define-public go-1.9
212 (uri (string-append "https://storage.googleapis.com/golang/"
213 name version ".src.tar.gz"))
216 "1p23n4xzbknl3bbhlckbvxbhpxknd5rn0i2szmn9i2dcz15ihpv6"))))
218 (substitute-keyword-arguments (package-arguments go-1.4)
220 `(modify-phases ,phases
222 ;; TODO: Most of this could be factorized with Go 1.4.
223 (lambda* (#:key inputs outputs #:allow-other-keys)
224 (let* ((gcclib (string-append (assoc-ref inputs "gcc:lib") "/lib"))
225 (ld (string-append (assoc-ref inputs "libc") "/lib"))
226 (loader (car (find-files ld "^ld-linux.+")))
227 (net-base (assoc-ref inputs "net-base"))
229 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
230 (output (assoc-ref outputs "out")))
232 ;; Removing net/ tests, which fail when attempting to access
233 ;; network resources not present in the build container.
234 (for-each delete-file
235 '("net/listen_test.go"
237 "net/cgo_unix_test.go"))
239 (substitute* "os/os_test.go"
240 (("/usr/bin") (getcwd))
241 (("/bin/pwd") (which "pwd"))
242 (("/bin/sh") (which "sh")))
244 ;; Add libgcc to runpath
245 (substitute* "cmd/link/internal/ld/lib.go"
246 (("!rpath.set") "true"))
247 (substitute* "cmd/go/internal/work/build.go"
248 (("cgoldflags := \\[\\]string\\{\\}")
249 (string-append "cgoldflags := []string{"
250 "\"-rpath=" gcclib "\""
252 (("ldflags = setextld\\(ldflags, compiler\\)")
254 "ldflags = setextld(ldflags, compiler)\n"
255 "ldflags = append(ldflags, \"-r\")\n"
256 "ldflags = append(ldflags, \"" gcclib "\")\n"))
259 "\"-Wl,-rpath=" gcclib "\", \"-lgcc_s\", ")))
261 ;; Disable failing tests: these tests attempt to access
262 ;; commands or network resources which are neither available
263 ;; nor necessary for the build to succeed.
268 ((regex all before test_name)
269 (string-append before "Disabled" test_name)))))
270 '(("net/net_test.go" "(.+)(TestShutdownUnix.+)")
271 ("net/dial_test.go" "(.+)(TestDialTimeout.+)")
272 ("os/os_test.go" "(.+)(TestHostname.+)")
273 ("time/format_test.go" "(.+)(TestParseInSydney.+)")
274 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
275 ("os/exec/exec_test.go" "(.+)(TestEcho.+)")
276 ("os/exec/exec_test.go" "(.+)(TestCommandRelativeName.+)")
277 ("os/exec/exec_test.go" "(.+)(TestCatStdin.+)")
278 ("os/exec/exec_test.go" "(.+)(TestCatGoodAndBadFile.+)")
279 ("os/exec/exec_test.go" "(.+)(TestExitStatus.+)")
280 ("os/exec/exec_test.go" "(.+)(TestPipes.+)")
281 ("os/exec/exec_test.go" "(.+)(TestStdinClose.+)")
282 ("os/exec/exec_test.go" "(.+)(TestIgnorePipeErrorOnSuccess.+)")
283 ("syscall/syscall_unix_test.go" "(.+)(TestPassFD\\(.+)")
284 ("os/exec/exec_test.go" "(.+)(TestExtraFiles/areturn.+)")
285 ("cmd/go/go_test.go" "(.+)(TestCoverageWithCgo.+)")
286 ("os/exec/exec_test.go" "(.+)(TestOutputStderrCapture.+)")
287 ("os/exec/exec_test.go" "(.+)(TestExtraFiles.+)")
288 ("os/exec/exec_test.go" "(.+)(TestExtraFilesRace.+)")
289 ("net/lookup_test.go" "(.+)(TestLookupPort.+)")
290 ("syscall/exec_linux_test.go"
291 "(.+)(TestCloneNEWUSERAndRemapNoRootDisableSetgroups.+)")))
293 (substitute* "../misc/cgo/testsanitizers/test.bash"
294 (("(CC=)cc" all var) (string-append var "gcc")))
296 ;; fix shebang for testar script
297 ;; note the target script is generated at build time.
298 (substitute* "../misc/cgo/testcarchive/carchive_test.go"
299 (("#!/usr/bin/env") (string-append "#!" (which "env"))))
301 ;; Escape braces in test data to workaround test failure. For
303 ;; https://github.com/golang/go/issues/20007
304 ;; FIXME: remove this once we upgrade to 1.9
305 (substitute* "cmd/vet/testdata/copylock_func.go"
306 (("struct\\{lock sync.Mutex\\}") "struct\\{lock sync.Mutex\\}"))
308 (substitute* "net/lookup_unix.go"
309 (("/etc/protocols") (string-append net-base "/etc/protocols")))
310 (substitute* "net/port_unix.go"
311 (("/etc/services") (string-append net-base "/etc/services")))
312 (substitute* "time/zoneinfo_unix.go"
313 (("/usr/share/zoneinfo/") tzdata-path))
314 (substitute* (find-files "cmd" "\\.go")
315 (("/lib(64)?/ld-linux.*\\.so\\.[0-9]") loader))
317 (add-before 'build 'set-bootstrap-variables
318 (lambda* (#:key outputs inputs #:allow-other-keys)
319 ;; Tell the build system where to find the bootstrap Go.
320 (let ((go (assoc-ref inputs "go"))
321 (out (assoc-ref outputs "out")))
322 (setenv "GOROOT_BOOTSTRAP" go)
324 (string-append out "/bin:"
325 (dirname (getcwd)) "/bin:"
328 ;; XXX: The following variables seem unrelated.
329 (setenv "GOGC" "400")
330 (setenv "GO_TEST_TIMEOUT_SCALE" "9999")
334 (lambda* (#:key inputs outputs #:allow-other-keys)
335 ;; FIXME: Some of the .a files are not bit-reproducible.
336 (let* ((output (assoc-ref outputs "out")))
337 (setenv "CC" (which "gcc"))
338 (setenv "GOOS" "linux")
339 (setenv "GOROOT" (dirname (getcwd)))
340 (setenv "GOROOT_FINAL" output)
341 (setenv "CGO_ENABLED" "1")
342 (zero? (system* "sh" "all.bash")))))
345 ;; TODO: Most of this could be factorized with Go 1.4.
346 (lambda* (#:key outputs #:allow-other-keys)
347 (let* ((output (assoc-ref outputs "out"))
348 (doc_out (assoc-ref outputs "doc"))
349 (docs (string-append doc_out "/share/doc/" ,name "-" ,version))
351 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
352 (delete-file-recursively "../pkg/bootstrap")
355 (copy-recursively "../test" (string-append src "/test"))
356 (delete-file-recursively "../test")
358 (copy-recursively "../api" (string-append docs "/api"))
359 (delete-file-recursively "../api")
360 (copy-recursively "../doc" (string-append docs "/doc"))
361 (delete-file-recursively "../doc")
365 (let* ((filein (string-append "../" file))
366 (fileout (string-append docs "/" file)))
367 (copy-file filein fileout)
368 (delete-file filein)))
369 ;; Note the slightly different file names compared to 1.4.
370 '("README.md" "CONTRIBUTORS" "AUTHORS" "PATENTS"
371 "LICENSE" "VERSION" "CONTRIBUTING.md" "robots.txt"))
373 (copy-recursively "../" output))))))))
376 ,@(package-native-inputs go-1.4)))
377 (supported-systems %supported-systems)))
379 (define-public go go-1.9)