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