feat(nix/buildLisp): pass implementation description instead of name
Instead of using a string to refer to an internal set defined in buildLisp, we just expose the relevant sets (as nix.buildLisp.sbcl, nix.buildLisp.ecl, …) and receive them as the `implementation` argument directly. This has several advantages: * It becomes easier to extend buildLisp, even for downstream users: Since you can just pass your own set, there's nothing stopping you from adding support for another implementation in a downstream derivation without having to edit the buildLisp file in any way which is great if you're using e. g. builtins.fetchGit to import it. * Users can mess with the implementation set by changing out some parts of it for customization purposes. Note that currently the sets use a lot of self-references which aren't even bound by a fix-point, so to make this work smoothly, we'd need to add some overriding mechanism. * The buildLisp code becomes quite a bit clearer. Since we're now always dealing with the implementation set, the confusing distinction between `impl`, `impl.name` and `implementation` no longer exists. `impl` is now exclusively an abbreviation of `implementation` (we could make this more consistent in the future even). Change-Id: I36d68069dd1315610b2f7159941507b465469b7c Reviewed-on: https://cl.tvl.fyi/c/depot/+/3368 Reviewed-by: tazjin <mail@tazj.in> Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
d7e70b1d72
commit
7df7cd6257
1 changed files with 32 additions and 30 deletions
|
@ -15,7 +15,7 @@ let
|
||||||
# Internal helper definitions
|
# Internal helper definitions
|
||||||
#
|
#
|
||||||
|
|
||||||
defaultImplementation = "sbcl";
|
defaultImplementation = impls.sbcl;
|
||||||
|
|
||||||
# Many Common Lisp implementations (like ECL and CCL) will occasionally drop
|
# Many Common Lisp implementations (like ECL and CCL) will occasionally drop
|
||||||
# you into an interactive debugger even when executing something as a script.
|
# you into an interactive debugger even when executing something as a script.
|
||||||
|
@ -109,7 +109,7 @@ let
|
||||||
# attribute created by withExtras if present, override in all other cases
|
# attribute created by withExtras if present, override in all other cases
|
||||||
# (mainly bundled).
|
# (mainly bundled).
|
||||||
deps' = builtins.map (dep: dep."${impl.name}" or (dep.overrideLisp (_: {
|
deps' = builtins.map (dep: dep."${impl.name}" or (dep.overrideLisp (_: {
|
||||||
implementation = impl.name;
|
implementation = impl;
|
||||||
}))) deps;
|
}))) deps;
|
||||||
in (lib.toposort dependsOn (lib.unique (
|
in (lib.toposort dependsOn (lib.unique (
|
||||||
lib.flatten (deps' ++ (map (d: d.lispDeps) deps'))
|
lib.flatten (deps' ++ (map (d: d.lispDeps) deps'))
|
||||||
|
@ -147,37 +147,37 @@ let
|
||||||
(builtins.attrNames impls);
|
(builtins.attrNames impls);
|
||||||
in {
|
in {
|
||||||
passthru = (old.passthru or {}) // {
|
passthru = (old.passthru or {}) // {
|
||||||
repl = impls."${implementation}".lispWith [ self ];
|
repl = implementation.lispWith [ self ];
|
||||||
|
|
||||||
# meta is done via passthru to minimize rebuilds caused by overriding
|
# meta is done via passthru to minimize rebuilds caused by overriding
|
||||||
meta = (old.passthru.meta or {}) // {
|
meta = (old.passthru.meta or {}) // {
|
||||||
inherit targets;
|
inherit targets;
|
||||||
};
|
};
|
||||||
} // builtins.listToAttrs (builtins.map (name: {
|
} // builtins.listToAttrs (builtins.map (impl: {
|
||||||
inherit name;
|
inherit (impl) name;
|
||||||
value = self.overrideLisp (_: {
|
value = self.overrideLisp (_: {
|
||||||
implementation = name;
|
implementation = impl;
|
||||||
});
|
});
|
||||||
}) (builtins.attrNames impls));
|
}) (builtins.attrValues impls));
|
||||||
}) // {
|
}) // {
|
||||||
overrideLisp = new: withExtras f (args // new args);
|
overrideLisp = new: withExtras f (args // new args);
|
||||||
});
|
});
|
||||||
|
|
||||||
# 'testSuite' builds a Common Lisp test suite that loads all of srcs and deps,
|
# 'testSuite' builds a Common Lisp test suite that loads all of srcs and deps,
|
||||||
# and then executes expression to check its result
|
# and then executes expression to check its result
|
||||||
testSuite = { name, expression, srcs, deps ? [], native ? [], impl }:
|
testSuite = { name, expression, srcs, deps ? [], native ? [], implementation }:
|
||||||
let
|
let
|
||||||
lispNativeDeps = allNative native deps;
|
lispNativeDeps = allNative native deps;
|
||||||
lispDeps = allDeps impl (implFilter impl deps);
|
lispDeps = allDeps implementation (implFilter implementation deps);
|
||||||
filteredSrcs = implFilter impl srcs;
|
filteredSrcs = implFilter implementation srcs;
|
||||||
in runCommandNoCC name {
|
in runCommandNoCC name {
|
||||||
LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
|
LD_LIBRARY_PATH = lib.makeLibraryPath lispNativeDeps;
|
||||||
LANG = "C.UTF-8";
|
LANG = "C.UTF-8";
|
||||||
} ''
|
} ''
|
||||||
echo "Running test suite ${name}"
|
echo "Running test suite ${name}"
|
||||||
|
|
||||||
${impl.runScript} ${
|
${implementation.runScript} ${
|
||||||
impl.genTestLisp {
|
implementation.genTestLisp {
|
||||||
inherit name expression;
|
inherit name expression;
|
||||||
srcs = filteredSrcs;
|
srcs = filteredSrcs;
|
||||||
deps = lispDeps;
|
deps = lispDeps;
|
||||||
|
@ -579,19 +579,17 @@ let
|
||||||
, passthru ? {}
|
, passthru ? {}
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
impl = impls."${implementation}" or
|
filteredDeps = implFilter implementation deps;
|
||||||
(builtins.throw "Unkown Common Lisp Implementation ${implementation}");
|
filteredSrcs = implFilter implementation srcs;
|
||||||
filteredDeps = implFilter impl deps;
|
|
||||||
filteredSrcs = implFilter impl srcs;
|
|
||||||
lispNativeDeps = (allNative native filteredDeps);
|
lispNativeDeps = (allNative native filteredDeps);
|
||||||
lispDeps = allDeps impl filteredDeps;
|
lispDeps = allDeps implementation filteredDeps;
|
||||||
testDrv = if ! isNull tests
|
testDrv = if ! isNull tests
|
||||||
then testSuite {
|
then testSuite {
|
||||||
name = tests.name or "${name}-test";
|
name = tests.name or "${name}-test";
|
||||||
srcs = filteredSrcs ++ (tests.srcs or []);
|
srcs = filteredSrcs ++ (tests.srcs or []);
|
||||||
deps = filteredDeps ++ (tests.deps or []);
|
deps = filteredDeps ++ (tests.deps or []);
|
||||||
expression = tests.expression;
|
expression = tests.expression;
|
||||||
inherit impl;
|
inherit implementation;
|
||||||
}
|
}
|
||||||
else null;
|
else null;
|
||||||
in lib.fix (self: runCommandNoCC "${name}-cllib" {
|
in lib.fix (self: runCommandNoCC "${name}-cllib" {
|
||||||
|
@ -610,8 +608,8 @@ let
|
||||||
|
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
|
||||||
${impl.runScript} ${
|
${implementation.runScript} ${
|
||||||
impl.genCompileLisp {
|
implementation.genCompileLisp {
|
||||||
srcs = filteredSrcs;
|
srcs = filteredSrcs;
|
||||||
inherit name;
|
inherit name;
|
||||||
deps = lispDeps;
|
deps = lispDeps;
|
||||||
|
@ -633,11 +631,9 @@ let
|
||||||
, passthru ? {}
|
, passthru ? {}
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
impl = impls."${implementation}" or
|
filteredSrcs = implFilter implementation srcs;
|
||||||
(builtins.throw "Unkown Common Lisp Implementation ${implementation}");
|
filteredDeps = implFilter implementation deps;
|
||||||
filteredSrcs = implFilter impl srcs;
|
lispDeps = allDeps implementation filteredDeps;
|
||||||
filteredDeps = implFilter impl deps;
|
|
||||||
lispDeps = allDeps impl filteredDeps;
|
|
||||||
libPath = lib.makeLibraryPath (allNative native lispDeps);
|
libPath = lib.makeLibraryPath (allNative native lispDeps);
|
||||||
# overriding is used internally to propagate the implementation to use
|
# overriding is used internally to propagate the implementation to use
|
||||||
selfLib = (makeOverridable library) {
|
selfLib = (makeOverridable library) {
|
||||||
|
@ -653,7 +649,7 @@ let
|
||||||
filteredSrcs ++ (tests.srcs or []));
|
filteredSrcs ++ (tests.srcs or []));
|
||||||
deps = filteredDeps ++ (tests.deps or []);
|
deps = filteredDeps ++ (tests.deps or []);
|
||||||
expression = tests.expression;
|
expression = tests.expression;
|
||||||
inherit impl;
|
inherit implementation;
|
||||||
}
|
}
|
||||||
else null;
|
else null;
|
||||||
in lib.fix (self: runCommandNoCC "${name}" {
|
in lib.fix (self: runCommandNoCC "${name}" {
|
||||||
|
@ -673,13 +669,13 @@ let
|
||||||
else ""}
|
else ""}
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
|
|
||||||
${impl.runScript} ${
|
${implementation.runScript} ${
|
||||||
impl.genDumpLisp {
|
implementation.genDumpLisp {
|
||||||
inherit name main;
|
inherit name main;
|
||||||
deps = ([ selfLib ] ++ lispDeps);
|
deps = ([ selfLib ] ++ lispDeps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'' + lib.optionalString impl.wrapProgram ''
|
'' + lib.optionalString implementation.wrapProgram ''
|
||||||
wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}"
|
wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}"
|
||||||
''));
|
''));
|
||||||
|
|
||||||
|
@ -699,7 +695,7 @@ let
|
||||||
{ implementation ? defaultImplementation
|
{ implementation ? defaultImplementation
|
||||||
, name
|
, name
|
||||||
}:
|
}:
|
||||||
impls."${implementation}".bundled or (defaultBundled implementation) name;
|
implementation.bundled or (defaultBundled implementation) name;
|
||||||
|
|
||||||
in (makeOverridable bundled') {
|
in (makeOverridable bundled') {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
@ -713,4 +709,10 @@ in {
|
||||||
# 'sbclWith' creates an image with the specified libraries /
|
# 'sbclWith' creates an image with the specified libraries /
|
||||||
# programs loaded in SBCL.
|
# programs loaded in SBCL.
|
||||||
sbclWith = impls.sbcl.lispWith;
|
sbclWith = impls.sbcl.lispWith;
|
||||||
|
|
||||||
|
inherit (impls)
|
||||||
|
sbcl
|
||||||
|
ecl
|
||||||
|
ccl
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue