Ricerca…


Costruire Buildapp

I binari Common Lisp standalone possono essere buildapp con buildapp . Prima di poterlo utilizzare per generare binari, dobbiamo installarlo e costruirlo.

Il modo più semplice per sapere come usare quicklisp e Common Lisp (questo esempio usa [ sbcl ], ma non dovrebbe fare la differenza rispetto a quello che hai).

$ sbcl

This is SBCL 1.3.5.nixos, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.

* (ql:quickload :buildapp)
To load "buildapp":
  Load 1 ASDF system:
    buildapp
; Loading "buildapp"

(:BUILDAPP)

* (buildapp:build-buildapp)
;; loading system "buildapp"
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into /home/inaimathi/buildapp:
writing 4800 bytes from the read-only space at 0x20000000
writing 3216 bytes from the static space at 0x20100000
writing 47349760 bytes from the dynamic space at 0x1000000000
done]
NIL

* (quit)

$ ls -lh buildapp 
-rwxr-xr-x 1 inaimathi inaimathi 46M Aug 13 20:12 buildapp
$

Una volta creato quel file binario, puoi usarlo per costruire i binari dei tuoi programmi Common Lisp. Se hai intenzione di farlo molto, dovresti probabilmente metterlo da qualche parte sul tuo PATH modo che tu possa semplicemente eseguirlo con buildapp da qualsiasi directory.

Buildapp Ciao mondo

Il binario più semplice che è possibile creare

  1. Non ha dipendenze
  2. Non accetta argomenti dalla riga di comando
  3. Basta scrivere "Ciao mondo!" allo stdout

Dopo aver costruito buildapp , puoi solo ...

$ buildapp --eval '(defun main (argv) (declare (ignore argv)) (write-line "Hello, world!"))' --entry main --output hello-world
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into hello-world:
writing 4800 bytes from the read-only space at 0x20000000
writing 3216 bytes from the static space at 0x20100000
writing 43220992 bytes from the dynamic space at 0x1000000000
done]

$ ./hello-world 
Hello, world!

$

Buildapp Hello Web World

Un esempio più realistico tratta di un progetto che si sta costruendo con più file su disco (piuttosto che un --eval un'opzione passato a buildapp ), e alcune dipendenze di tirare in.

Poiché le cose arbitrarie possono accadere durante il rilevamento e il caricamento di sistemi asdf (incluso il caricamento di altri sistemi potenzialmente non correlati), non è sufficiente esaminare solo i file asd dei progetti a cui si sta lavorando per scoprire cosa è necessario caricare . L'approccio generale è usare quicklisp per caricare il sistema di destinazione, quindi chiamare ql:write-asdf-manifest-file per scrivere un manifest completo di tutto ciò che viene caricato.

Ecco un sistema di gioco creato con hunchentoot per illustrare come ciò potrebbe accadere nella pratica:


;;;; buildapp-hello-web-world.asd

(asdf:defsystem #:buildapp-hello-web-world
  :description "An example application to use when getting familiar with buildapp"
  :author "inaimathi <[email protected]>"
  :license "Expat"
  :depends-on (#:hunchentoot)
  :serial t
  :components ((:file "package")
               (:file "buildapp-hello-web-world"))
;;;; package.lisp

(defpackage #:buildapp-hello-web-world
  (:use #:cl #:hunchentoot))
;;;; buildapp-hello-web-world.lisp

(in-package #:buildapp-hello-web-world)

(define-easy-handler (hello :uri "/") ()
  (setf (hunchentoot:content-type*) "text/plain")
  "Hello Web World!")

(defun main (argv)
  (declare (ignore argv))
  (start (make-instance 'easy-acceptor :port 4242))
  (format t "Press any key to exit...~%")
  (read-char))
;;;; build.lisp
(ql:quickload :buildapp-hello-web-world)
(ql:write-asdf-manifest-file "/tmp/build-hello-web-world.manifest")
(with-open-file (s "/tmp/build-hello-web-world.manifest" :direction :output :if-exists :append)
  (format s "~a~%" (merge-pathnames
            "buildapp-hello-web-world.asd"
            (asdf/system:system-source-directory
             :buildapp-hello-web-world))))
#### build.sh
sbcl --load "build.lisp" --quit

buildapp --manifest-file /tmp/build-hello-web-world.manifest --load-system hunchentoot --load-system buildapp-hello-web-world --output hello-web-world --entry buildapp-hello-web-world:main

Una volta che hai salvato quei file in una directory chiamata buildapp-hello-web-world , puoi farlo

$ cd buildapp-hello-web-world/

$ sh build.sh 
This is SBCL 1.3.7.nixos, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
To load "cffi":
  Load 1 ASDF system:
    cffi
; Loading "cffi"
........
To load "buildapp-hello-web-world":
  Load 1 ASDF system:
    buildapp-hello-web-world
; Loading "buildapp-hello-web-world"
....
;; loading system "cffi"
;; loading system "hunchentoot"
;; loading system "buildapp-hello-web-world"
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into hello-web-world:
writing 4800 bytes from the read-only space at 0x20000000
writing 4624 bytes from the static space at 0x20100000
writing 66027520 bytes from the dynamic space at 0x1000000000
done]

$ ls -lh hello-web-world 
-rwxr-xr-x 1 inaimathi inaimathi 64M Aug 13 21:17 hello-web-world

Questo produce un binario che fa esattamente quello che pensi che dovrebbe, dato quanto sopra.

$ ./hello-web-world 
Press any key to exit...

Dovresti quindi essere in grado di attivare un'altra shell, curl localhost:4242 e vedere la risposta in chiaro di Hello Web World! essere stampato



Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow