1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu packages bootstrap)
20 #:use-module (guix licenses)
21 #:use-module (gnu packages)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix build-system)
25 #:use-module (guix build-system gnu)
26 #:use-module (guix build-system trivial)
27 #:use-module ((guix store) #:select (add-to-store add-text-to-store))
28 #:use-module ((guix derivations) #:select (derivation))
29 #:use-module (guix utils)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-26)
32 #:use-module (ice-9 match)
33 #:export (bootstrap-origin
34 package-with-bootstrap-guile
38 %bootstrap-coreutils&co
46 ;;; Pre-built packages that are used to bootstrap the
47 ;;; distribution--i.e., to build all the core packages from scratch.
54 ;;; Helper procedures.
57 (define (bootstrap-origin source)
58 "Return a variant of SOURCE, an <origin> instance, whose method uses
59 %BOOTSTRAP-GUILE to do its job."
61 (lambda* (store url hash-algo hash
62 #:optional name #:key system)
63 (fetch store url hash-algo hash
64 #:guile %bootstrap-guile
67 (let ((orig-method (origin-method source)))
68 (origin (inherit source)
69 (method (cond ((eq? orig-method url-fetch)
71 (else orig-method))))))
73 (define (package-from-tarball name* source* program-to-test description*)
74 "Return a package that correspond to the extraction of SOURCE*.
75 PROGRAM-TO-TEST is a program to run after extraction of SOURCE*, to
76 check whether everything is alright."
81 (build-system trivial-build-system)
83 `(#:guile ,%bootstrap-guile
84 #:modules ((guix build utils))
86 (let ((out (assoc-ref %outputs "out"))
87 (tar (assoc-ref %build-inputs "tar"))
88 (xz (assoc-ref %build-inputs "xz"))
89 (tarball (assoc-ref %build-inputs "tarball")))
90 (use-modules (guix build utils))
93 (copy-file tarball "binaries.tar.xz")
94 (system* xz "-d" "binaries.tar.xz")
95 (let ((builddir (getcwd)))
96 (with-directory-excursion out
97 (and (zero? (system* tar "xvf"
98 (string-append builddir "/binaries.tar")))
99 (zero? (system* (string-append "bin/" ,program-to-test)
102 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
103 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
104 ("tarball" ,(bootstrap-origin (source* (%current-system))))))
105 (synopsis description*)
109 (define package-with-bootstrap-guile
112 "Return a variant of P such that all its origins are fetched with
114 (define rewritten-input
116 ((name (? origin? o))
117 `(,name ,(bootstrap-origin o)))
118 ((name (? package? p) sub-drvs ...)
119 `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
123 (source (match (package-source p)
124 ((? origin? o) (bootstrap-origin o))
126 (inputs (map rewritten-input
128 (native-inputs (map rewritten-input
129 (package-native-inputs p)))
130 (propagated-inputs (map rewritten-input
131 (package-propagated-inputs p)))))))
133 (define* (glibc-dynamic-linker #:optional (system (%current-system)))
134 "Return the name of Glibc's dynamic linker for SYSTEM."
135 (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
136 ((string=? system "i686-linux") "/lib/ld-linux.so.2")
137 (else (error "dynamic linker name not known for this system"
142 ;;; Bootstrap packages.
145 (define %bootstrap-guile
146 ;; The Guile used to run the build scripts of the initial derivations.
147 ;; It is just unpacked from a tarball containing a pre-built binary.
148 ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
150 ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
151 ;; support (for /etc/services).
152 (let ((raw (build-system
154 (description "Raw build system with direct store access")
155 (build (lambda* (store name source inputs #:key outputs system)
156 (define (->store file)
157 (add-to-store store file #t "sha256"
158 (or (search-bootstrap-binary file
160 (error "bootstrap binary not found"
163 (let* ((tar (->store "tar"))
165 (mkdir (->store "mkdir"))
166 (bash (->store "bash"))
167 (guile (->store "guile-2.0.7.tar.xz"))
169 (add-text-to-store store
170 "build-bootstrap-guile.sh"
172 echo \"unpacking bootstrap Guile to '$out'...\"
178 $out/bin/guile --version~%"
180 (list mkdir xz guile tar))))
181 (derivation store name system
183 `((,bash) (,builder)))))))))
185 (name "guile-bootstrap")
189 (synopsis "Bootstrap Guile")
190 (description "Pre-built Guile for bootstrapping purposes.")
194 (define %bootstrap-base-urls
195 ;; This is where the initial binaries come from.
196 '("http://alpha.gnu.org/gnu/guix/bootstrap"
197 "http://www.fdn.fr/~lcourtes/software/guix/packages"))
199 (define %bootstrap-coreutils&co
200 (package-from-tarball "bootstrap-binaries"
204 (uri (map (cut string-append <> "/" system
205 "/20130105/static-binaries.tar.xz")
206 %bootstrap-base-urls))
211 "0md23alzy6nc5f16pric7mkagczdzr8xbh074sb3rjzrls06j1ls"))
214 "0nzj1lmm9b94g7k737cr4w1dv282w5nmhb53238ikax9r6pkc0yb"))))))
215 "true" ; the program to test
216 "Bootstrap binaries of Coreutils, Awk, etc."))
218 (define %bootstrap-binutils
219 (package-from-tarball "binutils-bootstrap"
223 (uri (map (cut string-append <> "/" system
224 "/20130105/binutils-2.22.tar.xz")
225 %bootstrap-base-urls))
230 "1ffmk2yy2pxvkqgzrkzp3s4jpn4qaaksyk3b5nsc5cjwfm7qkgzh"))
233 "1rafk6aq4sayvv3r3d2khn93nkyzf002xzh0xadlyci4mznr6b0a"))))))
234 "ld" ; the program to test
235 "Bootstrap binaries of the GNU Binutils"))
237 (define %bootstrap-glibc
240 (name "glibc-bootstrap")
243 (build-system trivial-build-system)
245 `(#:guile ,%bootstrap-guile
246 #:modules ((guix build utils))
248 (let ((out (assoc-ref %outputs "out"))
249 (tar (assoc-ref %build-inputs "tar"))
250 (xz (assoc-ref %build-inputs "xz"))
251 (tarball (assoc-ref %build-inputs "tarball")))
252 (use-modules (guix build utils))
255 (copy-file tarball "binaries.tar.xz")
256 (system* xz "-d" "binaries.tar.xz")
257 (let ((builddir (getcwd)))
258 (with-directory-excursion out
260 (string-append builddir
264 ;; Patch libc.so so it refers to the right path.
265 (substitute* "lib/libc.so"
266 (("/[^ ]+/lib/(libc|ld)" _ prefix)
267 (string-append out "/lib/" prefix))))))))
269 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
270 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
271 ("tarball" ,(bootstrap-origin
274 (uri (map (cut string-append <> "/" (%current-system)
275 "/20130105/glibc-2.17.tar.xz")
276 %bootstrap-base-urls))
278 (match (%current-system)
281 "18kv1z9d8dr1j3hm9w7663kchqw9p6rsx11n1m143jgba2jz6jy3"))
284 "08hv8i0axwnihrcgbz19x0a7s6zyv3yx38x8r29liwl8h82x9g88")))))))))
285 (synopsis "Bootstrap binaries and headers of the GNU C Library")
289 (define %bootstrap-gcc
290 ;; The initial GCC. Uses binaries from a tarball typically built by
291 ;; %GCC-BOOTSTRAP-TARBALL.
293 (name "gcc-bootstrap")
296 (build-system trivial-build-system)
298 `(#:guile ,%bootstrap-guile
299 #:modules ((guix build utils))
301 (let ((out (assoc-ref %outputs "out"))
302 (tar (assoc-ref %build-inputs "tar"))
303 (xz (assoc-ref %build-inputs "xz"))
304 (bash (assoc-ref %build-inputs "bash"))
305 (libc (assoc-ref %build-inputs "libc"))
306 (tarball (assoc-ref %build-inputs "tarball")))
307 (use-modules (guix build utils)
311 (copy-file tarball "binaries.tar.xz")
312 (system* xz "-d" "binaries.tar.xz")
313 (let ((builddir (getcwd))
314 (bindir (string-append out "/bin")))
315 (with-directory-excursion out
317 (string-append builddir "/binaries.tar")))
319 (with-directory-excursion bindir
321 (rename-file "gcc" ".gcc-wrapped")
322 (call-with-output-file "gcc"
325 exec ~a/bin/.gcc-wrapped -B~a/lib \
326 -Wl,-rpath -Wl,~a/lib \
327 -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
330 ,(glibc-dynamic-linker))))
332 (chmod "gcc" #o555))))))
334 `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
335 ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
336 ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
337 ("libc" ,%bootstrap-glibc)
338 ("tarball" ,(bootstrap-origin
341 (uri (map (cut string-append <> "/" (%current-system)
342 "/20130105/gcc-4.7.2.tar.xz")
343 %bootstrap-base-urls))
345 (match (%current-system)
348 "1x1p7han5crnbw906iwdifykr6grzm0w27dy9gz75j0q1b32i4px"))
351 "06wqs0xxnpw3hn0xjb4c9cs0899p1xwkcysa2rvzhvpra0c5vsg2")))))))))
352 (synopsis "Bootstrap binaries of the GNU Compiler Collection")
356 (define %bootstrap-inputs
357 ;; The initial, pre-built inputs. From now on, we can start building our
359 `(("libc" ,%bootstrap-glibc)
360 ("gcc" ,%bootstrap-gcc)
361 ("binutils" ,%bootstrap-binutils)
362 ("coreutils&co" ,%bootstrap-coreutils&co)
364 ;; In gnu-build-system.scm, we rely on the availability of Bash.
365 ("bash" ,%bootstrap-coreutils&co)))
367 ;;; bootstrap.scm ends here