You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
15 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  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.
  10. ;;;
  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.
  15. ;;;
  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/>.
  18. (define-module (gnu packages bootstrap)
  19. #:use-module (guix licenses)
  20. #:use-module (gnu packages)
  21. #:use-module (guix packages)
  22. #:use-module (guix download)
  23. #:use-module (guix build-system)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (guix build-system trivial)
  26. #:use-module ((guix store) #:select (add-to-store add-text-to-store))
  27. #:use-module ((guix derivations) #:select (derivation))
  28. #:use-module (guix utils)
  29. #:use-module (srfi srfi-1)
  30. #:use-module (srfi srfi-26)
  31. #:use-module (ice-9 match)
  32. #:export (bootstrap-origin
  33. package-with-bootstrap-guile
  34. glibc-dynamic-linker
  35. %bootstrap-guile
  36. %bootstrap-coreutils&co
  37. %bootstrap-binutils
  38. %bootstrap-gcc
  39. %bootstrap-glibc
  40. %bootstrap-inputs))
  41. ;;; Commentary:
  42. ;;;
  43. ;;; Pre-built packages that are used to bootstrap the
  44. ;;; distribution--i.e., to build all the core packages from scratch.
  45. ;;;
  46. ;;; Code:
  47. ;;;
  48. ;;; Helper procedures.
  49. ;;;
  50. (define (bootstrap-origin source)
  51. "Return a variant of SOURCE, an <origin> instance, whose method uses
  52. %BOOTSTRAP-GUILE to do its job."
  53. (define (boot fetch)
  54. (lambda* (store url hash-algo hash
  55. #:optional name #:key system)
  56. (fetch store url hash-algo hash
  57. #:guile %bootstrap-guile
  58. #:system system)))
  59. (let ((orig-method (origin-method source)))
  60. (origin (inherit source)
  61. (method (cond ((eq? orig-method url-fetch)
  62. (boot url-fetch))
  63. (else orig-method))))))
  64. (define (package-from-tarball name* source* program-to-test description*)
  65. "Return a package that correspond to the extraction of SOURCE*.
  66. PROGRAM-TO-TEST is a program to run after extraction of SOURCE*, to
  67. check whether everything is alright."
  68. (package
  69. (name name*)
  70. (version "0")
  71. (source #f)
  72. (build-system trivial-build-system)
  73. (arguments
  74. `(#:guile ,%bootstrap-guile
  75. #:modules ((guix build utils))
  76. #:builder
  77. (let ((out (assoc-ref %outputs "out"))
  78. (tar (assoc-ref %build-inputs "tar"))
  79. (xz (assoc-ref %build-inputs "xz"))
  80. (tarball (assoc-ref %build-inputs "tarball")))
  81. (use-modules (guix build utils))
  82. (mkdir out)
  83. (copy-file tarball "binaries.tar.xz")
  84. (system* xz "-d" "binaries.tar.xz")
  85. (let ((builddir (getcwd)))
  86. (with-directory-excursion out
  87. (and (zero? (system* tar "xvf"
  88. (string-append builddir "/binaries.tar")))
  89. (zero? (system* (string-append "bin/" ,program-to-test)
  90. "--version"))))))))
  91. (inputs
  92. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  93. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  94. ("tarball" ,(bootstrap-origin (source* (%current-system))))))
  95. (synopsis description*)
  96. (description #f)
  97. (home-page #f)
  98. (license #f)))
  99. (define package-with-bootstrap-guile
  100. (memoize
  101. (lambda (p)
  102. "Return a variant of P such that all its origins are fetched with
  103. %BOOTSTRAP-GUILE."
  104. (define rewritten-input
  105. (match-lambda
  106. ((name (? origin? o))
  107. `(,name ,(bootstrap-origin o)))
  108. ((name (? package? p) sub-drvs ...)
  109. `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
  110. (x x)))
  111. (package (inherit p)
  112. (source (match (package-source p)
  113. ((? origin? o) (bootstrap-origin o))
  114. (s s)))
  115. (inputs (map rewritten-input
  116. (package-inputs p)))
  117. (native-inputs (map rewritten-input
  118. (package-native-inputs p)))
  119. (propagated-inputs (map rewritten-input
  120. (package-propagated-inputs p)))))))
  121. (define* (glibc-dynamic-linker
  122. #:optional (system (or (and=> (%current-target-system)
  123. gnu-triplet->nix-system)
  124. (%current-system))))
  125. "Return the name of Glibc's dynamic linker for SYSTEM."
  126. (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
  127. ((string=? system "i686-linux") "/lib/ld-linux.so.2")
  128. ((string=? system "mips64el-linux") "/lib/ld.so.1")
  129. (else (error "dynamic linker name not known for this system"
  130. system))))
  131. ;;;
  132. ;;; Bootstrap packages.
  133. ;;;
  134. (define %bootstrap-guile
  135. ;; The Guile used to run the build scripts of the initial derivations.
  136. ;; It is just unpacked from a tarball containing a pre-built binary.
  137. ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
  138. ;;
  139. ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
  140. ;; support (for /etc/services).
  141. (let ((raw (build-system
  142. (name "raw")
  143. (description "Raw build system with direct store access")
  144. (build (lambda* (store name source inputs
  145. #:key outputs system search-paths)
  146. (define (->store file)
  147. (add-to-store store file #t "sha256"
  148. (or (search-bootstrap-binary file
  149. system)
  150. (error "bootstrap binary not found"
  151. file system))))
  152. (let* ((tar (->store "tar"))
  153. (xz (->store "xz"))
  154. (mkdir (->store "mkdir"))
  155. (bash (->store "bash"))
  156. (guile (->store "guile-2.0.7.tar.xz"))
  157. (builder
  158. (add-text-to-store store
  159. "build-bootstrap-guile.sh"
  160. (format #f "
  161. echo \"unpacking bootstrap Guile to '$out'...\"
  162. ~a $out
  163. cd $out
  164. ~a -dc < ~a | ~a xv
  165. # Sanity check.
  166. $out/bin/guile --version~%"
  167. mkdir xz guile tar)
  168. (list mkdir xz guile tar))))
  169. (derivation store name
  170. bash `(,builder)
  171. #:system system
  172. #:inputs `((,bash) (,builder)))))))))
  173. (package
  174. (name "guile-bootstrap")
  175. (version "2.0")
  176. (source #f)
  177. (build-system raw)
  178. (synopsis "Bootstrap Guile")
  179. (description "Pre-built Guile for bootstrapping purposes.")
  180. (home-page #f)
  181. (license lgpl3+))))
  182. (define %bootstrap-base-urls
  183. ;; This is where the initial binaries come from.
  184. '("http://alpha.gnu.org/gnu/guix/bootstrap"
  185. "http://www.fdn.fr/~lcourtes/software/guix/packages"))
  186. (define %bootstrap-coreutils&co
  187. (package-from-tarball "bootstrap-binaries"
  188. (lambda (system)
  189. (origin
  190. (method url-fetch)
  191. (uri (map (cut string-append <> "/" system
  192. "/20130105/static-binaries.tar.xz")
  193. %bootstrap-base-urls))
  194. (sha256
  195. (match system
  196. ("x86_64-linux"
  197. (base32
  198. "0md23alzy6nc5f16pric7mkagczdzr8xbh074sb3rjzrls06j1ls"))
  199. ("i686-linux"
  200. (base32
  201. "0nzj1lmm9b94g7k737cr4w1dv282w5nmhb53238ikax9r6pkc0yb"))))))
  202. "true" ; the program to test
  203. "Bootstrap binaries of Coreutils, Awk, etc."))
  204. (define %bootstrap-binutils
  205. (package-from-tarball "binutils-bootstrap"
  206. (lambda (system)
  207. (origin
  208. (method url-fetch)
  209. (uri (map (cut string-append <> "/" system
  210. "/20130105/binutils-2.22.tar.xz")
  211. %bootstrap-base-urls))
  212. (sha256
  213. (match system
  214. ("x86_64-linux"
  215. (base32
  216. "1ffmk2yy2pxvkqgzrkzp3s4jpn4qaaksyk3b5nsc5cjwfm7qkgzh"))
  217. ("i686-linux"
  218. (base32
  219. "1rafk6aq4sayvv3r3d2khn93nkyzf002xzh0xadlyci4mznr6b0a"))))))
  220. "ld" ; the program to test
  221. "Bootstrap binaries of the GNU Binutils"))
  222. (define %bootstrap-glibc
  223. ;; The initial libc.
  224. (package
  225. (name "glibc-bootstrap")
  226. (version "0")
  227. (source #f)
  228. (build-system trivial-build-system)
  229. (arguments
  230. `(#:guile ,%bootstrap-guile
  231. #:modules ((guix build utils))
  232. #:builder
  233. (let ((out (assoc-ref %outputs "out"))
  234. (tar (assoc-ref %build-inputs "tar"))
  235. (xz (assoc-ref %build-inputs "xz"))
  236. (tarball (assoc-ref %build-inputs "tarball")))
  237. (use-modules (guix build utils))
  238. (mkdir out)
  239. (copy-file tarball "binaries.tar.xz")
  240. (system* xz "-d" "binaries.tar.xz")
  241. (let ((builddir (getcwd)))
  242. (with-directory-excursion out
  243. (system* tar "xvf"
  244. (string-append builddir
  245. "/binaries.tar"))
  246. (chmod "lib" #o755)
  247. ;; Patch libc.so so it refers to the right path.
  248. (substitute* "lib/libc.so"
  249. (("/[^ ]+/lib/(libc|ld)" _ prefix)
  250. (string-append out "/lib/" prefix))))))))
  251. (inputs
  252. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  253. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  254. ("tarball" ,(bootstrap-origin
  255. (origin
  256. (method url-fetch)
  257. (uri (map (cut string-append <> "/" (%current-system)
  258. "/20130105/glibc-2.17.tar.xz")
  259. %bootstrap-base-urls))
  260. (sha256
  261. (match (%current-system)
  262. ("x86_64-linux"
  263. (base32
  264. "18kv1z9d8dr1j3hm9w7663kchqw9p6rsx11n1m143jgba2jz6jy3"))
  265. ("i686-linux"
  266. (base32
  267. "08hv8i0axwnihrcgbz19x0a7s6zyv3yx38x8r29liwl8h82x9g88")))))))))
  268. (synopsis "Bootstrap binaries and headers of the GNU C Library")
  269. (description #f)
  270. (home-page #f)
  271. (license lgpl2.1+)))
  272. (define %bootstrap-gcc
  273. ;; The initial GCC. Uses binaries from a tarball typically built by
  274. ;; %GCC-BOOTSTRAP-TARBALL.
  275. (package
  276. (name "gcc-bootstrap")
  277. (version "0")
  278. (source #f)
  279. (build-system trivial-build-system)
  280. (arguments
  281. `(#:guile ,%bootstrap-guile
  282. #:modules ((guix build utils))
  283. #:builder
  284. (let ((out (assoc-ref %outputs "out"))
  285. (tar (assoc-ref %build-inputs "tar"))
  286. (xz (assoc-ref %build-inputs "xz"))
  287. (bash (assoc-ref %build-inputs "bash"))
  288. (libc (assoc-ref %build-inputs "libc"))
  289. (tarball (assoc-ref %build-inputs "tarball")))
  290. (use-modules (guix build utils)
  291. (ice-9 popen))
  292. (mkdir out)
  293. (copy-file tarball "binaries.tar.xz")
  294. (system* xz "-d" "binaries.tar.xz")
  295. (let ((builddir (getcwd))
  296. (bindir (string-append out "/bin")))
  297. (with-directory-excursion out
  298. (system* tar "xvf"
  299. (string-append builddir "/binaries.tar")))
  300. (with-directory-excursion bindir
  301. (chmod "." #o755)
  302. (rename-file "gcc" ".gcc-wrapped")
  303. (call-with-output-file "gcc"
  304. (lambda (p)
  305. (format p "#!~a
  306. exec ~a/bin/.gcc-wrapped -B~a/lib \
  307. -Wl,-rpath -Wl,~a/lib \
  308. -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
  309. bash
  310. out libc libc libc
  311. ,(glibc-dynamic-linker))))
  312. (chmod "gcc" #o555))))))
  313. (inputs
  314. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  315. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  316. ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
  317. ("libc" ,%bootstrap-glibc)
  318. ("tarball" ,(bootstrap-origin
  319. (origin
  320. (method url-fetch)
  321. (uri (map (cut string-append <> "/" (%current-system)
  322. "/20130105/gcc-4.7.2.tar.xz")
  323. %bootstrap-base-urls))
  324. (sha256
  325. (match (%current-system)
  326. ("x86_64-linux"
  327. (base32
  328. "1x1p7han5crnbw906iwdifykr6grzm0w27dy9gz75j0q1b32i4px"))
  329. ("i686-linux"
  330. (base32
  331. "06wqs0xxnpw3hn0xjb4c9cs0899p1xwkcysa2rvzhvpra0c5vsg2")))))))))
  332. (native-search-paths
  333. (list (search-path-specification
  334. (variable "CPATH")
  335. (directories '("include")))
  336. (search-path-specification
  337. (variable "LIBRARY_PATH")
  338. (directories '("lib" "lib64")))))
  339. (synopsis "Bootstrap binaries of the GNU Compiler Collection")
  340. (description #f)
  341. (home-page #f)
  342. (license gpl3+)))
  343. (define %bootstrap-inputs
  344. ;; The initial, pre-built inputs. From now on, we can start building our
  345. ;; own packages.
  346. `(("libc" ,%bootstrap-glibc)
  347. ("gcc" ,%bootstrap-gcc)
  348. ("binutils" ,%bootstrap-binutils)
  349. ("coreutils&co" ,%bootstrap-coreutils&co)
  350. ;; In gnu-build-system.scm, we rely on the availability of Bash.
  351. ("bash" ,%bootstrap-coreutils&co)))
  352. ;;; bootstrap.scm ends here