Buildapp Hello Web World
一个更现实的例子涉及你在磁盘上使用多个文件构建的项目(而不是传递给 buildapp
的 --eval
选项),以及一些依赖项。
因为在发现和加载 asdf
系统期间可能发生任意事情(包括加载其他可能不相关的系统),仅仅检查你所依赖的项目的 asd
文件是不够的,以便找出你需要加载的内容。一般方法是使用 quicklisp
加载目标系统,然后调用 ql:write-asdf-manifest-file
写出所有已加载的清单。
这是一个用 hunchentoot
构建的玩具系统,用于说明在实践中可能发生的情况:
;;;; buildapp-hello-web-world.asd
(asdf:defsystem #:buildapp-hello-web-world
:description "An example application to use when getting familiar with buildapp"
:author "inaimathi <leo.zovic@gmail.com>"
: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
将这些文件保存在名为 buildapp-hello-web-world
的目录中后,就可以了
$ 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
这产生了一个二进制文件,它完全符合你的想法,如上所述。
$ ./hello-web-world
Press any key to exit...
然后你应该能够启动另一个 shell,做 curl localhost:4242
并看到 Hello Web World!
的明文响应被打印出来。