(address . guix-patches@gnu.org)
Hi Guix!
This small series adds camlboot, a project to reimplement a bootstrap
for OCaml, which lets us remove the pre-built boot/ocaml{c,lex} :)
The first patch builds the bootstraped ocamlc and ocamllex. This takes
around 4 hours to build. The second patch rebuilds them using the source
code for ocaml 4.07.1, instead of the modified sources used in
camlboot, and reuse them to run the main Makefile (make world.opt).
As a result, we have identical files for this bootstrap and the
unbootstrapped OCaml (up to output store paths and hash of some files
that get embedded in native files, which differ because of the
different output path).
From 8fd06caa83e55d27dc5998f7548a7d45c55c6a91 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 27 Feb 2021 00:07:20 +0100
Subject: [PATCH 1/2] gnu: Add camlboot.
* gnu/packages/ocaml.scm (camlboot): New variable.
---
gnu/packages/ocaml.scm | 66 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
Toggle diff (86 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 9e68359a42..01c14a0ba0 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -52,6 +52,7 @@
#:use-module (gnu packages glib)
#:use-module (gnu packages gnome)
#:use-module (gnu packages gtk)
+ #:use-module (gnu packages guile)
#:use-module (gnu packages libevent)
#:use-module (gnu packages libffi)
#:use-module (gnu packages llvm)
@@ -105,6 +106,71 @@
".tar.gz"))
(sha256 (base32 hash))))
+(define-public camlboot
+ (let ((commit "506280c6e0813e0e794988151a8e46be55373ebc")
+ (revision "0"))
+ (package
+ (name "camlboot")
+ (version (git-version "0.0.0" revision commit))
+ (source (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/Ekdohibs/camlboot")
+ (commit commit)
+ (recursive? #t)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32
+ "0vimxl4karw9ih3npyc5rhxg85cjh6fqjbq3dzj7j2iymlhwfbkv"))
+ (modules '((guix build utils)))
+ (snippet
+ `(begin
+ ;; Remove bootstrap binaries and pre-generated source files,
+ ;; to ensure we actually bootstrap properly.
+ (for-each delete-file (find-files "ocaml-src" "^.depend$"))
+ (delete-file "ocaml-src/boot/ocamlc")
+ (delete-file "ocaml-src/boot/ocamllex")
+ ;; Ensure writable
+ (for-each
+ (lambda (file)
+ (chmod file (logior (stat:mode (stat file)) #o200)))
+ (find-files "." "."))))))
+ (build-system gnu-build-system)
+ (arguments
+ `(#:make-flags (list "_boot/ocamlc"); build target
+ #:tests? #f; no tests
+ #:phases
+ (modify-phases %standard-phases
+ (delete 'configure)
+ (add-before 'build 'no-autocompile
+ (lambda _
+ ;; prevent a guile warning
+ (setenv "GUILE_AUTO_COMPILE" "0")))
+ (replace 'install
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let* ((out (assoc-ref outputs "out"))
+ (bin (string-append out "/bin")))
+ (mkdir-p bin)
+ (install-file "_boot/ocamlc" bin)
+ (rename-file "miniml/interp/lex.byte" "ocamllex")
+ (install-file "ocamllex" bin)))))))
+ (native-inputs
+ `(("guile" ,guile-3.0)))
+ (home-page "https://github.com/Ekdohibs/camlboot")
+ (synopsis "OCaml bootstrap")
+ (description "OCaml is written in OCaml. Its sources contain a pre-compiled
+bytecode version of ocamlc and ocamllex that are used to build the next version
+of the compiler. Camlboot implements a bootstrap for the OCaml compiler and
+provides a bootstrapped equivalent to these files.
+
+It contains a compiler for a small subset of OCaml written in Guile Scheme,
+an interpreter for OCaml written in that subset and a manually-written lexer
+for OCaml. These elements eliminate the need for the binary bootstrap in
+OCaml and can effectively bootstrap OCaml 4.07.
+
+This package produces a native ocamlc and a bytecode ocamllex.")
+ (license license:expat))))
+
(define-public ocaml-4.11
(package
(name "ocaml")
--
2.30.0