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