Szukaj…


Budynek Buildapp

Samodzielne pliki binarne Common Lisp można budować za pomocą buildapp . Zanim będziemy mogli go użyć do wygenerowania plików binarnych, musimy go zainstalować i zbudować.

Najłatwiejszy sposób, w jaki wiem, jak używać quicklisp i Common Lisp (w tym przykładzie użyto [ sbcl ], ale nie powinno to mieć znaczenia, który z nich masz).

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

Kiedy już zbudujesz ten plik binarny, możesz go użyć do budowy plików binarnych programów Common Lisp. Jeśli zamierzasz to często robić, powinieneś również umieścić go gdzieś na swojej PATH , abyś mógł po prostu uruchomić go z buildapp z dowolnego katalogu.

Buildapp Hello World

Najprostszy możliwy plik binarny, jaki można zbudować

  1. Nie ma zależności
  2. Nie przyjmuje argumentów wiersza poleceń
  3. Po prostu pisze „Witaj świecie!” na standardowe stdout

Po zbudowaniu buildapp możesz po prostu ...

$ 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

Bardziej realistyczny przykład dotyczy projektu budowanego z wieloma plikami na dysku (zamiast opcji --eval przekazanej do buildapp ) oraz pewnych zależności do buildapp .

Ponieważ podczas wyszukiwania i ładowania systemów asdf mogą się zdarzyć dowolne rzeczy (w tym ładowanie innych, potencjalnie niepowiązanych systemów), nie wystarczy po prostu sprawdzić pliki asd projektów, od których zależysz, aby dowiedzieć się, co musisz załadować . Ogólne podejście polega na użyciu quicklisp do załadowania systemu docelowego, a następnie wywołaniu ql:write-asdf-manifest-file aby wypisać pełny manifest wszystkiego, co jest załadowane.

Oto system zabawek zbudowany z hunchentoot aby zilustrować, jak może się to zdarzyć w praktyce:


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

Po zapisaniu tych plików w katalogu o nazwie buildapp-hello-web-world możesz to zrobić

$ 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

To daje plik binarny, który robi dokładnie to, co według ciebie powinno, biorąc pod uwagę powyższe.

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

Powinieneś być w stanie odpalić kolejną powłokę, zrobić curl localhost:4242 i zobaczyć odpowiedź tekstową Hello Web World! wydrukować.



Modified text is an extract of the original Stack Overflow Documentation
Licencjonowany na podstawie CC BY-SA 3.0
Nie związany z Stack Overflow