Zoeken…


Build-app bouwen

Standalone Common Lisp binaries kunnen worden gebouwd met buildapp . Voordat we het kunnen gebruiken om binaire bestanden te genereren, moeten we het installeren en bouwen.

De eenvoudigste manier die ik ken is het gebruik van quicklisp en een Common Lisp (dit voorbeeld gebruikt [ sbcl ], maar het zou geen verschil moeten maken welke je hebt).

$ 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
$

Zodra je dat binaire bestand hebt gebouwd, kun je het gebruiken om binaire bestanden van je Common Lisp-programma's te maken. Als je van plan bent dit vaak te doen, moet je het waarschijnlijk ook ergens in je PATH zodat je het gewoon met buildapp vanuit elke map kunt uitvoeren.

Buildapp Hallo wereld

De eenvoudigst mogelijke binary die je zou kunnen bouwen

  1. Heeft geen afhankelijkheden
  2. Heeft geen opdrachtregelargumenten
  3. Schrijft gewoon "Hallo wereld!" naar stdout

Nadat je buildapp hebt gebouwd, kun je gewoon ...

$ 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 Hallo webwereld

Een realistischer voorbeeld betreft een project dat u bouwt met meerdere bestanden op schijf (in plaats van een --eval optie die aan buildapp doorgegeven), en enkele afhankelijkheden om in te trekken.

Omdat willekeurige dingen kunnen gebeuren tijdens het vinden en laden van asdf systemen (inclusief het laden van andere, mogelijk niet-gerelateerde systemen), is het niet voldoende om alleen de asd bestanden van de projecten te inspecteren waarvan u afhankelijk bent om erachter te komen wat u moet laden . De algemene aanpak is om quicklisp te gebruiken om het doelsysteem te laden en vervolgens ql:write-asdf-manifest-file aan te roepen om een volledig manifest uit te schrijven van alles wat is geladen.

Hier is een speelgoedsysteem gebouwd met hunchentoot om te illustreren hoe dat in de praktijk zou kunnen gebeuren:


;;;; 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

Zodra u die bestanden hebt opgeslagen in een map met de naam buildapp-hello-web-world , kunt u dat doen

$ 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

Dit levert een binair getal op dat precies doet wat je denkt dat het zou moeten, gezien het bovenstaande.

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

Je zou dan in staat moeten zijn om een andere shell op te curl localhost:4242 en de tekstreactie van Hello Web World! afgedrukt worden.



Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow