From acb5994e87fd5aa306f63196fdef9c55cc6345f4 Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 11 Aug 2021 10:45:26 +0200 Subject: feat(nix/buildLisp): allow implementation-specifc bundled functions By implementing a bundled function for an implementation, we can use a custom one for a specific implementation. This is useful for implementations like ECL where a require will be compiled as an instruction rather than importing all new symbols into a dump, so using the underlying static or shared object directly would be beneficial. overrideLisp for bundled libraries now only allows overriding the name and implementation arguments. Change-Id: I9036b29157e8daa4d86ff87d603b044373711dbf Reviewed-on: https://cl.tvl.fyi/c/depot/+/3301 Tested-by: BuildkiteCI Reviewed-by: tazjin --- nix/buildLisp/default.nix | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'nix/buildLisp') diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index b1d852fbb5..d12c1ff1d9 100644 --- a/nix/buildLisp/default.nix +++ b/nix/buildLisp/default.nix @@ -124,6 +124,16 @@ let # Builds a script (or dumped image) which when executed loads (or has # loaded) all given dependencies. When built this should create an executable # at "$out/bin/${implementation}". + # + # Optional members: + # + # - bundled :: string -> library + # Allows giving an implementation specific builder for a bundled library. + # This function is used as a replacement for the internal defaultBundled + # function and only needs to support one implementation. The returned derivation + # must behave like one built by 'library' (in particular have the same files + # available in "$out" and the same 'passthru' attributes), but may be built + # completely differently. impls = lib.mapAttrs (name: v: { inherit name; } // v) { sbcl = { runScript = "${sbcl}/bin/sbcl --script"; @@ -326,12 +336,28 @@ let wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}" ''); - # 'bundled' creates a "library" that calls 'require' on a built-in - # package, such as any of SBCL's sb-* packages. - bundled = name: (makeOverridable library) { - inherit name; - srcs = lib.singleton (builtins.toFile "${name}.lisp" "(require '${name})"); - }; + # 'bundled' creates a "library" which makes a built-in package available, + # such as any of SBCL's sb-* packages or ASDF. By default this is done + # by calling 'require', but implementations are free to provide their + # own specific bundled function. + bundled = name: + let + # TODO(sterni): allow overriding args to underlying 'library' (e. g. srcs) + defaultBundled = implementation: name: library { + inherit name implementation; + srcs = lib.singleton (builtins.toFile "${name}.lisp" "(require '${name})"); + }; + + bundled' = + { implementation ? defaultImplementation + , name + }: + impls."${implementation}".bundled or (defaultBundled implementation) name; + + in (makeOverridable bundled') { + inherit name; + }; + in { library = makeOverridable library; program = makeOverridable program; -- cgit 1.4.1