1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 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, 2018 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; This file is part of GNU Guix.
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.
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.
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/>.
24 (define-module (gnu packages commencement)
25 #:use-module ((guix licenses)
26 #:select (gpl3+ lgpl2.0+ public-domain))
27 #:use-module (gnu packages)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bash)
31 #:use-module (gnu packages gcc)
32 #:use-module (gnu packages m4)
33 #:use-module (gnu packages code)
34 #:use-module (gnu packages file)
35 #:use-module (gnu packages gawk)
36 #:use-module (gnu packages bison)
37 #:use-module (gnu packages flex)
38 #:use-module (gnu packages guile)
39 #:use-module (gnu packages gettext)
40 #:use-module (gnu packages multiprecision)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages perl)
43 #:use-module (gnu packages linux)
44 #:use-module (gnu packages hurd)
45 #:use-module (gnu packages texinfo)
46 #:use-module (gnu packages pkg-config)
47 #:use-module (guix packages)
48 #:use-module (guix download)
49 #:use-module (guix build-system gnu)
50 #:use-module (guix build-system trivial)
51 #:use-module (guix memoization)
52 #:use-module (guix utils)
53 #:use-module (srfi srfi-1)
54 #:use-module (srfi srfi-26)
55 #:use-module (ice-9 vlist)
56 #:use-module (ice-9 match)
57 #:use-module (ice-9 regex)
58 #:export (make-gcc-toolchain))
62 ;;; This is the commencement, this is where things start. Before the
63 ;;; commencement, of course, there's the 'bootstrap' module, which provides us
64 ;;; with the initial binaries. This module uses those bootstrap binaries to
65 ;;; actually build up the whole tool chain that make up the implicit inputs of
66 ;;; 'gnu-build-system'.
68 ;;; To avoid circular dependencies, this module should not be imported
69 ;;; directly from anywhere.
71 ;;; Below, we frequently use "inherit" to create modified packages. The
72 ;;; reason why we use "inherit" instead of "package/inherit" is because we do
73 ;;; not want these commencement packages to inherit grafts. By definition,
74 ;;; these packages are not depended on at run time by any of the packages we
75 ;;; use. Thus it does not make sense to inherit grafts. Furthermore, those
76 ;;; grafts would often lead to extra overhead for users who would end up
77 ;;; downloading those "-boot0" packages just to build package replacements
78 ;;; that are in fact not going to be used.
82 (define gnu-make-boot0
83 (package-with-bootstrap-guile
84 (package (inherit gnu-make)
87 `(#:guile ,%bootstrap-guile
89 #:tests? #f ; cannot run "make check"
90 ,@(substitute-keyword-arguments (package-arguments gnu-make)
92 `(modify-phases ,phases
98 (lambda* (#:key outputs #:allow-other-keys)
99 (let* ((out (assoc-ref outputs "out"))
100 (bin (string-append out "/bin")))
101 (install-file "make" bin)
103 (native-inputs '()) ; no need for 'pkg-config'
104 (inputs %bootstrap-inputs))))
106 (define diffutils-boot0
107 (package-with-bootstrap-guile
108 (let ((p (package-with-explicit-inputs diffutils
109 `(("make" ,gnu-make-boot0)
111 #:guile %bootstrap-guile)))
113 (name "diffutils-boot0")
114 (arguments `(#:tests? #f ; the test suite needs diffutils
115 ,@(package-arguments p)))))))
117 (define findutils-boot0
118 (package-with-bootstrap-guile
119 (package-with-explicit-inputs (package
121 (name "findutils-boot0"))
122 `(("make" ,gnu-make-boot0)
123 ("diffutils" ,diffutils-boot0) ; for tests
125 (current-source-location)
126 #:guile %bootstrap-guile)))
129 (package-with-bootstrap-guile
130 (package-with-explicit-inputs (package
133 `(("make" ,gnu-make-boot0)
135 (current-source-location)
136 #:guile %bootstrap-guile)))
139 (define %boot0-inputs
140 `(("make" ,gnu-make-boot0)
141 ("diffutils" ,diffutils-boot0)
142 ("findutils" ,findutils-boot0)
144 ,@%bootstrap-inputs))
146 (define* (boot-triplet #:optional (system (%current-system)))
147 ;; Return the triplet used to create the cross toolchain needed in the
148 ;; first bootstrapping stage.
149 (nix-system->gnu-triplet system "guix"))
151 ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
152 ;; toolchain actually targets the same OS and arch, but it has the advantage
153 ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
154 ;; GCC-BOOT0 (below) is built without any reference to the target libc.
156 (define binutils-boot0
157 (package-with-bootstrap-guile
158 (package (inherit binutils)
159 (name "binutils-cross-boot0")
161 `(#:guile ,%bootstrap-guile
162 #:implicit-inputs? #f
164 #:modules ((guix build gnu-build-system)
166 (ice-9 ftw)) ; for 'scandir'
167 #:phases (modify-phases %standard-phases
168 (add-after 'install 'add-symlinks
169 (lambda* (#:key outputs #:allow-other-keys)
170 ;; The cross-gcc invokes 'as', 'ld', etc, without the
171 ;; triplet prefix, so add symlinks.
172 (let ((out (assoc-ref outputs "out"))
173 (triplet-prefix (string-append ,(boot-triplet) "-")))
174 (define (has-triplet-prefix? name)
175 (string-prefix? triplet-prefix name))
176 (define (remove-triplet-prefix name)
177 (substring name (string-length triplet-prefix)))
178 (with-directory-excursion (string-append out "/bin")
179 (for-each (lambda (name)
180 (symlink name (remove-triplet-prefix name)))
181 (scandir "." has-triplet-prefix?)))
184 ,@(substitute-keyword-arguments (package-arguments binutils)
185 ((#:configure-flags cf)
186 `(cons ,(string-append "--target=" (boot-triplet))
188 (inputs %boot0-inputs))))
190 ;; Use a "fixed" package source for this early libstdc++ variant so we can
191 ;; update GCC 4.9 without triggering a full rebuild.
192 (define gcc-for-libstdc++
196 (inherit (package-source gcc-4.9))
197 (patches (search-patches "gcc-4.9-libsanitizer-fix.patch"
198 "gcc-arm-bug-71399.patch"
199 "gcc-asan-missing-include.patch"
200 "gcc-libvtv-runpath.patch"
201 "gcc-fix-texi2pod.patch"))))))
203 (define libstdc++-boot0
204 ;; GCC's libcc1 is always built as a shared library (the top-level
205 ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
206 ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
207 ;; C++14 features missing in some of our bootstrap compilers.
208 (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc-for-libstdc++))))
211 (name "libstdc++-boot0")
213 `(#:guile ,%bootstrap-guile
214 #:implicit-inputs? #f
216 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
217 #:validate-runpath? #f
219 ,@(package-arguments lib)))
220 (inputs %boot0-inputs)
221 (native-inputs '()))))
224 (package-with-bootstrap-guile
225 (package (inherit gcc)
226 (name "gcc-cross-boot0")
228 `(#:guile ,%bootstrap-guile
229 #:implicit-inputs? #f
230 #:modules ((guix build gnu-build-system)
235 ,@(substitute-keyword-arguments (package-arguments gcc)
236 ((#:configure-flags flags)
237 `(append (list ,(string-append "--target=" (boot-triplet))
242 ;; Disable features not needed at this stage.
244 "--enable-languages=c,c++"
246 ;; libstdc++ cannot be built at this stage
247 ;; ("Link tests are not allowed after
248 ;; GCC_NO_EXECUTABLES.").
249 "--disable-libstdc++-v3"
252 "--disable-libmudflap"
253 "--disable-libatomic"
254 "--disable-libsanitizer"
257 "--disable-libcilkrts"
260 "--disable-libquadmath"
261 "--disable-decimal-float")
262 (remove (cut string-match
263 "--(with-system-zlib|enable-languages.*)" <>)
266 `(modify-phases ,phases
267 (add-after 'unpack 'unpack-gmp&co
268 (lambda* (#:key inputs #:allow-other-keys)
269 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
270 (mpfr (assoc-ref %build-inputs "mpfr-source"))
271 (mpc (assoc-ref %build-inputs "mpc-source")))
273 ;; To reduce the set of pre-built bootstrap inputs, build
274 ;; GMP & co. from GCC.
275 (for-each (lambda (source)
276 (invoke "tar" "xvf" source))
279 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
281 ;; Drop trailing letters, as gmp-6.0.0a unpacks
283 `(symlink ,(string-trim-right
284 (package-full-name lib "-")
286 ,(package-name lib)))
287 (list gmp-6.0 mpfr mpc))
289 (add-after 'install 'symlink-libgcc_eh
290 (lambda* (#:key outputs #:allow-other-keys)
291 (let ((out (assoc-ref outputs "lib")))
292 ;; Glibc wants to link against libgcc_eh, so provide
294 (with-directory-excursion
295 (string-append out "/lib/gcc/"
297 "/" ,(package-version gcc))
298 (symlink "libgcc.a" "libgcc_eh.a"))
301 (inputs `(("gmp-source" ,(package-source gmp-6.0))
302 ("mpfr-source" ,(package-source mpfr))
303 ("mpc-source" ,(package-source mpc))
304 ("binutils-cross" ,binutils-boot0)
306 ;; The libstdc++ that libcc1 links against.
307 ("libstdc++" ,libstdc++-boot0)
309 ;; Call it differently so that the builder can check whether
310 ;; the "libc" input is #f.
311 ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
312 ,@(alist-delete "libc" %boot0-inputs)))
314 ;; No need for the native-inputs to build the documentation at this stage.
315 (native-inputs `()))))
322 ;; At the very least, this must not depend on GCC & co.
323 (let ((args `(#:disallowed-references
324 ,(list %bootstrap-binutils))))
325 (substitute-keyword-arguments (package-arguments perl)
327 `(modify-phases ,phases
328 ;; Pthread support is missing in the bootstrap compiler
329 ;; (broken spec file), so disable it.
330 (add-before 'configure 'disable-pthreads
332 (substitute* "Configure"
333 (("^libswanted=(.*)pthread" _ before)
334 (string-append "libswanted=" before)))
336 ;; Do not configure with '-Dusethreads' since pthread
337 ;; support is missing.
338 ((#:configure-flags configure-flags)
339 `(delete "-Dusethreads" ,configure-flags))))))))
340 (package-with-bootstrap-guile
341 (package-with-explicit-inputs perl
343 (current-source-location)
344 #:guile %bootstrap-guile))))
347 ;; This Bison is needed to build MiG so we need it early in the process.
348 ;; It is also needed to rebuild Bash's parser, which is modified by
349 ;; its CVE patches. Remove it when it's no longer needed.
350 (let* ((m4 (package-with-bootstrap-guile
351 (package-with-explicit-inputs m4 %boot0-inputs
352 (current-source-location)
353 #:guile %bootstrap-guile)))
354 (bison (package (inherit bison)
355 (propagated-inputs `(("m4" ,m4)))
356 (inputs '()) ;remove Flex...
358 '(#:tests? #f ;... and thus disable tests
360 ;; Zero timestamps in liby.a; this must be done
361 ;; explicitly here because the bootstrap Binutils don't
362 ;; do that (default is "cru".)
363 #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
366 (inherit (package-with-bootstrap-guile
367 (package-with-explicit-inputs bison %boot0-inputs
368 (current-source-location)
369 #:guile %bootstrap-guile)))
370 (native-inputs `(("perl" ,perl-boot0))))))
373 ;; This Flex is needed to build MiG.
374 (let* ((flex (package (inherit flex)
375 (native-inputs `(("bison" ,bison-boot0)))
376 (propagated-inputs `(("m4" ,m4)))
377 (inputs `(("indent" ,indent)))
378 (arguments '(#:tests? #f)))))
379 (package-with-bootstrap-guile
380 (package-with-explicit-inputs flex %boot0-inputs
381 (current-source-location)
382 #:guile %bootstrap-guile))))
384 (define linux-libre-headers-boot0
386 "Return Linux-Libre header files for the bootstrap environment."
387 ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
388 ;; between (gnu packages linux) and this module. Additionally, memoize
389 ;; the result to play well with further memoization and code that relies
390 ;; on pointer identity; see <https://bugs.gnu.org/30155>.
391 (package-with-bootstrap-guile
392 (package (inherit linux-libre-headers)
393 (arguments `(#:guile ,%bootstrap-guile
394 #:implicit-inputs? #f
395 ,@(package-arguments linux-libre-headers)))
397 `(("perl" ,perl-boot0)
398 ,@%boot0-inputs))))))
400 (define gnumach-headers-boot0
401 (package-with-bootstrap-guile
402 (package-with-explicit-inputs gnumach-headers
404 (current-source-location)
405 #:guile %bootstrap-guile)))
408 (let* ((mig (package (inherit mig)
409 (native-inputs `(("bison" ,bison-boot0)
410 ("flex" ,flex-boot0)))
411 (inputs `(("flex" ,flex-boot0)))
414 `(,(string-append "LDFLAGS=-Wl,-rpath="
415 (assoc-ref %build-inputs "flex") "/lib/")))))))
416 (package-with-bootstrap-guile
417 (package-with-explicit-inputs mig %boot0-inputs
418 (current-source-location)
419 #:guile %bootstrap-guile))))
421 (define hurd-headers-boot0
422 (let ((hurd-headers (package (inherit hurd-headers)
423 (native-inputs `(("mig" ,mig-boot0)))
425 (package-with-bootstrap-guile
426 (package-with-explicit-inputs hurd-headers %boot0-inputs
427 (current-source-location)
428 #:guile %bootstrap-guile))))
430 (define hurd-minimal-boot0
431 (let ((hurd-minimal (package (inherit hurd-minimal)
432 (native-inputs `(("mig" ,mig-boot0)))
434 (package-with-bootstrap-guile
435 (package-with-explicit-inputs hurd-minimal %boot0-inputs
436 (current-source-location)
437 #:guile %bootstrap-guile))))
439 (define hurd-core-headers-boot0
441 "Return the Hurd and Mach headers as well as initial Hurd libraries for
442 the bootstrap environment."
443 (package-with-bootstrap-guile
444 (package (inherit hurd-core-headers)
445 (arguments `(#:guile ,%bootstrap-guile
446 ,@(package-arguments hurd-core-headers)))
448 `(("gnumach-headers" ,gnumach-headers-boot0)
449 ("hurd-headers" ,hurd-headers-boot0)
450 ("hurd-minimal" ,hurd-minimal-boot0)
451 ,@%boot0-inputs))))))
453 (define* (kernel-headers-boot0 #:optional (system (%current-system)))
455 ("i586-gnu" (hurd-core-headers-boot0))
456 (_ (linux-libre-headers-boot0))))
458 (define texinfo-boot0
459 ;; Texinfo used to build libc's manual.
460 ;; We build without ncurses because it fails to build at this stage, and
461 ;; because we don't need the stand-alone Info reader.
462 ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
463 (let ((texinfo (package (inherit texinfo)
465 (inputs `(("perl" ,perl-boot0)))
467 ;; Some of Texinfo 6.1's tests would fail with "Couldn't
468 ;; set UTF-8 character type in locale" but we don't have a
469 ;; UTF-8 locale at this stage, so skip them.
470 (arguments '(#:tests? #f)))))
471 (package-with-bootstrap-guile
472 (package-with-explicit-inputs texinfo %boot0-inputs
473 (current-source-location)
474 #:guile %bootstrap-guile))))
476 (define ld-wrapper-boot0
477 ;; We need this so binaries on Hurd will have libmachuser and libhurduser
478 ;; in their RUNPATH, otherwise validate-runpath will fail.
479 (make-ld-wrapper "ld-wrapper-boot0"
480 #:target boot-triplet
481 #:binutils binutils-boot0
482 #:guile %bootstrap-guile
483 #:bash (car (assoc-ref %boot0-inputs "bash"))))
485 (define %boot1-inputs
488 ("ld-wrapper-cross" ,ld-wrapper-boot0)
489 ("binutils-cross" ,binutils-boot0)
490 ,@(alist-delete "binutils" %boot0-inputs)))
492 (define glibc-final-with-bootstrap-bash
493 ;; The final libc, "cross-built". If everything went well, the resulting
494 ;; store path has no dependencies. Actually, the really-final libc is
495 ;; built just below; the only difference is that this one uses the
497 (package-with-bootstrap-guile
498 (package (inherit glibc)
499 (name "glibc-intermediate")
501 `(#:guile ,%bootstrap-guile
502 #:implicit-inputs? #f
504 ,@(substitute-keyword-arguments (package-arguments glibc)
505 ((#:configure-flags flags)
506 `(append (list ,(string-append "--host=" (boot-triplet))
507 ,(string-append "--build="
508 (nix-system->gnu-triplet))
510 ;; Build Sun/ONC RPC support. In particular,
512 "--enable-obsolete-rpc")
515 `(modify-phases ,phases
516 (add-before 'configure 'pre-configure
517 (lambda* (#:key inputs #:allow-other-keys)
518 ;; Don't clobber CPATH with the bootstrap libc.
519 (setenv "NATIVE_CPATH" (getenv "CPATH"))
522 ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
523 ,@(if (hurd-triplet? (%current-system))
524 `((substitute* "libpthread/Makefile"
525 (("LDLIBS-pthread.so =.*")
526 (string-append "LDLIBS-pthread.so = "
527 (assoc-ref %build-inputs "kernel-headers")
528 "/lib/libihash.a\n"))))
531 ;; 'rpcgen' needs native libc headers to be built.
532 (substitute* "sunrpc/Makefile"
533 (("sunrpc-CPPFLAGS =.*" all)
534 (string-append "CPATH = $(NATIVE_CPATH)\n"
538 (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
540 `(("bison" ,bison-boot0)
541 ("texinfo" ,texinfo-boot0)
542 ("perl" ,perl-boot0)))
544 `(;; The boot inputs. That includes the bootstrap libc. We don't want
545 ;; it in $CPATH, hence the 'pre-configure' phase above.
548 ;; A native MiG is needed to build Glibc on Hurd.
549 ,@(if (hurd-triplet? (%current-system))
550 `(("mig" ,mig-boot0))
553 ;; A native GCC is needed to build `cross-rpcgen'.
554 ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
556 ;; Here, we use the bootstrap Bash, which is not satisfactory
557 ;; because we don't want to depend on bootstrap tools.
558 ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
560 (define (cross-gcc-wrapper gcc binutils glibc bash)
561 "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
562 that makes it available under the native tool names."
563 (package (inherit gcc)
564 (name (string-append (package-name gcc) "-wrapped"))
566 (build-system trivial-build-system)
569 `(#:guile ,%bootstrap-guile
570 #:modules ((guix build utils))
572 (use-modules (guix build utils))
574 (let* ((binutils (assoc-ref %build-inputs "binutils"))
575 (gcc (assoc-ref %build-inputs "gcc"))
576 (libc (assoc-ref %build-inputs "libc"))
577 (bash (assoc-ref %build-inputs "bash"))
578 (out (assoc-ref %outputs "out"))
579 (bindir (string-append out "/bin"))
580 (triplet ,(boot-triplet)))
581 (define (wrap-program program)
582 ;; GCC-BOOT0 is a libc-less cross-compiler, so it
583 ;; needs to be told where to find the crt files and
584 ;; the dynamic linker.
585 (call-with-output-file program
587 (format p "#!~a/bin/bash
588 exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
592 ,(glibc-dynamic-linker))))
594 (chmod program #o555))
597 (with-directory-excursion bindir
598 (for-each (lambda (tool)
599 (symlink (string-append binutils "/bin/"
603 (for-each wrap-program '("gcc" "g++")))
607 `(("binutils" ,binutils)
613 (define static-bash-for-glibc
614 ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
615 (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
616 glibc-final-with-bootstrap-bash
617 (car (assoc-ref %boot1-inputs "bash"))))
619 (inherit static-bash)
621 (substitute-keyword-arguments
622 (package-arguments static-bash)
625 ((#:configure-flags flags '())
626 ;; Add a '-L' flag so that the pseudo-cross-ld of
627 ;; BINUTILS-BOOT0 can find libc.a.
629 (list (string-append "LDFLAGS=-static -L"
630 (assoc-ref %build-inputs
633 (inputs `(("gcc" ,gcc)
634 ("libc" ,glibc-final-with-bootstrap-bash)
635 ("libc:static" ,glibc-final-with-bootstrap-bash "static")
636 ,@(fold alist-delete %boot1-inputs
638 (package-with-bootstrap-guile
639 (package-with-explicit-inputs bash inputs
640 (current-source-location)
641 #:guile %bootstrap-guile))))
643 (define gettext-boot0
644 ;; A minimal gettext used during bootstrap.
645 (let ((gettext-minimal
646 (package (inherit gettext-minimal)
647 (name "gettext-boot0")
648 (inputs '()) ;zero dependencies
650 (substitute-keyword-arguments
652 ,@(package-arguments gettext-minimal))
654 `(modify-phases ,phases
655 ;; Build only the tools.
656 (add-after 'unpack 'chdir
658 (chdir "gettext-tools")
661 ;; Some test programs require pthreads, which we don't have.
662 (add-before 'configure 'no-test-programs
664 (substitute* "tests/Makefile.in"
669 ;; Don't try to link against libexpat.
671 (delete 'patch-tests))))))))
672 (package-with-bootstrap-guile
673 (package-with-explicit-inputs gettext-minimal
675 (current-source-location)
676 #:guile %bootstrap-guile))))
679 ;; The final glibc, which embeds the statically-linked Bash built above.
680 ;; Use 'package/inherit' so we get the 'replacement' of 'glibc', if any.
681 (let ((glibc (package-with-bootstrap-guile glibc)))
682 (package/inherit glibc
684 (inputs `(("static-bash" ,static-bash-for-glibc)
687 (package-inputs glibc-final-with-bootstrap-bash))))
689 ;; This time we need 'msgfmt' to install all the libc.mo files.
690 (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
691 ("gettext" ,gettext-boot0)))
694 (package-propagated-inputs glibc-final-with-bootstrap-bash))
696 ;; The final libc only refers to itself, but the 'debug' output contains
697 ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
698 ;; if 'allowed-references' were per-output.
700 `(#:allowed-references
701 ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
702 static-bash-for-glibc
703 (package-outputs glibc-final-with-bootstrap-bash))
705 ,@(package-arguments glibc-final-with-bootstrap-bash))))))
707 (define gcc-boot0-wrapped
708 ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
710 (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
711 (car (assoc-ref %boot1-inputs "bash"))))
713 (define %boot2-inputs
715 `(("libc" ,glibc-final)
716 ("libc:static" ,glibc-final "static")
717 ("gcc" ,gcc-boot0-wrapped)
718 ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
720 (define binutils-final
721 (package-with-bootstrap-guile
722 (package (inherit binutils)
724 `(#:guile ,%bootstrap-guile
725 #:implicit-inputs? #f
726 #:allowed-references ("out" ,glibc-final)
727 ,@(package-arguments binutils)))
728 (inputs %boot2-inputs))))
731 ;; Intermediate libstdc++ that will allow us to build the final GCC
732 ;; (remember that GCC-BOOT0 cannot build libstdc++.)
733 (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc))))
737 `(#:guile ,%bootstrap-guile
738 #:implicit-inputs? #f
739 #:allowed-references ("out")
741 ;; XXX: libstdc++.so NEEDs ld.so for some reason.
742 #:validate-runpath? #f
744 ;; All of the package arguments from 'make-libstdc++
745 ;; except for the configure-flags.
746 ,@(package-arguments lib)
747 #:configure-flags `("--disable-shared"
748 "--disable-libstdcxx-threads"
749 "--disable-libstdcxx-pch"
750 ,(string-append "--with-gxx-include-dir="
751 (assoc-ref %outputs "out")
754 (inputs %boot2-inputs)
755 (synopsis "GNU C++ standard library (intermediate)"))))
758 ;; Zlib used by GCC-FINAL.
759 (package-with-bootstrap-guile
763 `(#:guile ,%bootstrap-guile
764 #:implicit-inputs? #f
765 #:allowed-references ("out" ,glibc-final)
766 ,@(package-arguments zlib)))
767 (inputs %boot2-inputs))))
769 (define ld-wrapper-boot3
770 ;; A linker wrapper that uses the bootstrap Guile.
771 (make-ld-wrapper "ld-wrapper-boot3"
772 #:binutils binutils-final
773 #:guile %bootstrap-guile
774 #:bash (car (assoc-ref %boot2-inputs "bash"))))
778 (package (inherit gcc-boot0)
781 ;; XXX: Currently #:allowed-references applies to all the outputs but the
782 ;; "debug" output contains disallowed references, notably
783 ;; linux-libre-headers. Disable the debugging output to work around that.
784 (outputs (delete "debug" (package-outputs gcc-boot0)))
787 `(#:guile ,%bootstrap-guile
788 #:implicit-inputs? #f
790 #:allowed-references ("out" "lib" ,zlib-final
791 ,glibc-final ,static-bash-for-glibc)
793 ;; Things like libasan.so and libstdc++.so NEED ld.so for some
794 ;; reason, but it is not in their RUNPATH. This is a false
795 ;; positive, so turn it off.
796 #:validate-runpath? #f
798 ;; Build again GMP & co. within GCC's build process, because it's hard
799 ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
800 ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
801 ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
802 ((#:configure-flags boot-flags)
803 (let loop ((args (package-arguments gcc)))
805 ((#:configure-flags normal-flags _ ...)
809 ((#:make-flags flags)
810 ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
811 `(let ((zlib (assoc-ref %build-inputs "zlib")))
813 (if (string-prefix? "LDFLAGS=" flag)
814 (string-append flag " -L"
815 (assoc-ref %build-inputs "libstdc++")
816 "/lib -L" zlib "/lib -Wl,-rpath="
821 `(alist-delete 'symlink-libgcc_eh ,phases)))))
823 ;; This time we want Texinfo, so we get the manual. Add
824 ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
825 ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
827 (native-inputs `(("texinfo" ,texinfo-boot0)
828 ("perl" ,perl-boot0) ;for manpages
829 ("static-bash" ,static-bash-for-glibc)
830 ,@(package-native-inputs gcc-boot0)))
832 (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
833 ("mpfr-source" ,(package-source mpfr))
834 ("mpc-source" ,(package-source mpc))
835 ("ld-wrapper" ,ld-wrapper-boot3)
836 ("binutils" ,binutils-final)
837 ("libstdc++" ,libstdc++)
841 (define %boot3-inputs
844 ("ld-wrapper" ,ld-wrapper-boot3)
845 ,@(alist-delete "gcc" %boot2-inputs)))
848 ;; Link with `-static-libgcc' to make sure we don't retain a reference
849 ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
850 ;; on Readline and ncurses.
852 (inherit bash-minimal)
854 `(#:disallowed-references
855 ,(assoc-ref %boot3-inputs "coreutils&co")
856 ,@(package-arguments bash-minimal))))))
857 (package-with-bootstrap-guile
858 (package-with-explicit-inputs (static-libgcc-package bash)
860 (current-source-location)
861 #:guile %bootstrap-guile))))
863 (define %boot4-inputs
864 ;; Now use the final Bash.
865 `(("bash" ,bash-final)
866 ,@(alist-delete "bash" %boot3-inputs)))
868 (define-public guile-final
869 ;; This package must be public because other modules refer to it. However,
870 ;; mark it as hidden so that 'fold-packages' ignores it.
871 (package-with-bootstrap-guile
872 (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
874 (current-source-location)
875 #:guile %bootstrap-guile)))
877 (define glibc-utf8-locales-final
878 ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
879 ;; by the build processes afterwards so their 'scm_to_locale_string' works
880 ;; with the full range of Unicode codepoints (remember
881 ;; 'scm_to_locale_string' is called every time a string is passed to a C
884 (inherit glibc-utf8-locales)
885 (inputs `(("glibc" ,glibc-final)
887 ,(package-with-explicit-inputs gzip %boot4-inputs
888 (current-source-location)
889 #:guile %bootstrap-guile))))))
891 (define-public ld-wrapper
892 ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
893 (make-ld-wrapper "ld-wrapper"
894 #:binutils binutils-final
898 (define %boot5-inputs
899 ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
900 ;; with an older libc, which cannot load the new locale format. See
901 ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
902 `(("locales" ,glibc-utf8-locales-final)
905 (define gnu-make-final
906 ;; The final GNU Make, which uses the final Guile.
907 (package-with-bootstrap-guile
908 (package-with-explicit-inputs gnu-make
909 `(("guile" ,guile-final)
911 (current-source-location))))
913 (define coreutils-final
914 ;; The final Coreutils. Treat them specially because some packages, such as
915 ;; Findutils, keep a reference to the Coreutils they were built with.
916 (package-with-bootstrap-guile
917 (package-with-explicit-inputs coreutils
919 (current-source-location)
921 ;; Use the final Guile, linked against the
922 ;; final libc with working iconv, so that
923 ;; 'substitute*' works well when touching
924 ;; test files in Gettext.
925 #:guile guile-final)))
928 ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
929 ;; built before gzip.
930 (let ((grep (package-with-bootstrap-guile
931 (package-with-explicit-inputs grep %boot5-inputs
932 (current-source-location)
933 #:guile guile-final))))
934 (package/inherit grep
935 (inputs (alist-delete "pcre" (package-inputs grep)))
936 (native-inputs `(("perl" ,perl-boot0))))))
938 (define %boot6-inputs
939 ;; Now use the final Coreutils.
940 `(("coreutils" ,coreutils-final)
946 (let ((sed (package-with-bootstrap-guile
947 (package-with-explicit-inputs sed %boot6-inputs
948 (current-source-location)
949 #:guile guile-final))))
950 (package/inherit sed (native-inputs `(("perl" ,perl-boot0))))))
952 (define-public %final-inputs
953 ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
954 ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
955 ;; used for origins that have patches, thereby avoiding circular
957 (let ((finalize (compose package-with-bootstrap-guile
958 (cut package-with-explicit-inputs <> %boot6-inputs
959 (current-source-location)))))
960 `(,@(map (match-lambda
962 (list name (finalize package))))
968 ("diffutils" ,diffutils)
970 ("findutils" ,findutils)
974 ("coreutils" ,coreutils-final)
975 ("make" ,gnu-make-final)
977 ("ld-wrapper" ,ld-wrapper)
978 ("binutils" ,binutils-final)
980 ("libc" ,glibc-final)
981 ("libc:static" ,glibc-final "static")
982 ("locales" ,glibc-utf8-locales-final))))
984 (define-public canonical-package
985 (let ((name->package (fold (lambda (input result)
987 ((_ package . outputs)
988 (vhash-cons (package-full-name package)
991 `(("guile" ,guile-final)
994 "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
995 the implicit inputs of 'gnu-build-system', return that one, otherwise return
998 The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
999 COREUTILS-FINAL vs. COREUTILS, etc."
1000 ;; XXX: This doesn't handle dependencies of the final inputs, such as
1001 ;; libunistring, GMP, etc.
1002 (match (vhash-assoc (package-full-name package) name->package)
1004 ;; In general we want CANON, except if we're cross-compiling: CANON
1005 ;; uses explicit inputs, so it is "anchored" in the bootstrapped
1006 ;; process, with dependencies on things that cannot be
1008 (if (%current-target-system)
1018 ;; Using the following procedure, a gcc toolchain targeting glibc-2.27 can be
1019 ;; instantiated like this:
1021 ;; (define-public gcc-glibc-2.27-toolchain
1022 ;; (make-gcc-toolchain gcc glibc-2.27))
1024 (define* (make-gcc-toolchain gcc
1027 "Return a complete toolchain for GCC. If LIBC is specified, target that libc."
1028 (let ((gcc (if libc (make-gcc-libc gcc libc) gcc))
1029 (libc (if libc libc glibc-final)))
1031 (name (string-append (package-name gcc) "-toolchain"))
1032 (version (package-version gcc))
1034 (build-system trivial-build-system)
1036 '(#:modules ((guix build union))
1038 (use-modules (ice-9 match)
1042 (let ((out (assoc-ref %outputs "out")))
1044 (match %build-inputs
1045 (((names . directories) ...)
1046 (union-build out directories)))
1048 (union-build (assoc-ref %outputs "debug")
1049 (list (assoc-ref %build-inputs
1051 (union-build (assoc-ref %outputs "static")
1052 (list (assoc-ref %build-inputs
1056 (native-search-paths (package-native-search-paths gcc))
1057 (search-paths (package-search-paths gcc))
1059 (license (package-license gcc))
1060 (synopsis "Complete GCC tool chain for C/C++ development")
1062 "This package provides a complete GCC tool chain for C/C++ development to
1063 be installed in user profiles. This includes GCC, as well as libc (headers
1064 an d binaries, plus debugging symbols in the @code{debug} output), and Binutils.")
1065 (home-page "https://gcc.gnu.org/")
1066 (outputs '("out" "debug" "static"))
1068 ;; The main raison d'être of this "meta-package" is (1) to conveniently
1069 ;; install everything that we need, and (2) to make sure ld-wrapper comes
1070 ;; before Binutils' ld in the user's profile.
1071 (inputs `(("gcc" ,gcc)
1072 ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
1073 ("binutils" ,binutils-final)
1075 ("libc-debug" ,libc "debug")
1076 ("libc-static" ,libc "static"))))))
1078 (define-public gcc-toolchain-4.8
1079 (make-gcc-toolchain gcc-4.8))
1081 (define-public gcc-toolchain-4.9
1082 (make-gcc-toolchain gcc-4.9))
1084 (define-public gcc-toolchain
1085 (make-gcc-toolchain gcc-final))
1087 (define-public gcc-toolchain-5
1090 (define-public gcc-toolchain-6
1091 (make-gcc-toolchain gcc-6))
1093 (define-public gcc-toolchain-7
1094 (make-gcc-toolchain gcc-7))
1096 (define-public gcc-toolchain-8
1097 (make-gcc-toolchain gcc-8))
1099 (define-public gcc-toolchain-9
1100 (make-gcc-toolchain gcc-9))
1102 ;;; commencement.scm ends here