From e3a8dc9500fa9d54930ce39c57afecae75a6aca8 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 8 Jan 2020 23:57:34 +0000 Subject: fix(buildLisp): Cursed code to fix load ordering 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. --- nix/buildLisp/default.nix | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'nix/buildLisp') diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index 641a9a8c4e..e8d235df7c 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 -- cgit 1.4.1