feat(buildLisp): Implement buildLisp.program to dump executables

Dumps the executable image from SBCL to $out/bin/$name.

Image compression is disabled.
This commit is contained in:
Vincent Ambo 2020-01-08 21:39:26 +00:00
parent 2bfe073eb2
commit bdad8f6642

View file

@ -61,10 +61,25 @@ let
lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps))) lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps)))
); );
# 'genDumpLisp' generates a Lisp file that instructs SBCL to dump
# the currently loaded image as an executable to $out/bin/$name.
#
# TODO(tazjin): Compression is currently unsupported because the
# SBCL in nixpkgs is, by default, not compiled with zlib support.
genDumpLisp = name: main: deps: writeText "dump.lisp" ''
(require 'sb-posix)
# ${genLoadLisp deps}
# Public API functions
# (let* ((bindir (concatenate 'string (sb-posix:getenv "out") "/bin"))
(outpath (make-pathname :name "${name}"
:directory bindir)))
(save-lisp-and-die outpath
:executable t
:toplevel (function ${main})
:purify t))
;;
'';
# Add an `overrideLisp` attribute to a function result that works # Add an `overrideLisp` attribute to a function result that works
# similar to `overrideAttrs`, but is used specifically for the # similar to `overrideAttrs`, but is used specifically for the
@ -73,6 +88,10 @@ let
overrideLisp = new: makeOverridable f (orig // (new orig)); overrideLisp = new: makeOverridable f (orig // (new orig));
}; };
#
# Public API functions
#
# 'library' builds a list of Common Lisp files into a single FASL # 'library' builds a list of Common Lisp files into a single FASL
# which can then be loaded into SBCL. # which can then be loaded into SBCL.
library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} '' library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} ''
@ -85,7 +104,14 @@ let
# 'program' creates an executable containing a dumped image of the # 'program' creates an executable containing a dumped image of the
# specified sources and dependencies. # specified sources and dependencies.
program = {}; program = { name, main ? "${name}:main", srcs, deps ? [] }: runCommandNoCC "${name}" {} ''
mkdir -p $out/bin
${sbcl}/bin/sbcl --script ${
genDumpLisp name main (lib.singleton (library {
inherit name srcs deps;
}))
}
'';
# 'sbclWith' creates an image with the specified libraries / # 'sbclWith' creates an image with the specified libraries /
# programs loaded. # programs loaded.