Subject: Re: bug#32770: Packaging SLIME/SWANK as Common Lisp library

From: Pierre Neidhardt <[email-masked]>
Date: Wed, 03 Oct 2018 20:34:24 +0200

Last (hopefully?) step before getting Next up and running: add support for CFFI.

I've re-used your CFFI package and they seem to work.  Now if I want to package
cl-sqlite, it fails because sqlite.so cannot be found.  Indeed, the patch to
/gnu/store/...-sqlite.../lib must be added to the
cffi:*foreign-library-directories* global variable before compiling.

If I do that from quicklisp, it works.  Now I guess we need to tweak
asdf-build-system so that packages can specify which paths to add to that global
variable.

Makes sense?

I've given it a quick shot (patch attached) but then every ASDF build fails with

--8<---------------cut here---------------start------------->8---
ice-9/boot-9.scm:222:17: In procedure map1:
Syntax error:
unknown location: unexpected syntax in form ()
--8<---------------cut here---------------end--------------->8---

I'm still lacking good knowledge of the asdf build system.

I'll give it a closer look tomorrow.
From 1c4b9b915086b0fdfb4229f5bbfa5aecff784f42 Mon Sep 17 00:00:00 2001
From: Pierre Neidhardt <[email-masked]>
Date: Wed, 3 Oct 2018 20:27:00 +0200
Subject: [PATCH] cffi support

---
 guix/build-system/asdf.scm       | 2 ++
 guix/build/asdf-build-system.scm | 4 ++--
 guix/build/lisp-utils.scm        | 5 ++++-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/guix/build-system/asdf.scm b/guix/build-system/asdf.scm
index 57e294d74..37c219460 100644
--- a/guix/build-system/asdf.scm
+++ b/guix/build-system/asdf.scm
@@ -266,6 +266,7 @@ set up using CL source package conventions."
                   (tests? #t)
                   (asd-file #f)
                   (asd-system-name #f)
+                  (cffi-foreign-library-directories '())
                   (test-asd-file #f)
                   (phases '(@ (guix build asdf-build-system)
                               %standard-phases))
@@ -298,6 +299,7 @@ set up using CL source package conventions."
                        #:asd-file ,(or asd-file (string-append system-name ".asd"))
                        #:asd-system-name ,system-name
                        #:test-asd-file ,test-asd-file
+                       #:cffi-foreign-library-directories ,cffi-foreign-library-directories
                        #:system ,system
                        #:tests? ,tests?
                        #:phases ,phases
diff --git a/guix/build/asdf-build-system.scm b/guix/build/asdf-build-system.scm
index dd6373b33..7d879ddb9 100644
--- a/guix/build/asdf-build-system.scm
+++ b/guix/build/asdf-build-system.scm
@@ -106,7 +106,7 @@ valid."
       (delete-file-recursively "systems")))
   #t)
 
-(define* (build #:key outputs inputs asd-file asd-system-name
+(define* (build #:key outputs inputs asd-file asd-system-name cffi-foreign-library-directories
                 #:allow-other-keys)
   "Compile the system."
   (let* ((out (library-output outputs))
@@ -121,7 +121,7 @@ valid."
 
     (setenv "HOME" out) ; ecl's asdf sometimes wants to create $HOME/.cache
 
-    (compile-system asd-system-name asd-file)
+    (compile-system asd-system-name asd-file cffi-foreign-library-directories)
 
     ;; As above, ecl will sometimes create this even though it doesn't use it
 
diff --git a/guix/build/lisp-utils.scm b/guix/build/lisp-utils.scm
index 5dea30486..5d7b5afd0 100644
--- a/guix/build/lisp-utils.scm
+++ b/guix/build/lisp-utils.scm
@@ -149,13 +149,16 @@ with PROGRAM."
          `(asdf:load-system ,system))
        systems))
 
-(define (compile-system system asd-file)
+(define* (compile-system system asd-file #:optional cffi-foreign-library-directories)
   "Use a lisp implementation to compile SYSTEM using asdf.  Load ASD-FILE
 first."
   (lisp-eval-program
    `((require :asdf)
      (let ((*package* (find-package :asdf)))
        (load ,asd-file))
+     ,(unless (null? cffi-foreign-library-directories)
+        `(progn (require :cffi)
+                (setq cffi:*foreign-library-directories* ,cffi-foreign-library-directories)))
      (asdf:operate 'asdf:compile-bundle-op ,system))))
 
 (define (system-dependencies system asd-file)
-- 
2.19.0

-- 
Pierre Neidhardt
https://ambrevar.xyz/