about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorVincent Ambo <Vincent Ambo>2020-01-08T23·57+0000
committerVincent Ambo <Vincent Ambo>2020-01-08T23·57+0000
commite3a8dc9500fa9d54930ce39c57afecae75a6aca8 (patch)
tree0b0e540825f754cd508445db829b063d443bbc6a /nix
parent7bc10eb9b78c08ae1e64ae5e24db26cdb74c7834 (diff)
fix(buildLisp): Cursed code to fix load ordering r/351
It's not enough to compile in the right order - turns out you also
have to load the compiled objects in the right order.

To achieve this some cursed code has been added that changes the Lisp
generated by Nix to compile the other Lisp so that it also generates
some bash, which Nix can then use to concatenate the FASLs in the
right order to feed them to Lisp again.

It works but I'll replace it with a more elegant solution once one is
needed.
Diffstat (limited to 'nix')
-rw-r--r--nix/buildLisp/default.nix33
1 files changed, 23 insertions, 10 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index 641a9a8c4ed7..e8d235df7c32 100644
--- a/nix/buildLisp/default.nix
+++ b/nix/buildLisp/default.nix
@@ -29,26 +29,36 @@ let
 
     ${genLoadLisp deps}
 
-    (defun nix-compile-lisp (srcfile)
+    (defun nix-compile-lisp (file srcfile)
       (let ((outfile (make-pathname :type "fasl"
                                     :directory (or (sb-posix:getenv "NIX_BUILD_TOP")
                                                    (error "not running in a Nix build"))
                                     :defaults srcfile)))
         (multiple-value-bind (_outfile _warnings-p failure-p)
             (compile-file srcfile :output-file outfile)
-          (when failure-p
-            (sb-posix:exit 1)))))
+          (if failure-p (sb-posix:exit 1)
+              (progn
+                ;; For the case of multiple files belonging to the same
+                ;; library being compiled, load them in order:
+                (load outfile)
+
+                ;; Write them to the FASL list in the same order:
+                (format file "cat ~a~%" (namestring outfile)))))))
 
     (let ((*compile-verbose* t)
           ;; FASL files are compiled into the working directory of the
           ;; build and *then* moved to the correct out location.
           (pwd (sb-posix:getcwd)))
 
-      ;; These forms were inserted by the Nix build:
-      ${
-        lib.concatStringsSep "\n" (map (src: "(nix-compile-lisp \"${src}\")") srcs)
-      }
-    )
+      (with-open-file (file "cat_fasls"
+                            :direction :output
+                            :if-does-not-exist :create)
+
+        ;; These forms were inserted by the Nix build:
+        ${
+          lib.concatStringsSep "\n" (map (src: "(nix-compile-lisp file \"${src}\")") srcs)
+        }
+        ))
   '';
 
   # 'allDeps' flattens the list of dependencies (and their
@@ -97,9 +107,12 @@ let
   library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} ''
     ${sbcl}/bin/sbcl --script ${genCompileLisp srcs deps}
 
-    # FASL files can be combined by simply concatenating them together:
+    # FASL files can be combined by simply concatenating them
+    # together, but it needs to be in the compilation order.
     mkdir $out
-    cat ./*.fasl > $out/${name}.fasl
+
+    chmod +x cat_fasls
+    ./cat_fasls > $out/${name}.fasl
   '' // { lispName = name; lispDeps = deps; };
 
   # 'program' creates an executable containing a dumped image of the