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 ;;; 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>
10 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
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
54 (uri (string-append "https://storage.googleapis.com/golang/"
55 name version ".src.tar.gz"))
58 "0na9yqilzpvq0bjndbibfp07wr796gf252y471cip10bbdqgqiwr"))))
59 (build-system gnu-build-system)
64 `(#:modules ((ice-9 match)
65 (guix build gnu-build-system)
68 #:tests? #f ; Tests are run by the all.bash script.
70 (modify-phases %standard-phases
72 (add-after 'patch-generated-file-shebangs 'chdir
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"))
82 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
83 (output (assoc-ref outputs "out")))
85 ;; Removing net/ tests, which fail when attempting to access
86 ;; network resources not present in the build container.
88 '("net/multicast_test.go" "net/parse_test.go"
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")
98 "ldflags := buildLdflags\n"
99 "ldflags = append(ldflags, \"-r\")\n"
100 "ldflags = append(ldflags, \"" gcclib "\")\n")))
102 (substitute* "os/os_test.go"
103 (("/usr/bin") (getcwd))
104 (("/bin/pwd") (which "pwd")))
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.
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.+)")
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.+)")
125 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
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.+)")))
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))
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)
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")
156 (zero? (system* "sh" "all.bash")))))
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)))
167 (copy-recursively "../test" (string-append tests "/test"))
168 (delete-file-recursively "../test")
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")
175 (for-each (lambda (file)
176 (let ((file (string-append "../" file)))
177 (install-file file docs)
179 '("README" "CONTRIBUTORS" "AUTHORS" "PATENTS"
180 "LICENSE" "VERSION" "robots.txt"))
181 (copy-recursively "../" output)
186 ("gcc:lib" ,gcc "lib")))
188 `(("pkg-config" ,%pkg-config)
190 ("net-base" ,net-base)
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
196 programming language. Designed primarily for systems programming, it is a
197 compiled, statically typed language in the tradition of C and C++, with
198 garbage collection, various safety features and in the style of communicating
199 sequential processes (CSP) concurrent programming features added.")
200 (license license:bsd-3)))
202 (define-public go-1.8
210 (uri (string-append "https://storage.googleapis.com/golang/"
211 name version ".src.tar.gz"))
214 "0mqf8ydxdx1pwmrs8p8wl5y1qrplzxmxzgb6vkghy4l67z0g9nik"))))
216 (substitute-keyword-arguments (package-arguments go-1.4)
218 `(modify-phases ,phases
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"))
227 (string-append (assoc-ref inputs "tzdata") "/share/zoneinfo"))
228 (output (assoc-ref outputs "out")))
230 ;; Removing net/ tests, which fail when attempting to access
231 ;; network resources not present in the build container.
232 (for-each delete-file
233 '("net/listen_test.go"
235 "net/cgo_unix_test.go"))
237 (substitute* "os/os_test.go"
238 (("/usr/bin") (getcwd))
239 (("/bin/pwd") (which "pwd"))
240 (("/bin/sh") (which "sh")))
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 "\""
250 (("ldflags = setextld\\(ldflags, compiler\\)")
252 "ldflags = setextld(ldflags, compiler)\n"
253 "ldflags = append(ldflags, \"-r\")\n"
254 "ldflags = append(ldflags, \"" gcclib "\")\n"))
257 "\"-Wl,-rpath=" gcclib "\", \"-lgcc_s\", ")))
259 ;; Disable failing tests: these tests attempt to access
260 ;; commands or network resources which are neither available or
261 ;; necessary for the build to succeed.
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.+)")
272 ("time/format_test.go" "(.+)(TestParseInLocation.+)")
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"
289 "(.+)(TestCloneNEWUSERAndRemapNoRootDisableSetgroups.+)")))
291 (substitute* "../misc/cgo/testsanitizers/test.bash"
292 (("(CC=)cc" all var) (string-append var "gcc")))
294 ;; fix shebang for testar script
295 ;; note the target script is generated at build time.
296 (substitute* "../misc/cgo/testcarchive/carchive_test.go"
297 (("#!/usr/bin/env") (string-append "#!" (which "env"))))
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))
305 (substitute* (find-files "cmd" "\\.go")
306 (("/lib(64)?/ld-linux.*\\.so\\.[0-9]") loader))
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)
315 (string-append out "/bin:"
316 (dirname (getcwd)) "/bin:"
319 ;; XXX: The following variables seem unrelated.
320 (setenv "GOGC" "400")
321 (setenv "GO_TEST_TIMEOUT_SCALE" "9999")
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")))))
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))
342 (assoc-ref outputs "tests") "/share/" ,name "-" ,version)))
343 (delete-file-recursively "../pkg/bootstrap")
346 (copy-recursively "../test" (string-append src "/test"))
347 (delete-file-recursively "../test")
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")
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"))
364 (copy-recursively "../" output))))))))
367 ,@(package-native-inputs go-1.4)))))
369 (define-public go go-1.8)