download: Don't report the progress too fast.
[jackhill/guix/guix.git] / gnu / packages / commencement.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
4 ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
5 ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
7 ;;;
8 ;;; This file is part of 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 commencement)
24 #:use-module ((guix licenses)
25 #:select (gpl3+ lgpl2.0+ public-domain))
26 #:use-module (gnu packages)
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages gcc)
31 #:use-module (gnu packages m4)
32 #:use-module (gnu packages indent)
33 #:use-module (gnu packages file)
34 #:use-module (gnu packages gawk)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages flex)
37 #:use-module (gnu packages guile)
38 #:use-module (gnu packages gettext)
39 #:use-module (gnu packages multiprecision)
40 #:use-module (gnu packages compression)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages linux)
43 #:use-module (gnu packages hurd)
44 #:use-module (gnu packages texinfo)
45 #:use-module (gnu packages pkg-config)
46 #:use-module (guix packages)
47 #:use-module (guix download)
48 #:use-module (guix build-system gnu)
49 #:use-module (guix build-system trivial)
50 #:use-module (guix utils)
51 #:use-module (srfi srfi-1)
52 #:use-module (srfi srfi-26)
53 #:use-module (ice-9 vlist)
54 #:use-module (ice-9 match)
55 #:use-module (ice-9 regex))
56
57 ;;; Commentary:
58 ;;;
59 ;;; This is the commencement, this is where things start. Before the
60 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
61 ;;; with the initial binaries. This module uses those bootstrap binaries to
62 ;;; actually build up the whole tool chain that make up the implicit inputs of
63 ;;; 'gnu-build-system'.
64 ;;;
65 ;;; To avoid circular dependencies, this module should not be imported
66 ;;; directly from anywhere.
67 ;;;
68 ;;; Code:
69
70 (define gnu-make-boot0
71 (package-with-bootstrap-guile
72 (package (inherit gnu-make)
73 (name "make-boot0")
74 (arguments
75 `(#:guile ,%bootstrap-guile
76 #:implicit-inputs? #f
77 #:tests? #f ; cannot run "make check"
78 ,@(substitute-keyword-arguments (package-arguments gnu-make)
79 ((#:phases phases)
80 `(modify-phases ,phases
81 (replace 'build
82 (lambda _
83 (zero? (system* "./build.sh"))))
84 (replace 'install
85 (lambda* (#:key outputs #:allow-other-keys)
86 (let* ((out (assoc-ref outputs "out"))
87 (bin (string-append out "/bin")))
88 (install-file "make" bin)))))))))
89 (native-inputs '()) ; no need for 'pkg-config'
90 (inputs %bootstrap-inputs))))
91
92 (define diffutils-boot0
93 (package-with-bootstrap-guile
94 (let ((p (package-with-explicit-inputs diffutils
95 `(("make" ,gnu-make-boot0)
96 ,@%bootstrap-inputs)
97 #:guile %bootstrap-guile)))
98 (package (inherit p)
99 (name "diffutils-boot0")
100 (arguments `(#:tests? #f ; the test suite needs diffutils
101 ,@(package-arguments p)))))))
102
103 (define findutils-boot0
104 (package-with-bootstrap-guile
105 (package-with-explicit-inputs (package
106 (inherit findutils)
107 (name "findutils-boot0"))
108 `(("make" ,gnu-make-boot0)
109 ("diffutils" ,diffutils-boot0) ; for tests
110 ,@%bootstrap-inputs)
111 (current-source-location)
112 #:guile %bootstrap-guile)))
113
114 (define file-boot0
115 (package-with-bootstrap-guile
116 (package-with-explicit-inputs (package/inherit file
117 (name "file-boot0"))
118 `(("make" ,gnu-make-boot0)
119 ,@%bootstrap-inputs)
120 (current-source-location)
121 #:guile %bootstrap-guile)))
122
123
124 (define %boot0-inputs
125 `(("make" ,gnu-make-boot0)
126 ("diffutils" ,diffutils-boot0)
127 ("findutils" ,findutils-boot0)
128 ("file" ,file-boot0)
129 ,@%bootstrap-inputs))
130
131 (define* (boot-triplet #:optional (system (%current-system)))
132 ;; Return the triplet used to create the cross toolchain needed in the
133 ;; first bootstrapping stage.
134 (nix-system->gnu-triplet system "guix"))
135
136 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
137 ;; toolchain actually targets the same OS and arch, but it has the advantage
138 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
139 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
140
141 (define binutils-boot0
142 (package-with-bootstrap-guile
143 (package/inherit binutils
144 (name "binutils-cross-boot0")
145 (arguments
146 `(#:guile ,%bootstrap-guile
147 #:implicit-inputs? #f
148
149 #:modules ((guix build gnu-build-system)
150 (guix build utils)
151 (ice-9 ftw)) ; for 'scandir'
152 #:phases (alist-cons-after
153 'install 'add-symlinks
154 (lambda* (#:key outputs #:allow-other-keys)
155 ;; The cross-gcc invokes 'as', 'ld', etc, without the
156 ;; triplet prefix, so add symlinks.
157 (let ((out (assoc-ref outputs "out"))
158 (triplet-prefix (string-append ,(boot-triplet) "-")))
159 (define (has-triplet-prefix? name)
160 (string-prefix? triplet-prefix name))
161 (define (remove-triplet-prefix name)
162 (substring name (string-length triplet-prefix)))
163 (with-directory-excursion (string-append out "/bin")
164 (for-each (lambda (name)
165 (symlink name (remove-triplet-prefix name)))
166 (scandir "." has-triplet-prefix?)))
167 #t))
168 %standard-phases)
169
170 ,@(substitute-keyword-arguments (package-arguments binutils)
171 ((#:configure-flags cf)
172 `(cons ,(string-append "--target=" (boot-triplet))
173 ,cf)))))
174 (inputs %boot0-inputs))))
175
176 (define libstdc++-boot0
177 ;; GCC's libcc1 is always built as a shared library (the top-level
178 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
179 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
180 ;; C++14 features missing in our bootstrap compiler.
181 (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc-4.9))))
182 (package
183 (inherit lib)
184 (name "libstdc++-boot0")
185 (arguments
186 `(#:guile ,%bootstrap-guile
187 #:implicit-inputs? #f
188
189 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
190 #:validate-runpath? #f
191
192 ,@(package-arguments lib)))
193 (inputs %boot0-inputs)
194 (native-inputs '()))))
195
196 (define gcc-boot0
197 (package-with-bootstrap-guile
198 (package (inherit gcc)
199 (name "gcc-cross-boot0")
200 (arguments
201 `(#:guile ,%bootstrap-guile
202 #:implicit-inputs? #f
203 #:modules ((guix build gnu-build-system)
204 (guix build utils)
205 (ice-9 regex)
206 (srfi srfi-1)
207 (srfi srfi-26))
208 ,@(substitute-keyword-arguments (package-arguments gcc)
209 ((#:configure-flags flags)
210 `(append (list ,(string-append "--target=" (boot-triplet))
211
212 ;; No libc yet.
213 "--without-headers"
214
215 ;; Disable features not needed at this stage.
216 "--disable-shared"
217 "--enable-languages=c,c++"
218
219 ;; libstdc++ cannot be built at this stage
220 ;; ("Link tests are not allowed after
221 ;; GCC_NO_EXECUTABLES.").
222 "--disable-libstdc++-v3"
223
224 "--disable-threads"
225 "--disable-libmudflap"
226 "--disable-libatomic"
227 "--disable-libsanitizer"
228 "--disable-libitm"
229 "--disable-libgomp"
230 "--disable-libcilkrts"
231 "--disable-libvtv"
232 "--disable-libssp"
233 "--disable-libquadmath"
234 "--disable-decimal-float")
235 (remove (cut string-match
236 "--(with-system-zlib|enable-languages.*)" <>)
237 ,flags)))
238 ((#:phases phases)
239 `(alist-cons-after
240 'unpack 'unpack-gmp&co
241 (lambda* (#:key inputs #:allow-other-keys)
242 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
243 (mpfr (assoc-ref %build-inputs "mpfr-source"))
244 (mpc (assoc-ref %build-inputs "mpc-source")))
245
246 ;; To reduce the set of pre-built bootstrap inputs, build
247 ;; GMP & co. from GCC.
248 (for-each (lambda (source)
249 (or (zero? (system* "tar" "xvf" source))
250 (error "failed to unpack tarball"
251 source)))
252 (list gmp mpfr mpc))
253
254 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
255 ,@(map (lambda (lib)
256 ;; Drop trailing letters, as gmp-6.0.0a unpacks
257 ;; into gmp-6.0.0.
258 `(symlink ,(string-trim-right
259 (package-full-name lib)
260 char-set:letter)
261 ,(package-name lib)))
262 (list gmp-6.0 mpfr mpc))))
263 (alist-cons-after
264 'install 'symlink-libgcc_eh
265 (lambda* (#:key outputs #:allow-other-keys)
266 (let ((out (assoc-ref outputs "lib")))
267 ;; Glibc wants to link against libgcc_eh, so provide
268 ;; it.
269 (with-directory-excursion
270 (string-append out "/lib/gcc/"
271 ,(boot-triplet)
272 "/" ,(package-version gcc))
273 (symlink "libgcc.a" "libgcc_eh.a"))))
274 ,phases))))))
275
276 (inputs `(("gmp-source" ,(package-source gmp-6.0))
277 ("mpfr-source" ,(package-source mpfr))
278 ("mpc-source" ,(package-source mpc))
279 ("binutils-cross" ,binutils-boot0)
280
281 ;; The libstdc++ that libcc1 links against.
282 ("libstdc++" ,libstdc++-boot0)
283
284 ;; Call it differently so that the builder can check whether
285 ;; the "libc" input is #f.
286 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
287 ,@(alist-delete "libc" %boot0-inputs)))
288
289 ;; No need for Texinfo at this stage.
290 (native-inputs (alist-delete "texinfo"
291 (package-native-inputs gcc))))))
292
293 (define perl-boot0
294 (let ((perl (package
295 (inherit perl)
296 (name "perl-boot0")
297 (arguments
298 ;; At the very least, this must not depend on GCC & co.
299 (let ((args `(#:disallowed-references
300 ,(list %bootstrap-binutils))))
301 (substitute-keyword-arguments (package-arguments perl)
302 ((#:phases phases)
303 `(modify-phases ,phases
304 ;; Pthread support is missing in the bootstrap compiler
305 ;; (broken spec file), so disable it.
306 (add-before 'configure 'disable-pthreads
307 (lambda _
308 (substitute* "Configure"
309 (("^libswanted=(.*)pthread" _ before)
310 (string-append "libswanted=" before)))))))
311 ;; Do not configure with '-Dusethreads' since pthread
312 ;; support is missing.
313 ((#:configure-flags configure-flags)
314 `(delete "-Dusethreads" ,configure-flags))))))))
315 (package-with-bootstrap-guile
316 (package-with-explicit-inputs perl
317 %boot0-inputs
318 (current-source-location)
319 #:guile %bootstrap-guile))))
320
321 (define bison-boot0
322 ;; This Bison is needed to build MiG so we need it early in the process.
323 ;; It is also needed to rebuild Bash's parser, which is modified by
324 ;; its CVE patches. Remove it when it's no longer needed.
325 (let* ((m4 (package-with-bootstrap-guile
326 (package-with-explicit-inputs m4 %boot0-inputs
327 (current-source-location)
328 #:guile %bootstrap-guile)))
329 (bison (package (inherit bison)
330 (propagated-inputs `(("m4" ,m4)))
331 (inputs '()) ;remove Flex...
332 (arguments
333 '(#:tests? #f ;... and thus disable tests
334
335 ;; Zero timestamps in liby.a; this must be done
336 ;; explicitly here because the bootstrap Binutils don't
337 ;; do that (default is "cru".)
338 #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
339 "V=1"))))))
340 (package
341 (inherit (package-with-bootstrap-guile
342 (package-with-explicit-inputs bison %boot0-inputs
343 (current-source-location)
344 #:guile %bootstrap-guile)))
345 (native-inputs `(("perl" ,perl-boot0))))))
346
347 (define flex-boot0
348 ;; This Flex is needed to build MiG.
349 (let* ((flex (package (inherit flex)
350 (native-inputs `(("bison" ,bison-boot0)))
351 (propagated-inputs `(("m4" ,m4)))
352 (inputs `(("indent" ,indent)))
353 (arguments '(#:tests? #f)))))
354 (package-with-bootstrap-guile
355 (package-with-explicit-inputs flex %boot0-inputs
356 (current-source-location)
357 #:guile %bootstrap-guile))))
358
359 (define (linux-libre-headers-boot0)
360 "Return Linux-Libre header files for the bootstrap environment."
361 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
362 ;; between (gnu packages linux) and this module.
363 (package-with-bootstrap-guile
364 (package (inherit linux-libre-headers)
365 (arguments `(#:guile ,%bootstrap-guile
366 #:implicit-inputs? #f
367 ,@(package-arguments linux-libre-headers)))
368 (native-inputs
369 `(("perl" ,perl-boot0)
370 ,@%boot0-inputs)))))
371
372 (define gnumach-headers-boot0
373 (package-with-bootstrap-guile
374 (package-with-explicit-inputs gnumach-headers
375 %boot0-inputs
376 (current-source-location)
377 #:guile %bootstrap-guile)))
378
379 (define mig-boot0
380 (let* ((mig (package (inherit mig)
381 (native-inputs `(("bison" ,bison-boot0)
382 ("flex" ,flex-boot0)))
383 (inputs `(("flex" ,flex-boot0)))
384 (arguments
385 `(#:configure-flags
386 `(,(string-append "LDFLAGS=-Wl,-rpath="
387 (assoc-ref %build-inputs "flex") "/lib/")))))))
388 (package-with-bootstrap-guile
389 (package-with-explicit-inputs mig %boot0-inputs
390 (current-source-location)
391 #:guile %bootstrap-guile))))
392
393 (define hurd-headers-boot0
394 (let ((hurd-headers (package (inherit hurd-headers)
395 (native-inputs `(("mig" ,mig-boot0)))
396 (inputs '()))))
397 (package-with-bootstrap-guile
398 (package-with-explicit-inputs hurd-headers %boot0-inputs
399 (current-source-location)
400 #:guile %bootstrap-guile))))
401
402 (define hurd-minimal-boot0
403 (let ((hurd-minimal (package (inherit hurd-minimal)
404 (native-inputs `(("mig" ,mig-boot0)))
405 (inputs '()))))
406 (package-with-bootstrap-guile
407 (package-with-explicit-inputs hurd-minimal %boot0-inputs
408 (current-source-location)
409 #:guile %bootstrap-guile))))
410
411 (define (hurd-core-headers-boot0)
412 "Return the Hurd and Mach headers as well as initial Hurd libraries for
413 the bootstrap environment."
414 (package-with-bootstrap-guile
415 (package (inherit hurd-core-headers)
416 (arguments `(#:guile ,%bootstrap-guile
417 ,@(package-arguments hurd-core-headers)))
418 (inputs
419 `(("gnumach-headers" ,gnumach-headers-boot0)
420 ("hurd-headers" ,hurd-headers-boot0)
421 ("hurd-minimal" ,hurd-minimal-boot0)
422 ,@%boot0-inputs)))))
423
424 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
425 (match system
426 ("i586-gnu" (hurd-core-headers-boot0))
427 (_ (linux-libre-headers-boot0))))
428
429 (define texinfo-boot0
430 ;; Texinfo used to build libc's manual.
431 ;; We build without ncurses because it fails to build at this stage, and
432 ;; because we don't need the stand-alone Info reader.
433 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
434 (let ((texinfo (package (inherit texinfo)
435 (native-inputs '())
436 (inputs `(("perl" ,perl-boot0)))
437
438 ;; Some of Texinfo 6.1's tests would fail with "Couldn't
439 ;; set UTF-8 character type in locale" but we don't have a
440 ;; UTF-8 locale at this stage, so skip them.
441 (arguments '(#:tests? #f)))))
442 (package-with-bootstrap-guile
443 (package-with-explicit-inputs texinfo %boot0-inputs
444 (current-source-location)
445 #:guile %bootstrap-guile))))
446
447 (define ld-wrapper-boot0
448 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
449 ;; in their RUNPATH, otherwise validate-runpath will fail.
450 (make-ld-wrapper "ld-wrapper-boot0"
451 #:target boot-triplet
452 #:binutils binutils-boot0
453 #:guile %bootstrap-guile
454 #:bash (car (assoc-ref %boot0-inputs "bash"))))
455
456 (define %boot1-inputs
457 ;; 2nd stage inputs.
458 `(("gcc" ,gcc-boot0)
459 ("ld-wrapper-cross" ,ld-wrapper-boot0)
460 ("binutils-cross" ,binutils-boot0)
461 ,@(alist-delete "binutils" %boot0-inputs)))
462
463 (define glibc-final-with-bootstrap-bash
464 ;; The final libc, "cross-built". If everything went well, the resulting
465 ;; store path has no dependencies. Actually, the really-final libc is
466 ;; built just below; the only difference is that this one uses the
467 ;; bootstrap Bash.
468 (package-with-bootstrap-guile
469 (package/inherit glibc
470 (name "glibc-intermediate")
471 (arguments
472 `(#:guile ,%bootstrap-guile
473 #:implicit-inputs? #f
474
475 ,@(substitute-keyword-arguments (package-arguments glibc)
476 ((#:configure-flags flags)
477 `(append (list ,(string-append "--host=" (boot-triplet))
478 ,(string-append "--build="
479 (nix-system->gnu-triplet))
480
481 ;; Build Sun/ONC RPC support. In particular,
482 ;; install rpc/*.h.
483 "--enable-obsolete-rpc")
484 ,flags))
485 ((#:phases phases)
486 `(alist-cons-before
487 'configure 'pre-configure
488 (lambda* (#:key inputs #:allow-other-keys)
489 ;; Don't clobber CPATH with the bootstrap libc.
490 (setenv "NATIVE_CPATH" (getenv "CPATH"))
491 (unsetenv "CPATH")
492
493 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
494 ,@(if (hurd-triplet? (%current-system))
495 `((substitute* "libpthread/Makefile"
496 (("LDLIBS-pthread.so =.*")
497 (string-append "LDLIBS-pthread.so = "
498 (assoc-ref %build-inputs "kernel-headers")
499 "/lib/libihash.a\n"))))
500 '())
501
502 ;; 'rpcgen' needs native libc headers to be built.
503 (substitute* "sunrpc/Makefile"
504 (("sunrpc-CPPFLAGS =.*" all)
505 (string-append "CPATH = $(NATIVE_CPATH)\n"
506 "export CPATH\n"
507 all "\n"))))
508 ,phases)))))
509 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
510 (native-inputs
511 `(("texinfo" ,texinfo-boot0)
512 ("perl" ,perl-boot0)))
513 (inputs
514 `(;; The boot inputs. That includes the bootstrap libc. We don't want
515 ;; it in $CPATH, hence the 'pre-configure' phase above.
516 ,@%boot1-inputs
517
518 ;; A native MiG is needed to build Glibc on Hurd.
519 ,@(if (hurd-triplet? (%current-system))
520 `(("mig" ,mig-boot0))
521 '())
522
523 ;; A native GCC is needed to build `cross-rpcgen'.
524 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
525
526 ;; Here, we use the bootstrap Bash, which is not satisfactory
527 ;; because we don't want to depend on bootstrap tools.
528 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
529
530 (define (cross-gcc-wrapper gcc binutils glibc bash)
531 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
532 that makes it available under the native tool names."
533 (package (inherit gcc)
534 (name (string-append (package-name gcc) "-wrapped"))
535 (source #f)
536 (build-system trivial-build-system)
537 (outputs '("out"))
538 (arguments
539 `(#:guile ,%bootstrap-guile
540 #:modules ((guix build utils))
541 #:builder (begin
542 (use-modules (guix build utils))
543
544 (let* ((binutils (assoc-ref %build-inputs "binutils"))
545 (gcc (assoc-ref %build-inputs "gcc"))
546 (libc (assoc-ref %build-inputs "libc"))
547 (bash (assoc-ref %build-inputs "bash"))
548 (out (assoc-ref %outputs "out"))
549 (bindir (string-append out "/bin"))
550 (triplet ,(boot-triplet)))
551 (define (wrap-program program)
552 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
553 ;; needs to be told where to find the crt files and
554 ;; the dynamic linker.
555 (call-with-output-file program
556 (lambda (p)
557 (format p "#!~a/bin/bash
558 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
559 bash
560 gcc triplet program
561 libc libc
562 ,(glibc-dynamic-linker))))
563
564 (chmod program #o555))
565
566 (mkdir-p bindir)
567 (with-directory-excursion bindir
568 (for-each (lambda (tool)
569 (symlink (string-append binutils "/bin/"
570 triplet "-" tool)
571 tool))
572 '("ar" "ranlib"))
573 (for-each wrap-program '("gcc" "g++")))))))
574 (native-inputs
575 `(("binutils" ,binutils)
576 ("gcc" ,gcc)
577 ("libc" ,glibc)
578 ("bash" ,bash)))
579 (inputs '())))
580
581 (define static-bash-for-glibc
582 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
583 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
584 glibc-final-with-bootstrap-bash
585 (car (assoc-ref %boot1-inputs "bash"))))
586 (bash (package (inherit static-bash)
587 (arguments
588 `(#:guile ,%bootstrap-guile
589 ,@(package-arguments static-bash)))))
590 (inputs `(("gcc" ,gcc)
591 ("libc" ,glibc-final-with-bootstrap-bash)
592 ,@(fold alist-delete %boot1-inputs
593 '("gcc" "libc")))))
594 (package-with-bootstrap-guile
595 (package-with-explicit-inputs bash inputs
596 (current-source-location)
597 #:guile %bootstrap-guile))))
598
599 (define gettext-boot0
600 ;; A minimal gettext used during bootstrap.
601 (let ((gettext-minimal
602 (package (inherit gettext-minimal)
603 (name "gettext-boot0")
604 (inputs '()) ;zero dependencies
605 (arguments
606 (substitute-keyword-arguments
607 `(#:tests? #f
608 ,@(package-arguments gettext-minimal))
609 ((#:phases phases)
610 `(modify-phases ,phases
611 ;; Build only the tools.
612 (add-after 'unpack 'chdir
613 (lambda _
614 (chdir "gettext-tools")))
615
616 ;; Some test programs require pthreads, which we don't have.
617 (add-before 'configure 'no-test-programs
618 (lambda _
619 (substitute* "tests/Makefile.in"
620 (("^PROGRAMS =.*$")
621 "PROGRAMS =\n"))
622 #t))
623
624 ;; Don't try to link against libexpat.
625 (delete 'link-expat)
626 (delete 'patch-tests))))))))
627 (package-with-bootstrap-guile
628 (package-with-explicit-inputs gettext-minimal
629 %boot1-inputs
630 (current-source-location)
631 #:guile %bootstrap-guile))))
632
633 (define glibc-final
634 ;; The final glibc, which embeds the statically-linked Bash built above.
635 (package/inherit glibc-final-with-bootstrap-bash
636 (name "glibc")
637 (inputs `(("static-bash" ,static-bash-for-glibc)
638 ,@(alist-delete
639 "static-bash"
640 (package-inputs glibc-final-with-bootstrap-bash))))
641
642 ;; This time we need 'msgfmt' to install all the libc.mo files.
643 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
644 ("gettext" ,gettext-boot0)))
645
646 ;; The final libc only refers to itself, but the 'debug' output contains
647 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
648 ;; if 'allowed-references' were per-output.
649 (arguments
650 `(#:allowed-references
651 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
652 static-bash-for-glibc
653 (package-outputs glibc-final-with-bootstrap-bash))
654
655 ,@(package-arguments glibc-final-with-bootstrap-bash)))))
656
657 (define gcc-boot0-wrapped
658 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
659 ;; non-cross names.
660 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
661 (car (assoc-ref %boot1-inputs "bash"))))
662
663 (define %boot2-inputs
664 ;; 3rd stage inputs.
665 `(("libc" ,glibc-final)
666 ("gcc" ,gcc-boot0-wrapped)
667 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
668
669 (define binutils-final
670 (package-with-bootstrap-guile
671 (package/inherit binutils
672 (arguments
673 `(#:guile ,%bootstrap-guile
674 #:implicit-inputs? #f
675 #:allowed-references ("out" ,glibc-final)
676 ,@(package-arguments binutils)))
677 (inputs %boot2-inputs))))
678
679 (define libstdc++
680 ;; Intermediate libstdc++ that will allow us to build the final GCC
681 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
682 ;; TODO: Write in terms of 'make-libstdc++'.
683 (package-with-bootstrap-guile
684 (package (inherit gcc)
685 (name "libstdc++")
686 (arguments
687 `(#:guile ,%bootstrap-guile
688 #:implicit-inputs? #f
689 #:allowed-references ("out")
690 #:out-of-source? #t
691 #:phases (alist-cons-before
692 'configure 'chdir
693 (lambda _
694 (chdir "libstdc++-v3"))
695 %standard-phases)
696 #:configure-flags `("--disable-shared"
697 "--disable-libstdcxx-threads"
698 "--disable-libstdcxx-pch"
699 ,(string-append "--with-gxx-include-dir="
700 (assoc-ref %outputs "out")
701 "/include"
702 ;; "/include/c++/"
703 ;; ,(package-version gcc)
704 ))))
705 (outputs '("out"))
706 (inputs %boot2-inputs)
707 (native-inputs '())
708 (propagated-inputs '())
709 (synopsis "GNU C++ standard library (intermediate)"))))
710
711 (define zlib-final
712 ;; Zlib used by GCC-FINAL.
713 (package-with-bootstrap-guile
714 (package
715 (inherit zlib)
716 (arguments
717 `(#:guile ,%bootstrap-guile
718 #:implicit-inputs? #f
719 #:allowed-references ("out" ,glibc-final)
720 ,@(package-arguments zlib)))
721 (inputs %boot2-inputs))))
722
723 (define ld-wrapper-boot3
724 ;; A linker wrapper that uses the bootstrap Guile.
725 (make-ld-wrapper "ld-wrapper-boot3"
726 #:binutils binutils-final
727 #:guile %bootstrap-guile
728 #:bash (car (assoc-ref %boot2-inputs "bash"))))
729
730 (define gcc-final
731 ;; The final GCC.
732 (package (inherit gcc-boot0)
733 (name "gcc")
734
735 ;; XXX: Currently #:allowed-references applies to all the outputs but the
736 ;; "debug" output contains disallowed references, notably
737 ;; linux-libre-headers. Disable the debugging output to work around that.
738 (outputs (delete "debug" (package-outputs gcc-boot0)))
739
740 (arguments
741 `(#:guile ,%bootstrap-guile
742 #:implicit-inputs? #f
743
744 #:allowed-references ("out" "lib" ,zlib-final
745 ,glibc-final ,static-bash-for-glibc)
746
747 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
748 ;; reason, but it is not in their RUNPATH. This is a false
749 ;; positive, so turn it off.
750 #:validate-runpath? #f
751
752 ;; Build again GMP & co. within GCC's build process, because it's hard
753 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
754 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
755 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
756 ((#:configure-flags boot-flags)
757 (let loop ((args (package-arguments gcc)))
758 (match args
759 ((#:configure-flags normal-flags _ ...)
760 normal-flags)
761 ((_ rest ...)
762 (loop rest)))))
763 ((#:make-flags flags)
764 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
765 `(let ((zlib (assoc-ref %build-inputs "zlib")))
766 (map (lambda (flag)
767 (if (string-prefix? "LDFLAGS=" flag)
768 (string-append flag " -L"
769 (assoc-ref %build-inputs "libstdc++")
770 "/lib -L" zlib "/lib -Wl,-rpath="
771 zlib "/lib")
772 flag))
773 ,flags)))
774 ((#:phases phases)
775 `(alist-delete 'symlink-libgcc_eh ,phases)))))
776
777 ;; This time we want Texinfo, so we get the manual. Add
778 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
779 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
780 ;; scripts?).
781 (native-inputs `(("texinfo" ,texinfo-boot0)
782 ("static-bash" ,static-bash-for-glibc)
783 ,@(package-native-inputs gcc-boot0)))
784
785 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
786 ("mpfr-source" ,(package-source mpfr))
787 ("mpc-source" ,(package-source mpc))
788 ("ld-wrapper" ,ld-wrapper-boot3)
789 ("binutils" ,binutils-final)
790 ("libstdc++" ,libstdc++)
791 ("zlib" ,zlib-final)
792 ,@%boot2-inputs))))
793
794 (define %boot3-inputs
795 ;; 4th stage inputs.
796 `(("gcc" ,gcc-final)
797 ("ld-wrapper" ,ld-wrapper-boot3)
798 ,@(alist-delete "gcc" %boot2-inputs)))
799
800 (define bash-final
801 ;; Link with `-static-libgcc' to make sure we don't retain a reference
802 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
803 ;; on Readline and ncurses.
804 (let ((bash (package
805 (inherit bash-minimal)
806 (arguments
807 `(#:disallowed-references
808 ,(assoc-ref %boot3-inputs "coreutils&co")
809 ,@(package-arguments bash-minimal))))))
810 (package-with-bootstrap-guile
811 (package-with-explicit-inputs (static-libgcc-package bash)
812 %boot3-inputs
813 (current-source-location)
814 #:guile %bootstrap-guile))))
815
816 (define %boot4-inputs
817 ;; Now use the final Bash.
818 `(("bash" ,bash-final)
819 ,@(alist-delete "bash" %boot3-inputs)))
820
821 (define-public guile-final
822 ;; This package must be public because other modules refer to it. However,
823 ;; mark it as hidden so that 'fold-packages' ignores it.
824 (package-with-bootstrap-guile
825 (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
826 %boot4-inputs
827 (current-source-location)
828 #:guile %bootstrap-guile)))
829
830 (define glibc-utf8-locales-final
831 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
832 ;; by the build processes afterwards so their 'scm_to_locale_string' works
833 ;; with the full range of Unicode codepoints (remember
834 ;; 'scm_to_locale_string' is called every time a string is passed to a C
835 ;; function.)
836 (package
837 (inherit glibc-utf8-locales)
838 (inputs `(("glibc" ,glibc-final)
839 ("gzip"
840 ,(package-with-explicit-inputs gzip %boot4-inputs
841 (current-source-location)
842 #:guile %bootstrap-guile))))))
843
844 (define-public ld-wrapper
845 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
846 (make-ld-wrapper "ld-wrapper"
847 #:binutils binutils-final
848 #:guile guile-final
849 #:bash bash-final))
850
851 (define %boot5-inputs
852 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
853 ;; with an older libc, which cannot load the new locale format. See
854 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
855 `(("locales" ,glibc-utf8-locales-final)
856 ,@%boot4-inputs))
857
858 (define gnu-make-final
859 ;; The final GNU Make, which uses the final Guile.
860 (package-with-bootstrap-guile
861 (package-with-explicit-inputs gnu-make
862 `(("guile" ,guile-final)
863 ,@%boot5-inputs)
864 (current-source-location))))
865
866 (define coreutils-final
867 ;; The final Coreutils. Treat them specially because some packages, such as
868 ;; Findutils, keep a reference to the Coreutils they were built with.
869 (package-with-bootstrap-guile
870 (package-with-explicit-inputs coreutils
871 %boot5-inputs
872 (current-source-location)
873
874 ;; Use the final Guile, linked against the
875 ;; final libc with working iconv, so that
876 ;; 'substitute*' works well when touching
877 ;; test files in Gettext.
878 #:guile guile-final)))
879
880 (define grep-final
881 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
882 ;; built before gzip.
883 (package-with-bootstrap-guile
884 (package-with-explicit-inputs (package
885 (inherit grep)
886 (native-inputs `(("perl" ,perl-boot0))))
887 %boot5-inputs
888 (current-source-location)
889 #:guile guile-final)))
890
891 (define %boot6-inputs
892 ;; Now use the final Coreutils.
893 `(("coreutils" ,coreutils-final)
894 ("grep" ,grep-final)
895 ,@%boot5-inputs))
896
897 (define-public %final-inputs
898 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
899 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
900 ;; used for origins that have patches, thereby avoiding circular
901 ;; dependencies.
902 (let ((finalize (compose package-with-bootstrap-guile
903 (cut package-with-explicit-inputs <> %boot6-inputs
904 (current-source-location)))))
905 `(,@(map (match-lambda
906 ((name package)
907 (list name (finalize package))))
908 `(("tar" ,tar)
909 ("gzip" ,gzip)
910 ("bzip2" ,bzip2)
911 ("xz" ,xz)
912 ("file" ,file)
913 ("diffutils" ,diffutils)
914 ("patch" ,patch)
915 ("sed" ,sed)
916 ("findutils" ,findutils)
917 ("gawk" ,gawk)))
918 ("grep" ,grep-final)
919 ("coreutils" ,coreutils-final)
920 ("make" ,gnu-make-final)
921 ("bash" ,bash-final)
922 ("ld-wrapper" ,ld-wrapper)
923 ("binutils" ,binutils-final)
924 ("gcc" ,gcc-final)
925 ("libc" ,glibc-final)
926 ("locales" ,glibc-utf8-locales-final))))
927
928 (define-public canonical-package
929 (let ((name->package (fold (lambda (input result)
930 (match input
931 ((_ package)
932 (vhash-cons (package-full-name package)
933 package result))))
934 vlist-null
935 `(("guile" ,guile-final)
936 ,@%final-inputs))))
937 (lambda (package)
938 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
939 the implicit inputs of 'gnu-build-system', return that one, otherwise return
940 PACKAGE.
941
942 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
943 COREUTILS-FINAL vs. COREUTILS, etc."
944 ;; XXX: This doesn't handle dependencies of the final inputs, such as
945 ;; libunistring, GMP, etc.
946 (match (vhash-assoc (package-full-name package) name->package)
947 ((_ . canon)
948 ;; In general we want CANON, except if we're cross-compiling: CANON
949 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
950 ;; process, with dependencies on things that cannot be
951 ;; cross-compiled.
952 (if (%current-target-system)
953 package
954 canon))
955 (_ package)))))
956
957 \f
958 ;;;
959 ;;; GCC toolchain.
960 ;;;
961
962 (define (gcc-toolchain gcc)
963 "Return a complete toolchain for GCC."
964 (package
965 (name "gcc-toolchain")
966 (version (package-version gcc))
967 (source #f)
968 (build-system trivial-build-system)
969 (arguments
970 '(#:modules ((guix build union))
971 #:builder (begin
972 (use-modules (ice-9 match)
973 (srfi srfi-26)
974 (guix build union))
975
976 (let ((out (assoc-ref %outputs "out")))
977
978 (match %build-inputs
979 (((names . directories) ...)
980 (union-build out directories)))
981
982 (union-build (assoc-ref %outputs "debug")
983 (list (assoc-ref %build-inputs
984 "libc-debug")))))))
985
986 (native-search-paths (package-native-search-paths gcc))
987 (search-paths (package-search-paths gcc))
988
989 (license (package-license gcc))
990 (synopsis "Complete GCC tool chain for C/C++ development")
991 (description
992 "This package provides a complete GCC tool chain for C/C++ development to
993 be installed in user profiles. This includes GCC, as well as libc (headers
994 and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
995 (home-page "https://gcc.gnu.org/")
996 (outputs '("out" "debug"))
997
998 ;; The main raison d'être of this "meta-package" is (1) to conveniently
999 ;; install everything that we need, and (2) to make sure ld-wrapper comes
1000 ;; before Binutils' ld in the user's profile.
1001 (inputs `(("gcc" ,gcc)
1002 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
1003 ("binutils" ,binutils-final)
1004 ("libc" ,glibc-final)
1005 ("libc-debug" ,glibc-final "debug")))))
1006
1007 (define-public gcc-toolchain-4.8
1008 (gcc-toolchain gcc-4.8))
1009
1010 (define-public gcc-toolchain-4.9
1011 (gcc-toolchain gcc-4.9))
1012
1013 (define-public gcc-toolchain-5
1014 (gcc-toolchain gcc-final))
1015
1016 (define-public gcc-toolchain-6
1017 (gcc-toolchain gcc-6))
1018
1019 (define-public gcc-toolchain-7
1020 (gcc-toolchain gcc-7))
1021
1022 ;;; commencement.scm ends here