Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / bootstrap.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015, 2018, 2019 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2017, 2020 Efraim Flashner <efraim@flashner.co.il>
5 ;;; Copyright © 2018, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
6 ;;; Copyright © 2019 Carl Dong <contact@carldong.me>
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 bootstrap)
24 #:use-module (guix licenses)
25 #:use-module (gnu packages)
26 #:use-module (guix packages)
27 #:use-module (guix download)
28 #:use-module (guix build-system)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix build-system trivial)
31 #:use-module ((guix store)
32 #:select (run-with-store add-to-store add-text-to-store))
33 #:use-module ((guix derivations)
34 #:select (derivation derivation-input derivation->output-path))
35 #:use-module ((guix utils) #:select (gnu-triplet->nix-system))
36 #:use-module ((guix gexp) #:select (lower-object))
37 #:use-module (guix memoization)
38 #:use-module (guix i18n)
39 #:use-module (srfi srfi-1)
40 #:use-module (srfi srfi-26)
41 #:use-module (srfi srfi-34)
42 #:use-module (srfi srfi-35)
43 #:use-module (ice-9 match)
44 #:export (bootstrap-origin
45 package-with-bootstrap-guile
46 glibc-dynamic-linker
47
48 bootstrap-executable
49 bootstrap-guile-origin
50
51 %bootstrap-guile
52 %bootstrap-coreutils&co
53 %bootstrap-linux-libre-headers
54 %bootstrap-binutils
55 %bootstrap-gcc
56 %bootstrap-glibc
57 %bootstrap-inputs
58 %bootstrap-mescc-tools
59 %bootstrap-mes
60
61 %bootstrap-inputs-for-tests))
62
63 ;;; Commentary:
64 ;;;
65 ;;; Pre-built packages that are used to bootstrap the
66 ;;; distribution--i.e., to build all the core packages from scratch.
67 ;;;
68 ;;; Code:
69
70
71 \f
72 ;;;
73 ;;; The bootstrap executables: 'bash', 'mkdir', 'tar', 'xz'. They allow us to
74 ;;; extract the very first tarball.
75 ;;;
76
77 (define %bootstrap-executables
78 ;; List of bootstrap executables and their recursive hashes (as per 'guix
79 ;; hash -r'), taking their executable bit into account.
80 `(("aarch64-linux"
81 ("bash"
82 ,(base32 "13aqhqb8nydlwq1ah9974q0iadx1pb95v13wzzyf7vgv6nasrwzr"))
83 ("mkdir"
84 ,(base32 "1pxhdp7ldwavmm71xbh9wc197cb2nr66acjn26yjx3732cixh9ws"))
85 ("tar"
86 ,(base32 "1j51gv08sfg277yxj73xd564wjq3f8xwd6s9rbcg8v9gms47m4cx"))
87 ("xz"
88 ,(base32 "1d779rwsrasphg5g3r37qppcqy3p7ay1jb1y83w7x4i3qsc7zjy2")))
89 ("armhf-linux"
90 ("bash"
91 ,(base32 "0s6f1s26g4dsrrkl39zblvwpxmbzi6n9mgqf6vxsqz42gik6bgyn"))
92 ("mkdir"
93 ,(base32 "1r5rcp35niyxfkrdf00y2ba8ifrq9bi76cr63lwjf2l655j1i5p7"))
94 ("tar"
95 ,(base32 "0dksx5im3fv8ximz7368bsax9f26nn47ds74298flm5lnvpv9xly"))
96 ("xz"
97 ,(base32 "1cqqavghjfr0iwxqf61lrssv27wfigysgq2rs4rm1gkmn04yn1k3")))
98 ("i686-linux"
99 ("bash"
100 ,(base32 "0rjaxyzjdllfkf1abczvgaf3cdcc7mmahyvdbkjmjzhgz92pv23g"))
101 ("mkdir"
102 ,(base32 "133ybmfpkmsnysrzbngwvbysqnsmfi8is8zifs7i7n6n600h4s1w"))
103 ("tar"
104 ,(base32 "07830bx29ad5i0l1ykj0g0b1jayjdblf01sr3ww9wbnwdbzinqms"))
105 ("xz"
106 ,(base32 "0i9kxdi17bm5gxfi2xzm0y73p3ii0cqxli1sbljm6rh2fjgyn90k")))
107 ("i586-gnu"
108 ("bash"
109 ,(base32 "1as8649aqaibahhhrvkj10ci8shpi4hq5n7gnik8rhhy0dc1jarg"))
110 ("mkdir"
111 ,(base32 "1snqgpfrl00hfn82lm29jqylzjsfb9jd6ha74dp12phwb8fpbmb9"))
112 ("tar"
113 ,(base32 "0nq2c1zb3wv5bf7kd83sziaashydazrn7xgq6kijlk0zj2syzc2m"))
114 ("xz"
115 ,(base32 "033rhpk6zrpxpd6ffjyg5y2zwq9x9cnq0zljb7k8jlncbalsayq5")))
116 ("mips64el-linux"
117 ("bash"
118 ,(base32 "1aw046dhda240k9pb9iaj5aqkm23gkvxa9j82n4k7fk87nbrixw6"))
119 ("mkdir"
120 ,(base32 "0c9j6qgyw84zxbry3ypifzll13gy8ax71w40kdk1h11jbgla3f5k"))
121 ("tar"
122 ,(base32 "06gmqdjq3rl8lr47b9fyx4ifnm5x56ymc8lyryp1ax1j2s4y5jb4"))
123 ("xz"
124 ,(base32 "09j1d69qr0hhhx4k4ih8wp00dfc9y4rp01hfg3vc15yxd0jxabh5")))))
125
126 (define %bootstrap-executable-base-urls
127 ;; This is where the bootstrap executables come from.
128 '("https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/bootstrap/"
129 "http://lilypond.org/janneke/guix/"))
130
131 (define (bootstrap-executable-file-name system program)
132 "Return the FILE-NAME part of url where PROGRAM can be found for SYSTEM."
133 (match system
134 ("i586-gnu" (string-append system "/20200326/" program))
135 (_ (string-append system "/" program
136 "?id=44f07d1dc6806e97c4e9ee3e6be883cc59dc666e"))))
137
138 (define bootstrap-executable
139 (mlambda (program system)
140 "Return an origin for PROGRAM, a statically-linked bootstrap executable
141 built for SYSTEM."
142 (let ((system (if (string=? system "x86_64-linux")
143 "i686-linux"
144 system)))
145 (match (assoc-ref (assoc-ref %bootstrap-executables system)
146 program)
147 (#f
148 (raise (condition
149 (&message
150 (message
151 (format #f (G_ "could not find bootstrap binary '~a' \
152 for system '~a'")
153 program system))))))
154 ((sha256)
155 (origin
156 (method url-fetch/executable)
157 (uri (map (cute string-append <>
158 (bootstrap-executable-file-name system program))
159 %bootstrap-executable-base-urls))
160 (file-name program)
161 (sha256 sha256)))))))
162
163 \f
164 ;;;
165 ;;; Helper procedures.
166 ;;;
167
168 (define bootstrap-origin
169 (mlambdaq (source)
170 "Return a variant of SOURCE, an <origin> instance, whose method uses
171 %BOOTSTRAP-GUILE to do its job."
172 (define (boot fetch)
173 (lambda* (url hash-algo hash
174 #:optional name #:key system)
175 (fetch url hash-algo hash name
176 #:guile %bootstrap-guile
177 #:system system)))
178
179 (define %bootstrap-patch-inputs
180 ;; Packages used when an <origin> has a non-empty 'patches' field.
181 `(("tar" ,%bootstrap-coreutils&co)
182 ("xz" ,%bootstrap-coreutils&co)
183 ("bzip2" ,%bootstrap-coreutils&co)
184 ("gzip" ,%bootstrap-coreutils&co)
185 ("patch" ,%bootstrap-coreutils&co)))
186
187 (let ((orig-method (origin-method source)))
188 (if (or (not (null? (origin-patches source)))
189 (origin-snippet source))
190 (origin (inherit source)
191 (method (if (eq? orig-method url-fetch)
192 (boot url-fetch)
193 orig-method))
194 (patch-guile %bootstrap-guile)
195 (patch-inputs %bootstrap-patch-inputs)
196
197 ;; Patches can be origins as well, so process them.
198 (patches (map (match-lambda
199 ((? origin? patch)
200 (bootstrap-origin patch))
201 (patch patch))
202 (origin-patches source))))
203 source))))
204
205 (define* (package-from-tarball name source program-to-test description
206 #:key snippet)
207 "Return a package that correspond to the extraction of SOURCE.
208 PROGRAM-TO-TEST is #f or a string: the program to run after extraction of
209 SOURCE to check whether everything is alright. If SNIPPET is provided, it is
210 evaluated after extracting SOURCE. SNIPPET should return true if successful,
211 or false to signal an error."
212 (package
213 (name name)
214 (version "0")
215 (build-system trivial-build-system)
216 (arguments
217 `(#:guile ,%bootstrap-guile
218 #:modules ((guix build utils))
219 #:builder
220 (begin
221 (use-modules (guix build utils))
222
223 (let ((out (assoc-ref %outputs "out"))
224 (tar (assoc-ref %build-inputs "tar"))
225 (xz (assoc-ref %build-inputs "xz"))
226 (tarball (assoc-ref %build-inputs "tarball")))
227
228 (mkdir out)
229 (copy-file tarball "binaries.tar.xz")
230 (invoke xz "-d" "binaries.tar.xz")
231 (let ((builddir (getcwd)))
232 (with-directory-excursion out
233 (invoke tar "xvf"
234 (string-append builddir "/binaries.tar"))
235 ,@(if snippet (list snippet) '())
236 (or (not ,program-to-test)
237 (invoke (string-append "bin/" ,program-to-test)
238 "--version"))))))))
239 (inputs
240 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
241 ("xz" ,(bootstrap-executable "xz" (%current-system)))
242 ("tarball" ,(bootstrap-origin (source (%current-system))))))
243 (source #f)
244 (synopsis description)
245 (description description)
246 (home-page #f)
247 (license gpl3+)))
248
249 (define package-with-bootstrap-guile
250 (mlambdaq (p)
251 "Return a variant of P such that all its origins are fetched with
252 %BOOTSTRAP-GUILE."
253 (define rewritten-input
254 (match-lambda
255 ((name (? origin? o))
256 `(,name ,(bootstrap-origin o)))
257 ((name (? package? p) sub-drvs ...)
258 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
259 (x x)))
260
261 (package (inherit p)
262 (source (match (package-source p)
263 ((? origin? o) (bootstrap-origin o))
264 (s s)))
265 (inputs (map rewritten-input
266 (package-inputs p)))
267 (native-inputs (map rewritten-input
268 (package-native-inputs p)))
269 (propagated-inputs (map rewritten-input
270 (package-propagated-inputs p)))
271 (replacement (and=> (package-replacement p)
272 package-with-bootstrap-guile)))))
273
274 (define* (glibc-dynamic-linker
275 #:optional (system (or (and=> (%current-target-system)
276 gnu-triplet->nix-system)
277 (%current-system))))
278 "Return the name of Glibc's dynamic linker for SYSTEM."
279 ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
280 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
281 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
282 ((string=? system "armhf-linux") "/lib/ld-linux-armhf.so.3")
283 ((string=? system "mips64el-linux") "/lib/ld.so.1")
284 ((string=? system "i586-gnu") "/lib/ld.so.1")
285 ((string=? system "i686-gnu") "/lib/ld.so.1")
286 ((string=? system "aarch64-linux") "/lib/ld-linux-aarch64.so.1")
287 ((string=? system "powerpc-linux") "/lib/ld.so.1")
288 ((string=? system "powerpc64le-linux") "/lib/ld64.so.2")
289 ((string=? system "alpha-linux") "/lib/ld-linux.so.2")
290 ((string=? system "s390x-linux") "/lib/ld64.so.1")
291 ((string=? system "riscv64-linux") "/lib/ld-linux-riscv64-lp64d.so.1")
292
293 ;; XXX: This one is used bare-bones, without a libc, so add a case
294 ;; here just so we can keep going.
295 ((string=? system "arm-elf") "no-ld.so")
296 ((string=? system "arm-eabi") "no-ld.so")
297 ((string=? system "xtensa-elf") "no-ld.so")
298 ((string=? system "avr") "no-ld.so")
299 ((string=? system "propeller-elf") "no-ld.so")
300 ((string=? system "i686-mingw") "no-ld.so")
301 ((string=? system "x86_64-mingw") "no-ld.so")
302 ((string=? system "vc4-elf") "no-ld.so")
303
304 (else (error "dynamic linker name not known for this system"
305 system))))
306
307 \f
308 ;;;
309 ;;; Bootstrap packages.
310 ;;;
311
312 (define %bootstrap-base-urls
313 ;; This is where the initial binaries come from.
314 '("https://ftp.gnu.org/gnu/guix/bootstrap"
315 "https://alpha.gnu.org/gnu/guix/bootstrap"
316 "http://ftp.gnu.org/gnu/guix/bootstrap"
317 "http://alpha.gnu.org/gnu/guix/bootstrap"
318 "ftp://alpha.gnu.org/gnu/guix/bootstrap"
319 "http://www.fdn.fr/~lcourtes/software/guix/packages"
320 "http://flashner.co.il/guix/bootstrap"
321 "http://lilypond.org/janneke/guix/"))
322
323 (define (bootstrap-guile-url-path system)
324 "Return the URI for FILE."
325 (string-append "/" system
326 (match system
327 ("aarch64-linux"
328 "/20170217/guile-2.0.14.tar.xz")
329 ("armhf-linux"
330 "/20150101/guile-2.0.11.tar.xz")
331 ("i586-gnu"
332 "/20200326/guile-static-stripped-2.0.14-i586-pc-gnu.tar.xz")
333 (_
334 "/20131110/guile-2.0.9.tar.xz"))))
335
336 (define (bootstrap-guile-hash system)
337 "Return the SHA256 hash of the Guile bootstrap tarball for SYSTEM."
338 (match system
339 ("x86_64-linux"
340 (base32 "1w2p5zyrglzzniqgvyn1b55vprfzhgk8vzbzkkbdgl5248si0yq3"))
341 ("i686-linux"
342 (base32 "0im800m30abgh7msh331pcbjvb4n02smz5cfzf1srv0kpx3csmxp"))
343 ("mips64el-linux"
344 (base32 "0fzp93lvi0hn54acc0fpvhc7bvl0yc853k62l958cihk03q80ilr"))
345 ("armhf-linux"
346 (base32 "1mi3brl7l58aww34rawhvja84xc7l1b4hmwdmc36fp9q9mfx0lg5"))
347 ("aarch64-linux"
348 (base32 "1giy2aprjmn5fp9c4s9r125fljw4wv6ixy5739i5bffw4jgr0f9r"))
349 ("i586-gnu"
350 (base32 "0wgqpsmvg25rnqn49ap7kwd2qxccd8dr4lllzp7i3rjvgav27vac"))))
351
352 (define (bootstrap-guile-origin system)
353 "Return an <origin> object for the Guile tarball of SYSTEM."
354 (origin
355 (method url-fetch)
356 (uri (map (cute string-append <> (bootstrap-guile-url-path system))
357 %bootstrap-base-urls))
358 (sha256 (bootstrap-guile-hash system))))
359
360 (define (download-bootstrap-guile store system)
361 "Return a derivation that downloads the bootstrap Guile tarball for SYSTEM."
362 (let* ((path (bootstrap-guile-url-path system))
363 (base (basename path))
364 (urls (map (cut string-append <> path) %bootstrap-base-urls)))
365 (run-with-store store
366 (url-fetch urls 'sha256 (bootstrap-guile-hash system)
367 #:system system))))
368
369 (define* (raw-build store name inputs
370 #:key outputs system search-paths
371 #:allow-other-keys)
372 (define (->store file)
373 (run-with-store store
374 (lower-object (bootstrap-executable file system)
375 system)))
376
377 (let* ((tar (->store "tar"))
378 (xz (->store "xz"))
379 (mkdir (->store "mkdir"))
380 (bash (->store "bash"))
381 (guile (download-bootstrap-guile store system))
382 ;; The following code, run by the bootstrap guile after it is
383 ;; unpacked, creates a wrapper for itself to set its load path.
384 ;; This replaces the previous non-portable method based on
385 ;; reading the /proc/self/exe symlink.
386 (make-guile-wrapper
387 '(begin
388 (use-modules (ice-9 match))
389 (match (command-line)
390 ((_ out bash)
391 (let ((bin-dir (string-append out "/bin"))
392 (guile (string-append out "/bin/guile"))
393 (guile-real (string-append out "/bin/.guile-real"))
394 ;; We must avoid using a bare dollar sign in this code,
395 ;; because it would be interpreted by the shell.
396 (dollar (string (integer->char 36))))
397 (chmod bin-dir #o755)
398 (rename-file guile guile-real)
399 (call-with-output-file guile
400 (lambda (p)
401 (format p "\
402 #!~a
403 export GUILE_SYSTEM_PATH=~a/share/guile/2.0
404 export GUILE_SYSTEM_COMPILED_PATH=~a/lib/guile/2.0/ccache
405 exec -a \"~a0\" ~a \"~a@\"\n"
406 bash out out dollar guile-real dollar)))
407 (chmod guile #o555)
408 (chmod bin-dir #o555))))))
409 (builder
410 (add-text-to-store store
411 "build-bootstrap-guile.sh"
412 (format #f "
413 echo \"unpacking bootstrap Guile to '$out'...\"
414 ~a $out
415 cd $out
416 ~a -dc < $GUILE_TARBALL | ~a xv
417
418 # Use the bootstrap guile to create its own wrapper to set the load path.
419 GUILE_SYSTEM_PATH=$out/share/guile/2.0 \
420 GUILE_SYSTEM_COMPILED_PATH=$out/lib/guile/2.0/ccache \
421 $out/bin/guile -c ~s $out ~a
422
423 # Sanity check.
424 $out/bin/guile --version~%"
425 (derivation->output-path mkdir)
426 (derivation->output-path xz)
427 (derivation->output-path tar)
428 (format #f "~s" make-guile-wrapper)
429 (derivation->output-path bash)))))
430 (derivation store name
431 (derivation->output-path bash) `(,builder)
432 #:system system
433 #:inputs (map derivation-input
434 (list bash mkdir tar xz guile))
435 #:sources (list builder)
436 #:env-vars `(("GUILE_TARBALL"
437 . ,(derivation->output-path guile))))))
438
439 (define* (make-raw-bag name
440 #:key source inputs native-inputs outputs
441 system target)
442 (bag
443 (name name)
444 (system system)
445 (build-inputs inputs)
446 (build raw-build)))
447
448 (define %bootstrap-guile
449 ;; The Guile used to run the build scripts of the initial derivations.
450 ;; It is just unpacked from a tarball containing a pre-built binary.
451 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
452 ;;
453 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
454 ;; support (for /etc/services).
455 (let ((raw (build-system
456 (name 'raw)
457 (description "Raw build system with direct store access")
458 (lower make-raw-bag))))
459 (package
460 (name "guile-bootstrap")
461 (version "2.0")
462 (source #f)
463 (build-system raw)
464 (synopsis "Bootstrap Guile")
465 (description "Pre-built Guile for bootstrapping purposes.")
466 (home-page #f)
467 (license lgpl3+))))
468
469 (define %bootstrap-coreutils&co
470 (package-from-tarball "bootstrap-binaries"
471 (lambda (system)
472 (origin
473 (method url-fetch)
474 (uri (map (cut string-append <> "/" system
475 (match system
476 ("armhf-linux"
477 "/20150101/static-binaries.tar.xz")
478 ("aarch64-linux"
479 "/20170217/static-binaries.tar.xz")
480 ("i586-gnu"
481 "/20200326/static-binaries-0-i586-pc-gnu.tar.xz")
482 (_
483 "/20131110/static-binaries.tar.xz")))
484 %bootstrap-base-urls))
485 (sha256
486 (match system
487 ("x86_64-linux"
488 (base32
489 "0c533p9dhczzcsa1117gmfq3pc8w362g4mx84ik36srpr7cx2bg4"))
490 ("i686-linux"
491 (base32
492 "0s5b3jb315n13m1k8095l0a5hfrsz8g0fv1b6riyc5hnxqyphlak"))
493 ("armhf-linux"
494 (base32
495 "0gf0fn2kbpxkjixkmx5f4z6hv6qpmgixl69zgg74dbsfdfj8jdv5"))
496 ("aarch64-linux"
497 (base32
498 "18dfiq6c6xhsdpbidigw6480wh0vdgsxqq3xindq4lpdgqlccpfh"))
499 ("i586-gnu"
500 (base32
501 "17kllqnf3fg79gzy9ansgi801c46yh9c23h4d923plvb0nfm1cfn"))
502 ("mips64el-linux"
503 (base32
504 "072y4wyfsj1bs80r6vbybbafy8ya4vfy7qj25dklwk97m6g71753"))))))
505 "fgrep" ; the program to test
506 "Bootstrap binaries of Coreutils, Awk, etc."
507 #:snippet
508 '(let ((path (list (string-append (getcwd) "/bin"))))
509 (chmod "bin" #o755)
510 (patch-shebang "bin/egrep" path)
511 (patch-shebang "bin/fgrep" path)
512 ;; Starting with grep@2.25 'egrep' and 'fgrep' are shell files
513 ;; that call 'grep'. If the bootstrap 'egrep' and 'fgrep'
514 ;; are not binaries then patch them to execute 'grep' via its
515 ;; absolute file name instead of searching for it in $PATH.
516 (if (not (elf-file? "bin/egrep"))
517 (substitute* '("bin/egrep" "bin/fgrep")
518 (("^exec grep") (string-append (getcwd) "/bin/grep"))))
519 (chmod "bin" #o555))))
520
521 (define-public %bootstrap-linux-libre-headers
522 (package-from-tarball
523 "linux-libre-headers-bootstrap"
524 (lambda (system)
525 (origin
526 (method url-fetch)
527 (uri (map (cute string-append <>
528 "/i686-linux/20190815/"
529 "linux-libre-headers-stripped-4.14.67-i686-linux.tar.xz")
530 %bootstrap-base-urls))
531 (sha256
532 (base32
533 "0sm2z9x4wk45bh6qfs94p0w1d6hsy6dqx9sw38qsqbvxwa1qzk8s"))))
534 #f ; no program to test
535 "Bootstrap linux-libre-headers"))
536
537 (define %bootstrap-binutils
538 (package-from-tarball "binutils-bootstrap"
539 (lambda (system)
540 (origin
541 (method url-fetch)
542 (uri (map (cut string-append <> "/" system
543 (match system
544 ("armhf-linux"
545 "/20150101/binutils-2.25.tar.xz")
546 ("aarch64-linux"
547 "/20170217/binutils-2.27.tar.xz")
548 ("i586-gnu"
549 "/20200326/binutils-static-stripped-2.34-i586-pc-gnu.tar.xz")
550 (_
551 "/20131110/binutils-2.23.2.tar.xz")))
552 %bootstrap-base-urls))
553 (sha256
554 (match system
555 ("x86_64-linux"
556 (base32
557 "1j5yivz7zkjqfsfmxzrrrffwyayjqyfxgpi89df0w4qziqs2dg20"))
558 ("i686-linux"
559 (base32
560 "14jgwf9gscd7l2pnz610b1zia06dvcm2qyzvni31b8zpgmcai2v9"))
561 ("armhf-linux"
562 (base32
563 "1v7dj6bzn6m36f20gw31l99xaabq4xrhrx3gwqkhhig0mdlmr69q"))
564 ("aarch64-linux"
565 (base32
566 "111s7ilfiby033rczc71797xrmaa3qlv179wdvsaq132pd51xv3n"))
567 ("i586-gnu"
568 (base32
569 "11kykv1kmqc5wln57rs4klaqa13hm952smkc57qcsyss21kfjprs"))
570 ("mips64el-linux"
571 (base32
572 "1x8kkhcxmfyzg1ddpz2pxs6fbdl6412r7x0nzbmi5n7mj8zw2gy7"))))))
573 "ld" ; the program to test
574 "Bootstrap binaries of the GNU Binutils"))
575
576 (define %bootstrap-glibc
577 ;; The initial libc.
578 (package
579 (name "glibc-bootstrap")
580 (version "0")
581 (source #f)
582 (build-system trivial-build-system)
583 (arguments
584 `(#:guile ,%bootstrap-guile
585 #:modules ((guix build utils))
586 #:builder
587 (begin
588 (use-modules (guix build utils))
589
590 (let ((out (assoc-ref %outputs "out"))
591 (tar (assoc-ref %build-inputs "tar"))
592 (xz (assoc-ref %build-inputs "xz"))
593 (tarball (assoc-ref %build-inputs "tarball")))
594
595 (mkdir out)
596 (copy-file tarball "binaries.tar.xz")
597 (invoke xz "-d" "binaries.tar.xz")
598 (let ((builddir (getcwd)))
599 (with-directory-excursion out
600 (invoke tar "xvf"
601 (string-append builddir
602 "/binaries.tar"))
603 (chmod "lib" #o755)
604
605 ;; Patch libc.so so it refers to the right path.
606 (substitute* "lib/libc.so"
607 (("/[^ ]+/lib/(libc|ld)" _ prefix)
608 (string-append out "/lib/" prefix)))
609
610 #t))))))
611 (inputs
612 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
613 ("xz" ,(bootstrap-executable "xz" (%current-system)))
614 ("tarball" ,(bootstrap-origin
615 (origin
616 (method url-fetch)
617 (uri (map (cut string-append <> "/" (%current-system)
618 (match (%current-system)
619 ("armhf-linux"
620 "/20150101/glibc-2.20.tar.xz")
621 ("aarch64-linux"
622 "/20170217/glibc-2.25.tar.xz")
623 ("i586-gnu"
624 "/20200326/glibc-stripped-2.31-i586-pc-gnu.tar.xz")
625 (_
626 "/20131110/glibc-2.18.tar.xz")))
627 %bootstrap-base-urls))
628 (sha256
629 (match (%current-system)
630 ("x86_64-linux"
631 (base32
632 "0jlqrgavvnplj1b083s20jj9iddr4lzfvwybw5xrcis9spbfzk7v"))
633 ("i686-linux"
634 (base32
635 "1hgrccw1zqdc7lvgivwa54d9l3zsim5pqm0dykxg0z522h6gr05w"))
636 ("armhf-linux"
637 (base32
638 "18cmgvpllqfpn6khsmivqib7ys8ymnq0hdzi3qp24prik0ykz8gn"))
639 ("aarch64-linux"
640 (base32
641 "07nx3x8598i2924rjnlrncg6rm61c9bmcczbbcpbx0fb742nvv5c"))
642 ("i586-gnu"
643 (base32
644 "14ddm10lpbas8bankmn5bcrlqvz1v5dnn1qjzxb19r57vd2w5952"))
645 ("mips64el-linux"
646 (base32
647 "0k97a3whzx3apsi9n2cbsrr79ad6lh00klxph9hw4fqyp1abkdsg")))))))))
648 (synopsis "Bootstrap binaries and headers of the GNU C Library")
649 (description synopsis)
650 (home-page #f)
651 (license lgpl2.1+)))
652
653 (define %bootstrap-gcc
654 ;; The initial GCC. Uses binaries from a tarball typically built by
655 ;; %GCC-BOOTSTRAP-TARBALL.
656 (package
657 (name "gcc-bootstrap")
658 (version "0")
659 (source #f)
660 (build-system trivial-build-system)
661 (arguments
662 `(#:guile ,%bootstrap-guile
663 #:modules ((guix build utils))
664 #:builder
665 (begin
666 (use-modules (guix build utils)
667 (ice-9 popen))
668
669 (let ((out (assoc-ref %outputs "out"))
670 (tar (assoc-ref %build-inputs "tar"))
671 (xz (assoc-ref %build-inputs "xz"))
672 (bash (assoc-ref %build-inputs "bash"))
673 (libc (assoc-ref %build-inputs "libc"))
674 (tarball (assoc-ref %build-inputs "tarball")))
675
676 (mkdir out)
677 (copy-file tarball "binaries.tar.xz")
678 (invoke xz "-d" "binaries.tar.xz")
679 (let ((builddir (getcwd))
680 (bindir (string-append out "/bin")))
681 (with-directory-excursion out
682 (invoke tar "xvf"
683 (string-append builddir "/binaries.tar")))
684
685 (with-directory-excursion bindir
686 (chmod "." #o755)
687 (rename-file "gcc" ".gcc-wrapped")
688 (call-with-output-file "gcc"
689 (lambda (p)
690 (format p "#!~a
691 exec ~a/bin/.gcc-wrapped -B~a/lib \
692 -Wl,-rpath -Wl,~a/lib \
693 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
694 bash
695 out libc libc libc
696 ,(glibc-dynamic-linker))))
697
698 (chmod "gcc" #o555)
699 #t))))))
700 (inputs
701 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
702 ("xz" ,(bootstrap-executable "xz" (%current-system)))
703 ("bash" ,(bootstrap-executable "bash" (%current-system)))
704 ("libc" ,%bootstrap-glibc)
705 ("tarball" ,(bootstrap-origin
706 (origin
707 (method url-fetch)
708 (uri (map (cut string-append <> "/" (%current-system)
709 (match (%current-system)
710 ("armhf-linux"
711 "/20150101/gcc-4.8.4.tar.xz")
712 ("aarch64-linux"
713 "/20170217/gcc-5.4.0.tar.xz")
714 ("i586-gnu"
715 "/20200326/gcc-stripped-5.5.0-i586-pc-gnu.tar.xz")
716 (_
717 "/20131110/gcc-4.8.2.tar.xz")))
718 %bootstrap-base-urls))
719 (sha256
720 (match (%current-system)
721 ("x86_64-linux"
722 (base32
723 "17ga4m6195n4fnbzdkmik834znkhs53nkypp6557pl1ps7dgqbls"))
724 ("i686-linux"
725 (base32
726 "150c1arrf2k8vfy6dpxh59vcgs4p1bgiz2av5m19dynpks7rjnyw"))
727 ("armhf-linux"
728 (base32
729 "0ghz825yzp43fxw53kd6afm8nkz16f7dxi9xi40bfwc8x3nbbr8v"))
730 ("aarch64-linux"
731 (base32
732 "1ar3vdzyqbfm0z36kmvazvfswxhcihlacl2dzdjgiq25cqnq9ih1"))
733 ("i586-gnu"
734 (base32
735 "1j2zc58wzil71a34h7c70sd68dmqvcscrw3rmn2whq79vd70zvv5"))
736 ("mips64el-linux"
737 (base32
738 "1m5miqkyng45l745n0sfafdpjkqv9225xf44jqkygwsipj2cv9ks")))))))))
739 (native-search-paths
740 (list (search-path-specification
741 (variable "CPATH")
742 (files '("include")))
743 (search-path-specification
744 (variable "LIBRARY_PATH")
745 (files '("lib" "lib64")))))
746 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
747 (description synopsis)
748 (home-page #f)
749 (license gpl3+)))
750
751 (define %bootstrap-mescc-tools
752 ;; The initial MesCC tools. Uses binaries from a tarball typically built by
753 ;; %MESCC-TOOLS-BOOTSTRAP-TARBALL.
754 (package
755 (name "bootstrap-mescc-tools")
756 (version "0.5.2")
757 (source #f)
758 (build-system trivial-build-system)
759 (arguments
760 `(#:guile ,%bootstrap-guile
761 #:modules ((guix build utils))
762 #:builder
763 (begin
764 (use-modules (guix build utils)
765 (ice-9 popen))
766 (let ((out (assoc-ref %outputs "out"))
767 (tar (assoc-ref %build-inputs "tar"))
768 (xz (assoc-ref %build-inputs "xz"))
769 (tarball (assoc-ref %build-inputs "tarball")))
770
771 (mkdir out)
772 (copy-file tarball "binaries.tar.xz")
773 (invoke xz "-d" "binaries.tar.xz")
774 (let ((builddir (getcwd))
775 (bindir (string-append out "/bin")))
776 (with-directory-excursion out
777 (invoke tar "xvf"
778 (string-append builddir "/binaries.tar"))))))))
779 (inputs
780 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
781 ("xz" ,(bootstrap-executable "xz" (%current-system)))
782 ("tarball"
783 ,(bootstrap-origin
784 (origin
785 (method url-fetch)
786 (uri (map
787 (cute string-append <>
788 "/i686-linux/20190815/"
789 "mescc-tools-static-stripped-0.5.2-i686-linux.tar.xz")
790 %bootstrap-base-urls))
791 (sha256
792 (base32
793 "0c3kklgghzh4q2dbpl6asb74cimp7hp6jscdwqwmzxbapgcl6582")))))))
794 (synopsis "Bootstrap binaries of MesCC Tools")
795 (description synopsis)
796 (home-page #f)
797 (supported-systems '("i686-linux" "x86_64-linux"))
798 (license gpl3+)))
799
800 (define %bootstrap-mes
801 ;; The initial Mes. Uses binaries from a tarball typically built by
802 ;; %MES-BOOTSTRAP-TARBALL.
803 (package
804 (name "bootstrap-mes")
805 (version "0")
806 (source #f)
807 (build-system trivial-build-system)
808 (arguments
809 `(#:guile ,%bootstrap-guile
810 #:modules ((guix build utils))
811 #:builder
812 (begin
813 (use-modules (guix build utils)
814 (ice-9 popen))
815 (let ((out (assoc-ref %outputs "out"))
816 (tar (assoc-ref %build-inputs "tar"))
817 (xz (assoc-ref %build-inputs "xz"))
818 (tarball (assoc-ref %build-inputs "tarball")))
819
820 (mkdir out)
821 (copy-file tarball "binaries.tar.xz")
822 (invoke xz "-d" "binaries.tar.xz")
823 (let ((builddir (getcwd))
824 (bindir (string-append out "/bin")))
825 (with-directory-excursion out
826 (invoke tar "xvf"
827 (string-append builddir "/binaries.tar"))))))))
828 (inputs
829 `(("tar" ,(bootstrap-executable "tar" (%current-system)))
830 ("xz" ,(bootstrap-executable "xz" (%current-system)))
831 ("tarball"
832 ,(bootstrap-origin
833 (origin
834 (method url-fetch)
835 (uri (map
836 (cute string-append <>
837 "/i686-linux/20190815/"
838 "mes-minimal-stripped-0.19-i686-linux.tar.xz")
839 %bootstrap-base-urls))
840 (sha256
841 (base32
842 "1q4xjpx6nbn44kxnilpgl12bhpmwy2bblzwszc2ci7xkf400jcpv")))))))
843 (supported-systems '("i686-linux" "x86_64-linux"))
844 (synopsis "Bootstrap binaries of Mes")
845 (description synopsis)
846 (home-page #f)
847 (license gpl3+)))
848
849 (define (%bootstrap-inputs)
850 ;; The initial, pre-built inputs. From now on, we can start building our
851 ;; own packages.
852 (match (%current-system)
853 ((or "i686-linux" "x86_64-linux")
854 `(("linux-libre-headers" ,%bootstrap-linux-libre-headers)
855 ("bootstrap-mescc-tools" ,%bootstrap-mescc-tools)
856 ("mes" ,%bootstrap-mes)))
857 (_
858 `(("libc" ,%bootstrap-glibc)
859 ("gcc" ,%bootstrap-gcc)
860 ("binutils" ,%bootstrap-binutils)
861 ("coreutils&co" ,%bootstrap-coreutils&co)
862 ;; In gnu-build-system.scm, we rely on the availability of Bash.
863 ("bash" ,%bootstrap-coreutils&co)))))
864
865 (define %bootstrap-inputs-for-tests
866 ;; These are bootstrap inputs that are cheap to produce (no compilation
867 ;; needed) and that are meant to be used for testing. (These are those we
868 ;; used before the Mes-based reduced bootstrap.)
869 `(("libc" ,%bootstrap-glibc)
870 ("gcc" ,%bootstrap-gcc)
871 ("binutils" ,%bootstrap-binutils)
872 ("coreutils&co" ,%bootstrap-coreutils&co)
873 ("bash" ,%bootstrap-coreutils&co)))
874
875 ;;; bootstrap.scm ends here