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