commencement.scm 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014 Andreas Enge <andreas@enge.fr>
  4. ;;; Copyright © 2012 Nikita Karetnikov <nikita@karetnikov.org>
  5. ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
  6. ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
  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. (define-module (gnu packages commencement)
  23. #:use-module ((guix licenses)
  24. #:select (gpl3+ lgpl2.0+ public-domain))
  25. #:use-module (gnu packages)
  26. #:use-module (gnu packages bootstrap)
  27. #:use-module (gnu packages base)
  28. #:use-module (gnu packages bash)
  29. #:use-module (gnu packages gcc)
  30. #:use-module (gnu packages m4)
  31. #:use-module (gnu packages indent)
  32. #:use-module (gnu packages file)
  33. #:use-module (gnu packages gawk)
  34. #:use-module (gnu packages bison)
  35. #:use-module (gnu packages flex)
  36. #:use-module (gnu packages guile)
  37. #:use-module (gnu packages gettext)
  38. #:use-module (gnu packages multiprecision)
  39. #:use-module (gnu packages compression)
  40. #:use-module (gnu packages perl)
  41. #:use-module (gnu packages linux)
  42. #:use-module (gnu packages hurd)
  43. #:use-module (gnu packages texinfo)
  44. #:use-module (gnu packages pkg-config)
  45. #:use-module (guix packages)
  46. #:use-module (guix download)
  47. #:use-module (guix build-system gnu)
  48. #:use-module (guix build-system trivial)
  49. #:use-module (guix utils)
  50. #:use-module (srfi srfi-1)
  51. #:use-module (srfi srfi-26)
  52. #:use-module (ice-9 vlist)
  53. #:use-module (ice-9 match)
  54. #:use-module (ice-9 regex))
  55. ;;; Commentary:
  56. ;;;
  57. ;;; This is the commencement, this is where things start. Before the
  58. ;;; commencement, of course, there's the 'bootstrap' module, which provides us
  59. ;;; with the initial binaries. This module uses those bootstrap binaries to
  60. ;;; actually build up the whole tool chain that make up the implicit inputs of
  61. ;;; 'gnu-build-system'.
  62. ;;;
  63. ;;; To avoid circular dependencies, this module should not be imported
  64. ;;; directly from anywhere.
  65. ;;;
  66. ;;; Code:
  67. (define gnu-make-boot0
  68. (package-with-bootstrap-guile
  69. (package (inherit gnu-make)
  70. (name "make-boot0")
  71. (arguments
  72. `(#:guile ,%bootstrap-guile
  73. #:implicit-inputs? #f
  74. #:tests? #f ; cannot run "make check"
  75. ,@(substitute-keyword-arguments (package-arguments gnu-make)
  76. ((#:phases phases)
  77. `(modify-phases ,phases
  78. (replace 'build
  79. (lambda _
  80. (zero? (system* "./build.sh"))))
  81. (replace 'install
  82. (lambda* (#:key outputs #:allow-other-keys)
  83. (let* ((out (assoc-ref outputs "out"))
  84. (bin (string-append out "/bin")))
  85. (install-file "make" bin)))))))))
  86. (native-inputs '()) ; no need for 'pkg-config'
  87. (inputs %bootstrap-inputs))))
  88. (define diffutils-boot0
  89. (package-with-bootstrap-guile
  90. (let ((p (package-with-explicit-inputs diffutils
  91. `(("make" ,gnu-make-boot0)
  92. ,@%bootstrap-inputs)
  93. #:guile %bootstrap-guile)))
  94. (package (inherit p)
  95. (name "diffutils-boot0")
  96. (arguments `(#:tests? #f ; the test suite needs diffutils
  97. ,@(package-arguments p)))))))
  98. (define findutils-boot0
  99. (package-with-bootstrap-guile
  100. (package-with-explicit-inputs (package
  101. (inherit findutils)
  102. (name "findutils-boot0"))
  103. `(("make" ,gnu-make-boot0)
  104. ("diffutils" ,diffutils-boot0) ; for tests
  105. ,@%bootstrap-inputs)
  106. (current-source-location)
  107. #:guile %bootstrap-guile)))
  108. (define file-boot0
  109. (package-with-bootstrap-guile
  110. (package-with-explicit-inputs (package/inherit file
  111. (name "file-boot0"))
  112. `(("make" ,gnu-make-boot0)
  113. ,@%bootstrap-inputs)
  114. (current-source-location)
  115. #:guile %bootstrap-guile)))
  116. (define %boot0-inputs
  117. `(("make" ,gnu-make-boot0)
  118. ("diffutils" ,diffutils-boot0)
  119. ("findutils" ,findutils-boot0)
  120. ("file" ,file-boot0)
  121. ,@%bootstrap-inputs))
  122. (define* (boot-triplet #:optional (system (%current-system)))
  123. ;; Return the triplet used to create the cross toolchain needed in the
  124. ;; first bootstrapping stage.
  125. (nix-system->gnu-triplet system "guix"))
  126. ;; Following Linux From Scratch, build a cross-toolchain in stage 0. That
  127. ;; toolchain actually targets the same OS and arch, but it has the advantage
  128. ;; of being independent of the libc and tools in %BOOTSTRAP-INPUTS, since
  129. ;; GCC-BOOT0 (below) is built without any reference to the target libc.
  130. (define binutils-boot0
  131. (package-with-bootstrap-guile
  132. (package/inherit binutils
  133. (name "binutils-cross-boot0")
  134. (arguments
  135. `(#:guile ,%bootstrap-guile
  136. #:implicit-inputs? #f
  137. #:modules ((guix build gnu-build-system)
  138. (guix build utils)
  139. (ice-9 ftw)) ; for 'scandir'
  140. #:phases (alist-cons-after
  141. 'install 'add-symlinks
  142. (lambda* (#:key outputs #:allow-other-keys)
  143. ;; The cross-gcc invokes 'as', 'ld', etc, without the
  144. ;; triplet prefix, so add symlinks.
  145. (let ((out (assoc-ref outputs "out"))
  146. (triplet-prefix (string-append ,(boot-triplet) "-")))
  147. (define (has-triplet-prefix? name)
  148. (string-prefix? triplet-prefix name))
  149. (define (remove-triplet-prefix name)
  150. (substring name (string-length triplet-prefix)))
  151. (with-directory-excursion (string-append out "/bin")
  152. (for-each (lambda (name)
  153. (symlink name (remove-triplet-prefix name)))
  154. (scandir "." has-triplet-prefix?)))
  155. #t))
  156. %standard-phases)
  157. ,@(substitute-keyword-arguments (package-arguments binutils)
  158. ((#:configure-flags cf)
  159. `(cons ,(string-append "--target=" (boot-triplet))
  160. ,cf)))))
  161. (inputs %boot0-inputs))))
  162. (define libstdc++-boot0
  163. ;; GCC's libcc1 is always built as a shared library (the top-level
  164. ;; 'Makefile.def' forcefully adds --enable-shared) and thus needs to refer
  165. ;; to libstdc++.so. We cannot build libstdc++-5.3 because it relies on
  166. ;; C++14 features missing in our bootstrap compiler.
  167. (let ((lib (package-with-bootstrap-guile (make-libstdc++ gcc-4.9))))
  168. (package
  169. (inherit lib)
  170. (name "libstdc++-boot0")
  171. (arguments
  172. `(#:guile ,%bootstrap-guile
  173. #:implicit-inputs? #f
  174. ;; XXX: libstdc++.so NEEDs ld.so for some reason.
  175. #:validate-runpath? #f
  176. ,@(package-arguments lib)))
  177. (inputs %boot0-inputs)
  178. (native-inputs '()))))
  179. (define gcc-boot0
  180. (package-with-bootstrap-guile
  181. (package (inherit gcc)
  182. (name "gcc-cross-boot0")
  183. (arguments
  184. `(#:guile ,%bootstrap-guile
  185. #:implicit-inputs? #f
  186. #:modules ((guix build gnu-build-system)
  187. (guix build utils)
  188. (ice-9 regex)
  189. (srfi srfi-1)
  190. (srfi srfi-26))
  191. ,@(substitute-keyword-arguments (package-arguments gcc)
  192. ((#:configure-flags flags)
  193. `(append (list ,(string-append "--target=" (boot-triplet))
  194. ;; No libc yet.
  195. "--without-headers"
  196. ;; Disable features not needed at this stage.
  197. "--disable-shared"
  198. "--enable-languages=c,c++"
  199. ;; libstdc++ cannot be built at this stage
  200. ;; ("Link tests are not allowed after
  201. ;; GCC_NO_EXECUTABLES.").
  202. "--disable-libstdc++-v3"
  203. "--disable-threads"
  204. "--disable-libmudflap"
  205. "--disable-libatomic"
  206. "--disable-libsanitizer"
  207. "--disable-libitm"
  208. "--disable-libgomp"
  209. "--disable-libcilkrts"
  210. "--disable-libvtv"
  211. "--disable-libssp"
  212. "--disable-libquadmath"
  213. "--disable-decimal-float")
  214. (remove (cut string-match
  215. "--(with-system-zlib|enable-languages.*)" <>)
  216. ,flags)))
  217. ((#:phases phases)
  218. `(alist-cons-after
  219. 'unpack 'unpack-gmp&co
  220. (lambda* (#:key inputs #:allow-other-keys)
  221. (let ((gmp (assoc-ref %build-inputs "gmp-source"))
  222. (mpfr (assoc-ref %build-inputs "mpfr-source"))
  223. (mpc (assoc-ref %build-inputs "mpc-source")))
  224. ;; To reduce the set of pre-built bootstrap inputs, build
  225. ;; GMP & co. from GCC.
  226. (for-each (lambda (source)
  227. (or (zero? (system* "tar" "xvf" source))
  228. (error "failed to unpack tarball"
  229. source)))
  230. (list gmp mpfr mpc))
  231. ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
  232. ,@(map (lambda (lib)
  233. ;; Drop trailing letters, as gmp-6.0.0a unpacks
  234. ;; into gmp-6.0.0.
  235. `(symlink ,(string-trim-right
  236. (package-full-name lib)
  237. char-set:letter)
  238. ,(package-name lib)))
  239. (list gmp-6.0 mpfr mpc))))
  240. (alist-cons-after
  241. 'install 'symlink-libgcc_eh
  242. (lambda* (#:key outputs #:allow-other-keys)
  243. (let ((out (assoc-ref outputs "lib")))
  244. ;; Glibc wants to link against libgcc_eh, so provide
  245. ;; it.
  246. (with-directory-excursion
  247. (string-append out "/lib/gcc/"
  248. ,(boot-triplet)
  249. "/" ,(package-version gcc))
  250. (symlink "libgcc.a" "libgcc_eh.a"))))
  251. ,phases))))))
  252. (inputs `(("gmp-source" ,(package-source gmp-6.0))
  253. ("mpfr-source" ,(package-source mpfr))
  254. ("mpc-source" ,(package-source mpc))
  255. ("binutils-cross" ,binutils-boot0)
  256. ;; The libstdc++ that libcc1 links against.
  257. ("libstdc++" ,libstdc++-boot0)
  258. ;; Call it differently so that the builder can check whether
  259. ;; the "libc" input is #f.
  260. ("libc-native" ,@(assoc-ref %boot0-inputs "libc"))
  261. ,@(alist-delete "libc" %boot0-inputs)))
  262. ;; No need for Texinfo at this stage.
  263. (native-inputs (alist-delete "texinfo"
  264. (package-native-inputs gcc))))))
  265. (define perl-boot0
  266. (let ((perl (package
  267. (inherit perl)
  268. (name "perl-boot0")
  269. (arguments
  270. ;; At the very least, this must not depend on GCC & co.
  271. (let ((args `(#:disallowed-references
  272. ,(list %bootstrap-binutils))))
  273. (substitute-keyword-arguments (package-arguments perl)
  274. ((#:phases phases)
  275. `(modify-phases ,phases
  276. ;; Pthread support is missing in the bootstrap compiler
  277. ;; (broken spec file), so disable it.
  278. (add-before 'configure 'disable-pthreads
  279. (lambda _
  280. (substitute* "Configure"
  281. (("^libswanted=(.*)pthread" _ before)
  282. (string-append "libswanted=" before)))))))
  283. ;; Do not configure with '-Dusethreads' since pthread
  284. ;; support is missing.
  285. ((#:configure-flags configure-flags)
  286. `(delete "-Dusethreads" ,configure-flags))))))))
  287. (package-with-bootstrap-guile
  288. (package-with-explicit-inputs perl
  289. %boot0-inputs
  290. (current-source-location)
  291. #:guile %bootstrap-guile))))
  292. (define bison-boot0
  293. ;; This Bison is needed to build MiG so we need it early in the process.
  294. ;; It is also needed to rebuild Bash's parser, which is modified by
  295. ;; its CVE patches. Remove it when it's no longer needed.
  296. (let* ((m4 (package-with-bootstrap-guile
  297. (package-with-explicit-inputs m4 %boot0-inputs
  298. (current-source-location)
  299. #:guile %bootstrap-guile)))
  300. (bison (package (inherit bison)
  301. (propagated-inputs `(("m4" ,m4)))
  302. (inputs '()) ;remove Flex...
  303. (arguments
  304. '(#:tests? #f ;... and thus disable tests
  305. ;; Zero timestamps in liby.a; this must be done
  306. ;; explicitly here because the bootstrap Binutils don't
  307. ;; do that (default is "cru".)
  308. #:make-flags '("ARFLAGS=crD" "RANLIB=ranlib -D"
  309. "V=1"))))))
  310. (package
  311. (inherit (package-with-bootstrap-guile
  312. (package-with-explicit-inputs bison %boot0-inputs
  313. (current-source-location)
  314. #:guile %bootstrap-guile)))
  315. (native-inputs `(("perl" ,perl-boot0))))))
  316. (define flex-boot0
  317. ;; This Flex is needed to build MiG.
  318. (let* ((flex (package (inherit flex)
  319. (native-inputs `(("bison" ,bison-boot0)))
  320. (propagated-inputs `(("m4" ,m4)))
  321. (inputs `(("indent" ,indent)))
  322. (arguments '(#:tests? #f)))))
  323. (package-with-bootstrap-guile
  324. (package-with-explicit-inputs flex %boot0-inputs
  325. (current-source-location)
  326. #:guile %bootstrap-guile))))
  327. (define (linux-libre-headers-boot0)
  328. "Return Linux-Libre header files for the bootstrap environment."
  329. ;; Note: this is wrapped in a thunk to nicely handle circular dependencies
  330. ;; between (gnu packages linux) and this module.
  331. (package-with-bootstrap-guile
  332. (package (inherit linux-libre-headers)
  333. (arguments `(#:guile ,%bootstrap-guile
  334. #:implicit-inputs? #f
  335. ,@(package-arguments linux-libre-headers)))
  336. (native-inputs
  337. `(("perl" ,perl-boot0)
  338. ,@%boot0-inputs)))))
  339. (define gnumach-headers-boot0
  340. (package-with-bootstrap-guile
  341. (package-with-explicit-inputs gnumach-headers
  342. %boot0-inputs
  343. (current-source-location)
  344. #:guile %bootstrap-guile)))
  345. (define mig-boot0
  346. (let* ((mig (package (inherit mig)
  347. (native-inputs `(("bison" ,bison-boot0)
  348. ("flex" ,flex-boot0)))
  349. (inputs `(("flex" ,flex-boot0)))
  350. (arguments
  351. `(#:configure-flags
  352. `(,(string-append "LDFLAGS=-Wl,-rpath="
  353. (assoc-ref %build-inputs "flex") "/lib/")))))))
  354. (package-with-bootstrap-guile
  355. (package-with-explicit-inputs mig %boot0-inputs
  356. (current-source-location)
  357. #:guile %bootstrap-guile))))
  358. (define hurd-headers-boot0
  359. (let ((hurd-headers (package (inherit hurd-headers)
  360. (native-inputs `(("mig" ,mig-boot0)))
  361. (inputs '()))))
  362. (package-with-bootstrap-guile
  363. (package-with-explicit-inputs hurd-headers %boot0-inputs
  364. (current-source-location)
  365. #:guile %bootstrap-guile))))
  366. (define hurd-minimal-boot0
  367. (let ((hurd-minimal (package (inherit hurd-minimal)
  368. (native-inputs `(("mig" ,mig-boot0)))
  369. (inputs '()))))
  370. (package-with-bootstrap-guile
  371. (package-with-explicit-inputs hurd-minimal %boot0-inputs
  372. (current-source-location)
  373. #:guile %bootstrap-guile))))
  374. (define (hurd-core-headers-boot0)
  375. "Return the Hurd and Mach headers as well as initial Hurd libraries for
  376. the bootstrap environment."
  377. (package-with-bootstrap-guile
  378. (package (inherit hurd-core-headers)
  379. (arguments `(#:guile ,%bootstrap-guile
  380. ,@(package-arguments hurd-core-headers)))
  381. (inputs
  382. `(("gnumach-headers" ,gnumach-headers-boot0)
  383. ("hurd-headers" ,hurd-headers-boot0)
  384. ("hurd-minimal" ,hurd-minimal-boot0)
  385. ,@%boot0-inputs)))))
  386. (define* (kernel-headers-boot0 #:optional (system (%current-system)))
  387. (match system
  388. ("i586-gnu" (hurd-core-headers-boot0))
  389. (_ (linux-libre-headers-boot0))))
  390. (define texinfo-boot0
  391. ;; Texinfo used to build libc's manual.
  392. ;; We build without ncurses because it fails to build at this stage, and
  393. ;; because we don't need the stand-alone Info reader.
  394. ;; Also, use %BOOT0-INPUTS to avoid building Perl once more.
  395. (let ((texinfo (package (inherit texinfo)
  396. (native-inputs '())
  397. (inputs `(("perl" ,perl-boot0)))
  398. ;; Some of Texinfo 6.1's tests would fail with "Couldn't
  399. ;; set UTF-8 character type in locale" but we don't have a
  400. ;; UTF-8 locale at this stage, so skip them.
  401. (arguments '(#:tests? #f)))))
  402. (package-with-bootstrap-guile
  403. (package-with-explicit-inputs texinfo %boot0-inputs
  404. (current-source-location)
  405. #:guile %bootstrap-guile))))
  406. (define ld-wrapper-boot0
  407. ;; We need this so binaries on Hurd will have libmachuser and libhurduser
  408. ;; in their RUNPATH, otherwise validate-runpath will fail.
  409. (make-ld-wrapper "ld-wrapper-boot0"
  410. #:target boot-triplet
  411. #:binutils binutils-boot0
  412. #:guile %bootstrap-guile
  413. #:bash (car (assoc-ref %boot0-inputs "bash"))))
  414. (define %boot1-inputs
  415. ;; 2nd stage inputs.
  416. `(("gcc" ,gcc-boot0)
  417. ("ld-wrapper-cross" ,ld-wrapper-boot0)
  418. ("binutils-cross" ,binutils-boot0)
  419. ,@(alist-delete "binutils" %boot0-inputs)))
  420. (define glibc-final-with-bootstrap-bash
  421. ;; The final libc, "cross-built". If everything went well, the resulting
  422. ;; store path has no dependencies. Actually, the really-final libc is
  423. ;; built just below; the only difference is that this one uses the
  424. ;; bootstrap Bash.
  425. (package-with-bootstrap-guile
  426. (package/inherit glibc
  427. (name "glibc-intermediate")
  428. (arguments
  429. `(#:guile ,%bootstrap-guile
  430. #:implicit-inputs? #f
  431. ,@(substitute-keyword-arguments (package-arguments glibc)
  432. ((#:configure-flags flags)
  433. `(append (list ,(string-append "--host=" (boot-triplet))
  434. ,(string-append "--build="
  435. (nix-system->gnu-triplet))
  436. ;; Build Sun/ONC RPC support. In particular,
  437. ;; install rpc/*.h.
  438. "--enable-obsolete-rpc")
  439. ,flags))
  440. ((#:phases phases)
  441. `(alist-cons-before
  442. 'configure 'pre-configure
  443. (lambda* (#:key inputs #:allow-other-keys)
  444. ;; Don't clobber CPATH with the bootstrap libc.
  445. (setenv "NATIVE_CPATH" (getenv "CPATH"))
  446. (unsetenv "CPATH")
  447. ;; Tell 'libpthread' where to find 'libihash' on Hurd systems.
  448. ,@(if (hurd-triplet? (%current-system))
  449. `((substitute* "libpthread/Makefile"
  450. (("LDLIBS-pthread.so =.*")
  451. (string-append "LDLIBS-pthread.so = "
  452. (assoc-ref %build-inputs "kernel-headers")
  453. "/lib/libihash.a\n"))))
  454. '())
  455. ;; 'rpcgen' needs native libc headers to be built.
  456. (substitute* "sunrpc/Makefile"
  457. (("sunrpc-CPPFLAGS =.*" all)
  458. (string-append "CPATH = $(NATIVE_CPATH)\n"
  459. "export CPATH\n"
  460. all "\n"))))
  461. ,phases)))))
  462. (propagated-inputs `(("kernel-headers" ,(kernel-headers-boot0))))
  463. (native-inputs
  464. `(("texinfo" ,texinfo-boot0)
  465. ("perl" ,perl-boot0)))
  466. (inputs
  467. `(;; The boot inputs. That includes the bootstrap libc. We don't want
  468. ;; it in $CPATH, hence the 'pre-configure' phase above.
  469. ,@%boot1-inputs
  470. ;; A native MiG is needed to build Glibc on Hurd.
  471. ,@(if (hurd-triplet? (%current-system))
  472. `(("mig" ,mig-boot0))
  473. '())
  474. ;; A native GCC is needed to build `cross-rpcgen'.
  475. ("native-gcc" ,@(assoc-ref %boot0-inputs "gcc"))
  476. ;; Here, we use the bootstrap Bash, which is not satisfactory
  477. ;; because we don't want to depend on bootstrap tools.
  478. ("static-bash" ,@(assoc-ref %boot0-inputs "bash")))))))
  479. (define (cross-gcc-wrapper gcc binutils glibc bash)
  480. "Return a wrapper for the pseudo-cross toolchain GCC/BINUTILS/GLIBC
  481. that makes it available under the native tool names."
  482. (package (inherit gcc)
  483. (name (string-append (package-name gcc) "-wrapped"))
  484. (source #f)
  485. (build-system trivial-build-system)
  486. (outputs '("out"))
  487. (arguments
  488. `(#:guile ,%bootstrap-guile
  489. #:modules ((guix build utils))
  490. #:builder (begin
  491. (use-modules (guix build utils))
  492. (let* ((binutils (assoc-ref %build-inputs "binutils"))
  493. (gcc (assoc-ref %build-inputs "gcc"))
  494. (libc (assoc-ref %build-inputs "libc"))
  495. (bash (assoc-ref %build-inputs "bash"))
  496. (out (assoc-ref %outputs "out"))
  497. (bindir (string-append out "/bin"))
  498. (triplet ,(boot-triplet)))
  499. (define (wrap-program program)
  500. ;; GCC-BOOT0 is a libc-less cross-compiler, so it
  501. ;; needs to be told where to find the crt files and
  502. ;; the dynamic linker.
  503. (call-with-output-file program
  504. (lambda (p)
  505. (format p "#!~a/bin/bash
  506. exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
  507. bash
  508. gcc triplet program
  509. libc libc
  510. ,(glibc-dynamic-linker))))
  511. (chmod program #o555))
  512. (mkdir-p bindir)
  513. (with-directory-excursion bindir
  514. (for-each (lambda (tool)
  515. (symlink (string-append binutils "/bin/"
  516. triplet "-" tool)
  517. tool))
  518. '("ar" "ranlib"))
  519. (for-each wrap-program '("gcc" "g++")))))))
  520. (native-inputs
  521. `(("binutils" ,binutils)
  522. ("gcc" ,gcc)
  523. ("libc" ,glibc)
  524. ("bash" ,bash)))
  525. (inputs '())))
  526. (define static-bash-for-glibc
  527. ;; A statically-linked Bash to be used by GLIBC-FINAL in system(3) & co.
  528. (let* ((gcc (cross-gcc-wrapper gcc-boot0 binutils-boot0
  529. glibc-final-with-bootstrap-bash
  530. (car (assoc-ref %boot1-inputs "bash"))))
  531. (bash (package (inherit static-bash)
  532. (arguments
  533. `(#:guile ,%bootstrap-guile
  534. ,@(package-arguments static-bash)))))
  535. (inputs `(("gcc" ,gcc)
  536. ("libc" ,glibc-final-with-bootstrap-bash)
  537. ,@(fold alist-delete %boot1-inputs
  538. '("gcc" "libc")))))
  539. (package-with-bootstrap-guile
  540. (package-with-explicit-inputs bash inputs
  541. (current-source-location)
  542. #:guile %bootstrap-guile))))
  543. (define gettext-boot0
  544. ;; A minimal gettext used during bootstrap.
  545. (let ((gettext-minimal
  546. (package (inherit gettext-minimal)
  547. (name "gettext-boot0")
  548. (inputs '()) ;zero dependencies
  549. (arguments
  550. (substitute-keyword-arguments
  551. `(#:tests? #f
  552. ,@(package-arguments gettext-minimal))
  553. ((#:phases phases)
  554. `(modify-phases ,phases
  555. ;; Build only the tools.
  556. (add-after 'unpack 'chdir
  557. (lambda _
  558. (chdir "gettext-tools")))
  559. ;; Some test programs require pthreads, which we don't have.
  560. (add-before 'configure 'no-test-programs
  561. (lambda _
  562. (substitute* "tests/Makefile.in"
  563. (("^PROGRAMS =.*$")
  564. "PROGRAMS =\n"))
  565. #t))
  566. ;; Don't try to link against libexpat.
  567. (delete 'link-expat)
  568. (delete 'patch-tests))))))))
  569. (package-with-bootstrap-guile
  570. (package-with-explicit-inputs gettext-minimal
  571. %boot1-inputs
  572. (current-source-location)
  573. #:guile %bootstrap-guile))))
  574. (define glibc-final
  575. ;; The final glibc, which embeds the statically-linked Bash built above.
  576. (package/inherit glibc-final-with-bootstrap-bash
  577. (name "glibc")
  578. (inputs `(("static-bash" ,static-bash-for-glibc)
  579. ,@(alist-delete
  580. "static-bash"
  581. (package-inputs glibc-final-with-bootstrap-bash))))
  582. ;; This time we need 'msgfmt' to install all the libc.mo files.
  583. (native-inputs `(,@(package-native-inputs glibc-final-with-bootstrap-bash)
  584. ("gettext" ,gettext-boot0)))
  585. ;; The final libc only refers to itself, but the 'debug' output contains
  586. ;; references to GCC-BOOT0 and to the Linux headers. XXX: Would be great
  587. ;; if 'allowed-references' were per-output.
  588. (arguments
  589. `(#:allowed-references
  590. ,(cons* `(,gcc-boot0 "lib") (kernel-headers-boot0)
  591. static-bash-for-glibc
  592. (package-outputs glibc-final-with-bootstrap-bash))
  593. ,@(package-arguments glibc-final-with-bootstrap-bash)))))
  594. (define gcc-boot0-wrapped
  595. ;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
  596. ;; non-cross names.
  597. (cross-gcc-wrapper gcc-boot0 binutils-boot0 glibc-final
  598. (car (assoc-ref %boot1-inputs "bash"))))
  599. (define %boot2-inputs
  600. ;; 3rd stage inputs.
  601. `(("libc" ,glibc-final)
  602. ("gcc" ,gcc-boot0-wrapped)
  603. ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
  604. (define binutils-final
  605. (package-with-bootstrap-guile
  606. (package/inherit binutils
  607. (arguments
  608. `(#:guile ,%bootstrap-guile
  609. #:implicit-inputs? #f
  610. #:allowed-references ("out" ,glibc-final)
  611. ,@(package-arguments binutils)))
  612. (inputs %boot2-inputs))))
  613. (define libstdc++
  614. ;; Intermediate libstdc++ that will allow us to build the final GCC
  615. ;; (remember that GCC-BOOT0 cannot build libstdc++.)
  616. ;; TODO: Write in terms of 'make-libstdc++'.
  617. (package-with-bootstrap-guile
  618. (package (inherit gcc)
  619. (name "libstdc++")
  620. (arguments
  621. `(#:guile ,%bootstrap-guile
  622. #:implicit-inputs? #f
  623. #:allowed-references ("out")
  624. #:out-of-source? #t
  625. #:phases (alist-cons-before
  626. 'configure 'chdir
  627. (lambda _
  628. (chdir "libstdc++-v3"))
  629. %standard-phases)
  630. #:configure-flags `("--disable-shared"
  631. "--disable-libstdcxx-threads"
  632. "--disable-libstdcxx-pch"
  633. ,(string-append "--with-gxx-include-dir="
  634. (assoc-ref %outputs "out")
  635. "/include"
  636. ;; "/include/c++/"
  637. ;; ,(package-version gcc)
  638. ))))
  639. (outputs '("out"))
  640. (inputs %boot2-inputs)
  641. (native-inputs '())
  642. (propagated-inputs '())
  643. (synopsis "GNU C++ standard library (intermediate)"))))
  644. (define zlib-final
  645. ;; Zlib used by GCC-FINAL.
  646. (package-with-bootstrap-guile
  647. (package
  648. (inherit zlib)
  649. (arguments
  650. `(#:guile ,%bootstrap-guile
  651. #:implicit-inputs? #f
  652. #:allowed-references ("out" ,glibc-final)
  653. ,@(package-arguments zlib)))
  654. (inputs %boot2-inputs))))
  655. (define ld-wrapper-boot3
  656. ;; A linker wrapper that uses the bootstrap Guile.
  657. (make-ld-wrapper "ld-wrapper-boot3"
  658. #:binutils binutils-final
  659. #:guile %bootstrap-guile
  660. #:bash (car (assoc-ref %boot2-inputs "bash"))))
  661. (define gcc-final
  662. ;; The final GCC.
  663. (package (inherit gcc-boot0)
  664. (name "gcc")
  665. ;; XXX: Currently #:allowed-references applies to all the outputs but the
  666. ;; "debug" output contains disallowed references, notably
  667. ;; linux-libre-headers. Disable the debugging output to work around that.
  668. (outputs (delete "debug" (package-outputs gcc-boot0)))
  669. (arguments
  670. `(#:guile ,%bootstrap-guile
  671. #:implicit-inputs? #f
  672. #:allowed-references ("out" "lib" ,zlib-final
  673. ,glibc-final ,static-bash-for-glibc)
  674. ;; Things like libasan.so and libstdc++.so NEED ld.so for some
  675. ;; reason, but it is not in their RUNPATH. This is a false
  676. ;; positive, so turn it off.
  677. #:validate-runpath? #f
  678. ;; Build again GMP & co. within GCC's build process, because it's hard
  679. ;; to do outside (because GCC-BOOT0 is a cross-compiler, and thus
  680. ;; doesn't honor $LIBRARY_PATH, which breaks `gnu-build-system'.)
  681. ,@(substitute-keyword-arguments (package-arguments gcc-boot0)
  682. ((#:configure-flags boot-flags)
  683. (let loop ((args (package-arguments gcc)))
  684. (match args
  685. ((#:configure-flags normal-flags _ ...)
  686. normal-flags)
  687. ((_ rest ...)
  688. (loop rest)))))
  689. ((#:make-flags flags)
  690. ;; Since $LIBRARY_PATH is not honored, add the relevant flags.
  691. `(let ((zlib (assoc-ref %build-inputs "zlib")))
  692. (map (lambda (flag)
  693. (if (string-prefix? "LDFLAGS=" flag)
  694. (string-append flag " -L"
  695. (assoc-ref %build-inputs "libstdc++")
  696. "/lib -L" zlib "/lib -Wl,-rpath="
  697. zlib "/lib")
  698. flag))
  699. ,flags)))
  700. ((#:phases phases)
  701. `(alist-delete 'symlink-libgcc_eh ,phases)))))
  702. ;; This time we want Texinfo, so we get the manual. Add
  703. ;; STATIC-BASH-FOR-GLIBC so that it's used in the final shebangs of
  704. ;; scripts such as 'mkheaders' and 'fixinc.sh' (XXX: who cares about these
  705. ;; scripts?).
  706. (native-inputs `(("texinfo" ,texinfo-boot0)
  707. ("static-bash" ,static-bash-for-glibc)
  708. ,@(package-native-inputs gcc-boot0)))
  709. (inputs `(("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
  710. ("mpfr-source" ,(package-source mpfr))
  711. ("mpc-source" ,(package-source mpc))
  712. ("ld-wrapper" ,ld-wrapper-boot3)
  713. ("binutils" ,binutils-final)
  714. ("libstdc++" ,libstdc++)
  715. ("zlib" ,zlib-final)
  716. ,@%boot2-inputs))))
  717. (define %boot3-inputs
  718. ;; 4th stage inputs.
  719. `(("gcc" ,gcc-final)
  720. ("ld-wrapper" ,ld-wrapper-boot3)
  721. ,@(alist-delete "gcc" %boot2-inputs)))
  722. (define bash-final
  723. ;; Link with `-static-libgcc' to make sure we don't retain a reference
  724. ;; to the bootstrap GCC. Use "bash-minimal" to avoid an extra dependency
  725. ;; on Readline and ncurses.
  726. (let ((bash (package
  727. (inherit bash-minimal)
  728. (arguments
  729. `(#:disallowed-references
  730. ,(assoc-ref %boot3-inputs "coreutils&co")
  731. ,@(package-arguments bash-minimal))))))
  732. (package-with-bootstrap-guile
  733. (package-with-explicit-inputs (static-libgcc-package bash)
  734. %boot3-inputs
  735. (current-source-location)
  736. #:guile %bootstrap-guile))))
  737. (define %boot4-inputs
  738. ;; Now use the final Bash.
  739. `(("bash" ,bash-final)
  740. ,@(alist-delete "bash" %boot3-inputs)))
  741. (define-public guile-final
  742. ;; This package must be public because other modules refer to it. However,
  743. ;; mark it as hidden so that 'fold-packages' ignores it.
  744. (package-with-bootstrap-guile
  745. (package-with-explicit-inputs (hidden-package guile-2.2/fixed)
  746. %boot4-inputs
  747. (current-source-location)
  748. #:guile %bootstrap-guile)))
  749. (define glibc-utf8-locales-final
  750. ;; Now that we have GUILE-FINAL, build the UTF-8 locales. They are needed
  751. ;; by the build processes afterwards so their 'scm_to_locale_string' works
  752. ;; with the full range of Unicode codepoints (remember
  753. ;; 'scm_to_locale_string' is called every time a string is passed to a C
  754. ;; function.)
  755. (package
  756. (inherit glibc-utf8-locales)
  757. (inputs `(("glibc" ,glibc-final)
  758. ("gzip"
  759. ,(package-with-explicit-inputs gzip %boot4-inputs
  760. (current-source-location)
  761. #:guile %bootstrap-guile))))))
  762. (define-public ld-wrapper
  763. ;; The final 'ld' wrapper, which uses the final Guile and Binutils.
  764. (make-ld-wrapper "ld-wrapper"
  765. #:binutils binutils-final
  766. #:guile guile-final
  767. #:bash bash-final))
  768. (define %boot5-inputs
  769. ;; Now with UTF-8 locales. Remember that the bootstrap binaries were built
  770. ;; with an older libc, which cannot load the new locale format. See
  771. ;; <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
  772. `(("locales" ,glibc-utf8-locales-final)
  773. ,@%boot4-inputs))
  774. (define gnu-make-final
  775. ;; The final GNU Make, which uses the final Guile.
  776. (package-with-bootstrap-guile
  777. (package-with-explicit-inputs gnu-make
  778. `(("guile" ,guile-final)
  779. ,@%boot5-inputs)
  780. (current-source-location))))
  781. (define coreutils-final
  782. ;; The final Coreutils. Treat them specially because some packages, such as
  783. ;; Findutils, keep a reference to the Coreutils they were built with.
  784. (package-with-bootstrap-guile
  785. (package-with-explicit-inputs coreutils
  786. %boot5-inputs
  787. (current-source-location)
  788. ;; Use the final Guile, linked against the
  789. ;; final libc with working iconv, so that
  790. ;; 'substitute*' works well when touching
  791. ;; test files in Gettext.
  792. #:guile guile-final)))
  793. (define grep-final
  794. ;; The final grep. Gzip holds a reference to it (via zgrep), so it must be
  795. ;; built before gzip.
  796. (package-with-bootstrap-guile
  797. (package-with-explicit-inputs (package
  798. (inherit grep)
  799. (native-inputs `(("perl" ,perl-boot0))))
  800. %boot5-inputs
  801. (current-source-location)
  802. #:guile guile-final)))
  803. (define %boot6-inputs
  804. ;; Now use the final Coreutils.
  805. `(("coreutils" ,coreutils-final)
  806. ("grep" ,grep-final)
  807. ,@%boot5-inputs))
  808. (define-public %final-inputs
  809. ;; Final derivations used as implicit inputs by 'gnu-build-system'. We
  810. ;; still use 'package-with-bootstrap-guile' so that the bootstrap tools are
  811. ;; used for origins that have patches, thereby avoiding circular
  812. ;; dependencies.
  813. (let ((finalize (compose package-with-bootstrap-guile
  814. (cut package-with-explicit-inputs <> %boot6-inputs
  815. (current-source-location)))))
  816. `(,@(map (match-lambda
  817. ((name package)
  818. (list name (finalize package))))
  819. `(("tar" ,tar)
  820. ("gzip" ,gzip)
  821. ("bzip2" ,bzip2)
  822. ("xz" ,xz)
  823. ("file" ,file)
  824. ("diffutils" ,diffutils)
  825. ("patch" ,patch)
  826. ("sed" ,sed)
  827. ("findutils" ,findutils)
  828. ("gawk" ,gawk)))
  829. ("grep" ,grep-final)
  830. ("coreutils" ,coreutils-final)
  831. ("make" ,gnu-make-final)
  832. ("bash" ,bash-final)
  833. ("ld-wrapper" ,ld-wrapper)
  834. ("binutils" ,binutils-final)
  835. ("gcc" ,gcc-final)
  836. ("libc" ,glibc-final)
  837. ("locales" ,glibc-utf8-locales-final))))
  838. (define-public canonical-package
  839. (let ((name->package (fold (lambda (input result)
  840. (match input
  841. ((_ package)
  842. (vhash-cons (package-full-name package)
  843. package result))))
  844. vlist-null
  845. `(("guile" ,guile-final)
  846. ,@%final-inputs))))
  847. (lambda (package)
  848. "Return the 'canonical' variant of PACKAGE---i.e., if PACKAGE is one of
  849. the implicit inputs of 'gnu-build-system', return that one, otherwise return
  850. PACKAGE.
  851. The goal is to avoid duplication in cases like GUILE-FINAL vs. GUILE-2.2,
  852. COREUTILS-FINAL vs. COREUTILS, etc."
  853. ;; XXX: This doesn't handle dependencies of the final inputs, such as
  854. ;; libunistring, GMP, etc.
  855. (match (vhash-assoc (package-full-name package) name->package)
  856. ((_ . canon)
  857. ;; In general we want CANON, except if we're cross-compiling: CANON
  858. ;; uses explicit inputs, so it is "anchored" in the bootstrapped
  859. ;; process, with dependencies on things that cannot be
  860. ;; cross-compiled.
  861. (if (%current-target-system)
  862. package
  863. canon))
  864. (_ package)))))
  865. ;;;
  866. ;;; GCC toolchain.
  867. ;;;
  868. (define (gcc-toolchain gcc)
  869. "Return a complete toolchain for GCC."
  870. (package
  871. (name "gcc-toolchain")
  872. (version (package-version gcc))
  873. (source #f)
  874. (build-system trivial-build-system)
  875. (arguments
  876. '(#:modules ((guix build union))
  877. #:builder (begin
  878. (use-modules (ice-9 match)
  879. (srfi srfi-26)
  880. (guix build union))
  881. (let ((out (assoc-ref %outputs "out")))
  882. (match %build-inputs
  883. (((names . directories) ...)
  884. (union-build out directories)))
  885. (union-build (assoc-ref %outputs "debug")
  886. (list (assoc-ref %build-inputs
  887. "libc-debug")))))))
  888. (native-search-paths (package-native-search-paths gcc))
  889. (search-paths (package-search-paths gcc))
  890. (license (package-license gcc))
  891. (synopsis "Complete GCC tool chain for C/C++ development")
  892. (description
  893. "This package provides a complete GCC tool chain for C/C++ development to
  894. be installed in user profiles. This includes GCC, as well as libc (headers
  895. and binaries, plus debugging symbols in the 'debug' output), and Binutils.")
  896. (home-page "https://gcc.gnu.org/")
  897. (outputs '("out" "debug"))
  898. ;; The main raison d'être of this "meta-package" is (1) to conveniently
  899. ;; install everything that we need, and (2) to make sure ld-wrapper comes
  900. ;; before Binutils' ld in the user's profile.
  901. (inputs `(("gcc" ,gcc)
  902. ("ld-wrapper" ,(car (assoc-ref %final-inputs "ld-wrapper")))
  903. ("binutils" ,binutils-final)
  904. ("libc" ,glibc-final)
  905. ("libc-debug" ,glibc-final "debug")))))
  906. (define-public gcc-toolchain-4.8
  907. (gcc-toolchain gcc-4.8))
  908. (define-public gcc-toolchain-4.9
  909. (gcc-toolchain gcc-4.9))
  910. (define-public gcc-toolchain-5
  911. (gcc-toolchain gcc-final))
  912. (define-public gcc-toolchain-6
  913. (gcc-toolchain gcc-6))
  914. (define-public gcc-toolchain-7
  915. (gcc-toolchain gcc-7))
  916. ;;; commencement.scm ends here