From 09720e2da267c22f3e135c2cb3843a269c53a65b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 9 Jan 2020 03:32:29 +0000 Subject: fix(buildLisp): Wrap executables to set load paths correctly I can not currently find a way to set the CFFI variables correctly to get it to load libraries from Nix. In the absence of that feature, a wrapper also does the trick. --- nix/buildLisp/default.nix | 24 +++++++++--------------- nix/buildLisp/example/main.lisp | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'nix/buildLisp') diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index 15dc5f73e4..66de386631 100644 --- a/nix/buildLisp/default.nix +++ b/nix/buildLisp/default.nix @@ -9,7 +9,7 @@ let inherit (builtins) map elemAt match; - inherit (pkgs.third_party) lib runCommandNoCC writeText writeShellScriptBin sbcl; + inherit (pkgs.third_party) lib runCommandNoCC makeWrapper writeText writeShellScriptBin sbcl; # # Internal helper definitions @@ -77,15 +77,6 @@ let lib.flatten (native ++ (map (d: d.lispNativeDeps) deps)) ); - # 'pushLibDirs' generates forms that push all native library paths - # onto the variable `CFFI:*FOREIGN-LIBRARY-DIRECTORIES*` which is - # required for any runtime loading of libraries via CFFI. - pushLibDirs = deps: lib.concatStringsSep "\n" ( - map (l: "(push \"${ - lib.getLib l - }/lib\" cffi:*foreign-library-directories*)") (allNative [] deps) - ); - # 'genDumpLisp' generates a Lisp file that instructs SBCL to dump # the currently loaded image as an executable to $out/bin/$name. # @@ -96,10 +87,6 @@ let ${genLoadLisp deps} - ;; Push library directories if CFFI is in use. - (when (boundp 'cffi:*foreign-library-directories*) - ${pushLibDirs deps}) - (let* ((bindir (concatenate 'string (sb-posix:getenv "out") "/bin")) (outpath (make-pathname :name "${name}" :directory bindir))) @@ -150,15 +137,22 @@ let program = { name, main ? "${name}:main", srcs, deps ? [], native ? [] }: let lispDeps = allDeps deps; + libPath = lib.makeLibraryPath (allNative native lispDeps); selfLib = library { inherit name srcs native; deps = lispDeps; }; - in runCommandNoCC "${name}" {} '' + in runCommandNoCC "${name}" { + nativeBuildInputs = [ makeWrapper ]; + LD_LIBRARY_PATH = libPath; + } '' mkdir -p $out/bin + ${sbcl}/bin/sbcl --script ${ genDumpLisp name main ([ selfLib ] ++ lispDeps) } + + wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}" ''; # 'sbclWith' creates an image with the specified libraries / diff --git a/nix/buildLisp/example/main.lisp b/nix/buildLisp/example/main.lisp index f98bb8409a..a29390cf4d 100644 --- a/nix/buildLisp/example/main.lisp +++ b/nix/buildLisp/example/main.lisp @@ -4,4 +4,4 @@ (in-package :example) (defun main () - (format t "i <3 ~S" (who))) + (format t "i <3 ~A~%" (who))) -- cgit 1.4.1