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.
 
 
 
 
 
 

427 lines
17 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. (define %bootstrap-patch-inputs
  60. ;; Packages used when an <origin> has a non-empty 'patches' field.
  61. `(("tar" ,%bootstrap-coreutils&co)
  62. ("xz" ,%bootstrap-coreutils&co)
  63. ("bzip2" ,%bootstrap-coreutils&co)
  64. ("gzip" ,%bootstrap-coreutils&co)
  65. ("patch" ,%bootstrap-coreutils&co)))
  66. (let ((orig-method (origin-method source)))
  67. (origin (inherit source)
  68. (method (cond ((eq? orig-method url-fetch)
  69. (boot url-fetch))
  70. (else orig-method)))
  71. (patch-guile %bootstrap-guile)
  72. (patch-inputs %bootstrap-patch-inputs))))
  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."
  77. (package
  78. (name name)
  79. (version "0")
  80. (build-system trivial-build-system)
  81. (arguments
  82. `(#:guile ,%bootstrap-guile
  83. #:modules ((guix build utils))
  84. #:builder
  85. (let ((out (assoc-ref %outputs "out"))
  86. (tar (assoc-ref %build-inputs "tar"))
  87. (xz (assoc-ref %build-inputs "xz"))
  88. (tarball (assoc-ref %build-inputs "tarball")))
  89. (use-modules (guix build utils))
  90. (mkdir out)
  91. (copy-file tarball "binaries.tar.xz")
  92. (system* xz "-d" "binaries.tar.xz")
  93. (let ((builddir (getcwd)))
  94. (with-directory-excursion out
  95. (and (zero? (system* tar "xvf"
  96. (string-append builddir "/binaries.tar")))
  97. (zero? (system* (string-append "bin/" ,program-to-test)
  98. "--version"))))))))
  99. (inputs
  100. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  101. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  102. ("tarball" ,(bootstrap-origin (source (%current-system))))))
  103. (source #f)
  104. (synopsis description)
  105. (description #f)
  106. (home-page #f)
  107. (license #f)))
  108. (define package-with-bootstrap-guile
  109. (memoize
  110. (lambda (p)
  111. "Return a variant of P such that all its origins are fetched with
  112. %BOOTSTRAP-GUILE."
  113. (define rewritten-input
  114. (match-lambda
  115. ((name (? origin? o))
  116. `(,name ,(bootstrap-origin o)))
  117. ((name (? package? p) sub-drvs ...)
  118. `(,name ,(package-with-bootstrap-guile p) ,@sub-drvs))
  119. (x x)))
  120. (package (inherit p)
  121. (source (match (package-source p)
  122. ((? origin? o) (bootstrap-origin o))
  123. (s s)))
  124. (inputs (map rewritten-input
  125. (package-inputs p)))
  126. (native-inputs (map rewritten-input
  127. (package-native-inputs p)))
  128. (propagated-inputs (map rewritten-input
  129. (package-propagated-inputs p)))))))
  130. (define* (glibc-dynamic-linker
  131. #:optional (system (or (and=> (%current-target-system)
  132. gnu-triplet->nix-system)
  133. (%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. ((string=? system "mips64el-linux") "/lib/ld.so.1")
  138. (else (error "dynamic linker name not known for this system"
  139. system))))
  140. ;;;
  141. ;;; Bootstrap packages.
  142. ;;;
  143. (define %bootstrap-guile
  144. ;; The Guile used to run the build scripts of the initial derivations.
  145. ;; It is just unpacked from a tarball containing a pre-built binary.
  146. ;; This is typically built using %GUILE-BOOTSTRAP-TARBALL below.
  147. ;;
  148. ;; XXX: Would need libc's `libnss_files2.so' for proper `getaddrinfo'
  149. ;; support (for /etc/services).
  150. (let ((raw (build-system
  151. (name "raw")
  152. (description "Raw build system with direct store access")
  153. (build (lambda* (store name source inputs
  154. #:key outputs system search-paths)
  155. (define (->store file)
  156. (add-to-store store file #t "sha256"
  157. (or (search-bootstrap-binary file
  158. system)
  159. (error "bootstrap binary not found"
  160. file system))))
  161. (let* ((tar (->store "tar"))
  162. (xz (->store "xz"))
  163. (mkdir (->store "mkdir"))
  164. (bash (->store "bash"))
  165. (guile (->store
  166. (match (%current-system)
  167. ("mips64el-linux"
  168. "guile-2.0.9.tar.xz")
  169. (_
  170. "guile-2.0.7.tar.xz"))))
  171. (builder
  172. (add-text-to-store store
  173. "build-bootstrap-guile.sh"
  174. (format #f "
  175. echo \"unpacking bootstrap Guile to '$out'...\"
  176. ~a $out
  177. cd $out
  178. ~a -dc < ~a | ~a xv
  179. # Sanity check.
  180. $out/bin/guile --version~%"
  181. mkdir xz guile tar)
  182. (list mkdir xz guile tar))))
  183. (derivation store name
  184. bash `(,builder)
  185. #:system system
  186. #:inputs `((,bash) (,builder)))))))))
  187. (package
  188. (name "guile-bootstrap")
  189. (version "2.0")
  190. (source #f)
  191. (build-system raw)
  192. (synopsis "Bootstrap Guile")
  193. (description "Pre-built Guile for bootstrapping purposes.")
  194. (home-page #f)
  195. (license lgpl3+))))
  196. (define %bootstrap-base-urls
  197. ;; This is where the initial binaries come from.
  198. '("http://alpha.gnu.org/gnu/guix/bootstrap"
  199. "http://www.fdn.fr/~lcourtes/software/guix/packages"))
  200. (define %bootstrap-coreutils&co
  201. (package-from-tarball "bootstrap-binaries"
  202. (lambda (system)
  203. (origin
  204. (method url-fetch)
  205. (uri (map (cut string-append <> "/" system
  206. (match system
  207. ("mips64el-linux"
  208. "/20131017/static-binaries.tar.xz")
  209. (_
  210. "/20130105/static-binaries.tar.xz")))
  211. %bootstrap-base-urls))
  212. (sha256
  213. (match system
  214. ("x86_64-linux"
  215. (base32
  216. "0md23alzy6nc5f16pric7mkagczdzr8xbh074sb3rjzrls06j1ls"))
  217. ("i686-linux"
  218. (base32
  219. "0nzj1lmm9b94g7k737cr4w1dv282w5nmhb53238ikax9r6pkc0yb"))
  220. ("mips64el-linux"
  221. (base32
  222. "17k5f1322b7n1difhlyw4cghxvq8fxj7wlhzghh4y362fshvvw1c"))))))
  223. "true" ; the program to test
  224. "Bootstrap binaries of Coreutils, Awk, etc."))
  225. (define %bootstrap-binutils
  226. (package-from-tarball "binutils-bootstrap"
  227. (lambda (system)
  228. (origin
  229. (method url-fetch)
  230. (uri (map (cut string-append <> "/" system
  231. (match system
  232. ("mips64el-linux"
  233. "/20131017/binutils-2.23.2.tar.xz")
  234. (_
  235. "/20130105/binutils-2.22.tar.xz")))
  236. %bootstrap-base-urls))
  237. (sha256
  238. (match system
  239. ("x86_64-linux"
  240. (base32
  241. "1ffmk2yy2pxvkqgzrkzp3s4jpn4qaaksyk3b5nsc5cjwfm7qkgzh"))
  242. ("i686-linux"
  243. (base32
  244. "1rafk6aq4sayvv3r3d2khn93nkyzf002xzh0xadlyci4mznr6b0a"))
  245. ("mips64el-linux"
  246. (base32
  247. "1dpnmscgg1fxg9xmlbvcm1d8h8brjgqwaal748w3v3qf33is4sl6"))))))
  248. "ld" ; the program to test
  249. "Bootstrap binaries of the GNU Binutils"))
  250. (define %bootstrap-glibc
  251. ;; The initial libc.
  252. (package
  253. (name "glibc-bootstrap")
  254. (version "0")
  255. (source #f)
  256. (build-system trivial-build-system)
  257. (arguments
  258. `(#:guile ,%bootstrap-guile
  259. #:modules ((guix build utils))
  260. #:builder
  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. (use-modules (guix build utils))
  266. (mkdir out)
  267. (copy-file tarball "binaries.tar.xz")
  268. (system* xz "-d" "binaries.tar.xz")
  269. (let ((builddir (getcwd)))
  270. (with-directory-excursion out
  271. (system* tar "xvf"
  272. (string-append builddir
  273. "/binaries.tar"))
  274. (chmod "lib" #o755)
  275. ;; Patch libc.so so it refers to the right path.
  276. (substitute* "lib/libc.so"
  277. (("/[^ ]+/lib/(libc|ld)" _ prefix)
  278. (string-append out "/lib/" prefix))))))))
  279. (inputs
  280. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  281. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  282. ("tarball" ,(bootstrap-origin
  283. (origin
  284. (method url-fetch)
  285. (uri (map (cut string-append <> "/" (%current-system)
  286. (match (%current-system)
  287. ("mips64el-linux"
  288. "/20131017/glibc-2.18.tar.xz")
  289. (_
  290. "/20130105/glibc-2.17.tar.xz")))
  291. %bootstrap-base-urls))
  292. (sha256
  293. (match (%current-system)
  294. ("x86_64-linux"
  295. (base32
  296. "18kv1z9d8dr1j3hm9w7663kchqw9p6rsx11n1m143jgba2jz6jy3"))
  297. ("i686-linux"
  298. (base32
  299. "08hv8i0axwnihrcgbz19x0a7s6zyv3yx38x8r29liwl8h82x9g88"))
  300. ("mips64el-linux"
  301. (base32
  302. "1w9x8r2him7qbqlm7ah1aq04kk2ydma44jzgdzsdj3kjx36sqyq1")))))))))
  303. (synopsis "Bootstrap binaries and headers of the GNU C Library")
  304. (description #f)
  305. (home-page #f)
  306. (license lgpl2.1+)))
  307. (define %bootstrap-gcc
  308. ;; The initial GCC. Uses binaries from a tarball typically built by
  309. ;; %GCC-BOOTSTRAP-TARBALL.
  310. (package
  311. (name "gcc-bootstrap")
  312. (version "0")
  313. (source #f)
  314. (build-system trivial-build-system)
  315. (arguments
  316. `(#:guile ,%bootstrap-guile
  317. #:modules ((guix build utils))
  318. #:builder
  319. (let ((out (assoc-ref %outputs "out"))
  320. (tar (assoc-ref %build-inputs "tar"))
  321. (xz (assoc-ref %build-inputs "xz"))
  322. (bash (assoc-ref %build-inputs "bash"))
  323. (libc (assoc-ref %build-inputs "libc"))
  324. (tarball (assoc-ref %build-inputs "tarball")))
  325. (use-modules (guix build utils)
  326. (ice-9 popen))
  327. (mkdir out)
  328. (copy-file tarball "binaries.tar.xz")
  329. (system* xz "-d" "binaries.tar.xz")
  330. (let ((builddir (getcwd))
  331. (bindir (string-append out "/bin")))
  332. (with-directory-excursion out
  333. (system* tar "xvf"
  334. (string-append builddir "/binaries.tar")))
  335. (with-directory-excursion bindir
  336. (chmod "." #o755)
  337. (rename-file "gcc" ".gcc-wrapped")
  338. (call-with-output-file "gcc"
  339. (lambda (p)
  340. (format p "#!~a
  341. exec ~a/bin/.gcc-wrapped -B~a/lib \
  342. -Wl,-rpath -Wl,~a/lib \
  343. -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
  344. bash
  345. out libc libc libc
  346. ,(glibc-dynamic-linker))))
  347. (chmod "gcc" #o555))))))
  348. (inputs
  349. `(("tar" ,(search-bootstrap-binary "tar" (%current-system)))
  350. ("xz" ,(search-bootstrap-binary "xz" (%current-system)))
  351. ("bash" ,(search-bootstrap-binary "bash" (%current-system)))
  352. ("libc" ,%bootstrap-glibc)
  353. ("tarball" ,(bootstrap-origin
  354. (origin
  355. (method url-fetch)
  356. (uri (map (cut string-append <> "/" (%current-system)
  357. (match (%current-system)
  358. ("mips64el-linux"
  359. "/20131017/gcc-4.7.3.tar.xz")
  360. (_
  361. "/20130105/gcc-4.7.2.tar.xz")))
  362. %bootstrap-base-urls))
  363. (sha256
  364. (match (%current-system)
  365. ("x86_64-linux"
  366. (base32
  367. "1x1p7han5crnbw906iwdifykr6grzm0w27dy9gz75j0q1b32i4px"))
  368. ("i686-linux"
  369. (base32
  370. "06wqs0xxnpw3hn0xjb4c9cs0899p1xwkcysa2rvzhvpra0c5vsg2"))
  371. ("mips64el-linux"
  372. (base32
  373. "0g9z8cdlnlzbg67607rxxfk5vi4xjsdc7c2agvdnyzlp0shib6rb")))))))))
  374. (native-search-paths
  375. (list (search-path-specification
  376. (variable "CPATH")
  377. (directories '("include")))
  378. (search-path-specification
  379. (variable "LIBRARY_PATH")
  380. (directories '("lib" "lib64")))))
  381. (synopsis "Bootstrap binaries of the GNU Compiler Collection")
  382. (description #f)
  383. (home-page #f)
  384. (license gpl3+)))
  385. (define %bootstrap-inputs
  386. ;; The initial, pre-built inputs. From now on, we can start building our
  387. ;; own packages.
  388. `(("libc" ,%bootstrap-glibc)
  389. ("gcc" ,%bootstrap-gcc)
  390. ("binutils" ,%bootstrap-binutils)
  391. ("coreutils&co" ,%bootstrap-coreutils&co)
  392. ;; In gnu-build-system.scm, we rely on the availability of Bash.
  393. ("bash" ,%bootstrap-coreutils&co)))
  394. ;;; bootstrap.scm ends here