feat(buildLisp): Implement dependency loading & propagation
Similar to buildGo.nix, the library derivations carry information about their dependencies which is merged when a load file is instantiated. The load files are created when compiling libraries, but will in the future also be created when wrapping SBCL and dumping images.
This commit is contained in:
parent
1297afec4b
commit
ca199a57d9
2 changed files with 17 additions and 4 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) map elemAt match;
|
inherit (builtins) map elemAt match;
|
||||||
inherit (pkgs.third_party) lib runCommand writeText sbcl;
|
inherit (pkgs.third_party) lib runCommandNoCC writeText sbcl;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Internal helper definitions
|
# Internal helper definitions
|
||||||
|
@ -44,6 +44,18 @@ let
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# 'allDeps' flattens the list of dependencies (and their
|
||||||
|
# dependencies) into one list of unique deps.
|
||||||
|
allDeps = deps: lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps)));
|
||||||
|
|
||||||
|
# 'genLoadLisp' generates a Lisp file that instructs a Lisp to load
|
||||||
|
# all the provided Lisp libraries.
|
||||||
|
genLoadLisp = deps: writeText "load.lisp" (
|
||||||
|
lib.concatStringsSep "\n" (map (lib: "(load \"${lib}/${lib.lispName}.fasl\")") (allDeps deps))
|
||||||
|
);
|
||||||
|
|
||||||
|
insertLibraryLoads = deps: if deps == [] then "" else "--load ${genLoadLisp deps}";
|
||||||
|
|
||||||
#
|
#
|
||||||
# Public API functions
|
# Public API functions
|
||||||
#
|
#
|
||||||
|
@ -57,13 +69,13 @@ let
|
||||||
|
|
||||||
# '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 ? [] }: runCommand "${name}-cllib" {} ''
|
library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} ''
|
||||||
${sbcl}/bin/sbcl --script ${genCompileLisp srcs}
|
${sbcl}/bin/sbcl ${insertLibraryLoads deps} --script ${genCompileLisp srcs}
|
||||||
|
|
||||||
# FASL files can be combined by simply concatenating them together:
|
# FASL files can be combined by simply concatenating them together:
|
||||||
mkdir $out
|
mkdir $out
|
||||||
cat ./*.fasl > $out/${name}.fasl
|
cat ./*.fasl > $out/${name}.fasl
|
||||||
'';
|
'' // { lispName = name; lispDeps = deps; };
|
||||||
|
|
||||||
# '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.
|
||||||
|
|
1
third_party/default.nix
vendored
1
third_party/default.nix
vendored
|
@ -73,6 +73,7 @@ let
|
||||||
ripgrep
|
ripgrep
|
||||||
rsync
|
rsync
|
||||||
runCommand
|
runCommand
|
||||||
|
runCommandNoCC
|
||||||
rustPlatform
|
rustPlatform
|
||||||
rustc
|
rustc
|
||||||
sbcl
|
sbcl
|
||||||
|
|
Loading…
Reference in a new issue