Previous: spec file syntax, Up: cffi-grovel concepts


3.2 ASDF Integration

An example software project might contain four files; an ASDF file, a package definition file, an implementation file, and a CFFI-Grovel specification file.

The ASDF file defines the system and its dependencies. Notice the use of eval-when to ensure CFFI-Grovel is present and the use of (cffi-grovel-file ...) instead of (:file ...).

     ;; CFFI-Grovel is needed for processing
     ;; cffi-grovel-file components
     (cl:eval-when (:load-toplevel :execute)
       (asdf:operate 'asdf:load-op '#:cffi-grovel))
     
     (asdf:defsystem #:example-software
       :depends-on ("cffi")
       :components ((:file "example"
                           :depends-on ("defpackage" "exampleint"))
                    (:file "defpackage")
                    (cffi-grovel-file "exampleint"
                                      :depends-on ("defpackage"))))

The defpackage file would contain several defpackage forms, to remove circular dependencies and make building the project easier. Note that you may or may not want to :use your internal package.

     (defpackage #:example-internal
       (:nicknames #:exampleint))
     
     (defpackage #:example-software
       (:export ...)
       (:use #:cl #:cffi #:exampleint))

The internal package is created by Lisp code output from the C program written by CFFI-Grovel; if your specification file is exampleint.lisp, the exampleint.cffi.lisp file will contain the CFFI definitions needed by the rest of your project. See spec file syntax.