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