Debian Codegraph @

doc/index.html

raw symbols SCIP
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
4 <link rel='stylesheet' type='text/css' href='style.css'>
5 <title>Buildapp - Create executables with SBCL or CCL</title>
6 </head>
7 <body>
8
9 <div id='content'>
10 <h2>Buildapp - Create executables with SBCL or CCL</h2>
11
12 <div id='summary'>
13 <p>Buildapp is an application for SBCL or CCL that configures and saves an
14 executable Common Lisp image. It is similar
15 to <a href='http://www.cliki.net/cl-launch'>cl-launch</a> and
16 hu.dwim.build. Buildapp is available under
17 a <a href='#license'>BSD-style license</a>.
18
19 The latest version is 1.5.6, released on November 7th, 2015.
20
21 <p>Download shortcut: <a href='http://www.xach.com/lisp/buildapp.tgz'>http://www.xach.com/lisp/buildapp.tgz</a>
22 </div>
23
24 <h2>Contents</h2>
25
26 <ul>
27 <li> <a href='#installation'>Installation</a>
28 <li> <a href='#example'>Example Use</a>
29 <li> <a href='#overview'>Overview</a>
30 <li> <a href='#limitations'>Limitations</a>
31 <li> <a href='#implementation'>Implementation</a>
32 <li> <a href='#feedback'>Feedback</a>
33 <li> <a href='#license'>License</a>
34 </ul>
35
36 <a name='installation'><h2>Installation</h2></a>
37
38 <p>Buildapp does not require any libraries. To compile it with SBCL
39 you simply run <tt>make install</tt>. To compile with a different
40 lisp, just specify it after the make command:
41 <tt>make install LISP=&lt;my_favorite_lisp&gt;</tt>. For example,
42 you wanted to compile it under CCL you'd say
43 <tt>make install LISP=ccl</tt> By default, it is installed in
44 <tt>/usr/local/bin</tt>; to use another location,
45 use <tt>make&nbsp;DESTDIR=/path&nbsp;install</tt>.
46
47 <p>You can also create the buildapp binary by loading the buildapp
48 system with asdf and running <tt>(buildapp:build-buildapp)</tt>.
49
50
51 <a name='example'><h2>Example Use</h2></a>
52
53 <p>Here's a small application:
54
55 <pre class=code>
56 $ <b>buildapp \
57 --eval '(defun main (argv) (declare (ignore argv)) (write-line "Hello, world"))' \
58 --entry main \
59 --output hello-world</b>
60 [undoing binding stack and other enclosing state... done]
61 [saving current Lisp image into hello-world:
62 writing 6352 bytes from the read-only space at 0x20000000
63 writing 4064 bytes from the static space at 0x20100000
64 writing 44834816 bytes from the dynamic space at 0x1000000000
65 done]
66
67 $ <b>./hello-world</b>
68 Hello, world
69 </pre>
70
71
72 <p>The following creates a
73 toy <a href="http://curl.haxx.se/">curl</a>-like application. (It's
74 not quite practical, because any errors will land you in the
75 interactive debugger.)
76
77 <pre class='code'>
78 $ <b>buildapp --output lisp-curl --asdf-path ~/src/clbuild/systems/ \
79 --load-system drakma \
80 --eval '(defun main (args) (write-string (drakma:http-request (second args))))' \
81 --entry main</b>
82 ;; loading system sb-grovel (needed by drakma)
83 ;; from /usr/local/lib/sbcl/sb-grovel/
84 ;; loading system sb-posix (needed by cl+ssl)
85 ;; from /usr/local/lib/sbcl/sb-posix/
86 ;; loading system trivial-gray-streams (needed by chunga, cl+ssl, flexi-streams)
87 ;; from /home/xach/src/clbuild/source/trivial-gray-streams/
88 ;; loading system flexi-streams (needed by drakma, cl+ssl)
89 ;; from /home/xach/src/clbuild/source/flexi-streams/
90 ;; loading system alexandria (needed by cffi, babel)
91 ;; from /home/xach/src/clbuild/source/alexandria/
92 ;; loading system trivial-features (needed by cffi, babel)
93 ;; from /home/xach/src/clbuild/source/trivial-features/
94 ;; loading system babel (needed by cffi)
95 ;; from /home/xach/src/clbuild/source/babel/
96 ;; loading system cffi (needed by cl+ssl)
97 ;; from /home/xach/src/clbuild/source/cffi/
98 ;; loading system cl+ssl (needed by drakma)
99 ;; from /home/xach/src/clbuild/source/cl+ssl/
100 ;; loading system sb-bsd-sockets (needed by usocket)
101 ;; from /usr/local/lib/sbcl/sb-bsd-sockets/
102 ;; loading system usocket (needed by drakma)
103 ;; from /home/xach/src/clbuild/source/usocket/
104 ;; loading system chunga (needed by drakma)
105 ;; from /home/xach/src/clbuild/source/chunga/
106 ;; loading system cl-base64 (needed by drakma)
107 ;; from /home/xach/src/clbuild/source/cl-base64/
108 ;; loading system puri (needed by drakma)
109 ;; from /home/xach/src/clbuild/source/puri/
110 ;; loading system drakma
111 ;; from /home/xach/src/clbuild/source/drakma/
112 [undoing binding stack and other enclosing state... done]
113 [saving current Lisp image into lisp-curl:
114 writing 6352 bytes from the read-only space at 0x20000000
115 writing 5472 bytes from the static space at 0x20100000
116 writing 61722624 bytes from the dynamic space at 0x1000000000
117 done]
118
119 $ <b>./lisp-curl http://xach.com/</b>
120 &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
121 "http://www.w3.org/TR/REC-html40/loose.dtd">
122 &lt;HTML>
123 &lt;HEAD>
124 &lt;TITLE>www.xach.com&lt;/TITLE>
125 &lt;/HEAD>
126 ...
127 </pre>
128
129 <p>Here's how the <a href="http://l1sp.org/">l1sp.org</a> redirection
130 service application is built:
131
132 <pre class='code'>
133 $ <b>make</b>
134 buildapp --output l1sp --entry redirector:main \
135 --asdf-path /opt/l1sp/systems \
136 --require sb-aclrepl \
137 --eval '(pushnew :hunchentoot-no-ssl *features*)' \
138 --load-system swank \
139 --eval '(setf swank:*log-output* nil)' \
140 --load-system redirector
141 ;; loading system sb-grovel
142 ;; from /usr/local/lib/sbcl/sb-grovel/
143 ;; loading system sb-bsd-sockets
144 ;; from /usr/local/lib/sbcl/sb-bsd-sockets/
145 ;; loading system sb-introspect
146 ;; from /usr/local/lib/sbcl/sb-introspect/
147 ;; loading system sb-posix
148 ;; from /usr/local/lib/sbcl/sb-posix/
149 ;; loading system sb-cltl2
150 ;; from /usr/local/lib/sbcl/sb-cltl2/
151 ;; loading system swank
152 ;; from /opt/l1sp/src/slime/
153 ;; loading system html-template (needed by redirector)
154 ;; from /opt/l1sp/src/html-template-0.9.1/
155 ;; loading system sb-rotate-byte (needed by sb-md5)
156 ;; from /usr/local/lib/sbcl/sb-rotate-byte/
157 ;; loading system sb-md5 (needed by redirector)
158 ;; from /usr/local/lib/sbcl/sb-md5/
159 ;; loading system cl-who (needed by redirector)
160 ;; from /opt/l1sp/src/cl-who-0.11.1/
161 ;; loading system cl-ppcre (needed by hunchentoot, redirector)
162 ;; from /opt/l1sp/src/cl-ppcre-2.0.0/
163 ;; loading system url-rewrite (needed by hunchentoot)
164 ;; from /opt/l1sp/src/url-rewrite-0.1.1/
165 ;; loading system rfc2388 (needed by hunchentoot)
166 ;; from /opt/l1sp/src/rfc2388/
167 ;; loading system md5 (needed by hunchentoot)
168 ;; from /opt/l1sp/src/md5-1.8.5/
169 ;; loading system cl-fad (needed by hunchentoot)
170 ;; from /opt/l1sp/src/cl-fad-0.6.2/
171 ;; loading system cl-base64 (needed by hunchentoot)
172 ;; from /opt/l1sp/src/cl-base64-3.3.2/
173 ;; loading system trivial-gray-streams (needed by flexi-streams)
174 ;; from /opt/l1sp/src/trivial-gray-streams-2006-09-16/
175 ;; loading system flexi-streams (needed by chunga)
176 ;; from /opt/l1sp/src/flexi-streams-1.0.7/
177 ;; loading system chunga (needed by hunchentoot)
178 ;; from /opt/l1sp/src/chunga-0.4.3/
179 ;; loading system hunchentoot (needed by redirector)
180 ;; from /opt/l1sp/src/hunchentoot-0.15.7/
181 ;; loading system redirector
182 ;; from /opt/l1sp/src/redirector/
183 [undoing binding stack and other enclosing state... done]
184 [saving current Lisp image into l1sp:
185 writing 6176 bytes from the read-only space at 0x20000000
186 writing 4064 bytes from the static space at 0x20100000
187 writing 61042688 bytes from the dynamic space at 0x1000000000
188 done]
189
190 $ <b>./l1sp</b>
191 ;; Swank started at port: 7717.
192 CL-USER(1):
193 </pre>
194
195 <p>The <tt>(setf swank:*log-output* nil)</tt> eval is needed to avoid
196 problems when the image restarts.
197
198 <p><tt>redirector::main</tt> looks like this:
199
200 <pre class='code'>
201 (defun main (argv)
202 (declare (ignore argv))
203 (load "/opt/l1sp/etc/init.lisp")
204 (sb-impl::toplevel-repl nil))
205 </pre>
206
207 <p>Here's an example of the <tt>--dispatched-entry</tt> option, which
208 was inspired by the desire to have a dozen different small utilities
209 embedded in one big executable and called based on the binary name.
210
211 First, the support files:
212
213 <pre class=code>
214 ;;;; <b>utils.lisp</b>
215
216 (defpackage #:utils
217 (:use #:cl))
218
219 (in-package #:utils)
220
221 (defun main (argv)
222 (let ((name (pathname-name (first argv))))
223 (format *error-output*
224 "Unknown binary name ~S, try using cl-echo, cl-ls, or cl-true~%"
225 name)
226 (sb-ext:quit :unix-status 1)))
227
228 ;;;; <b>ls.lisp</b>
229
230 (defpackage #:ls
231 (:use #:cl))
232
233 (in-package #:ls)
234
235 (defun main (argv)
236 (declare (ignore argv))
237 (dolist (file (directory "*.*"))
238 (write-line (namestring file))))
239
240 ;;;; <b>echo.lisp</b>
241
242 (defpackage #:echo
243 (:use #:cl))
244
245 (in-package #:echo)
246
247 (defun main (argv)
248 (format t "~{~A~^ ~}~%" (rest argv)))
249
250 ;;;; <b>true.lisp</b>
251
252 (defpackage #:true
253 (:use #:cl))
254
255 (in-package #:true)
256
257 (defun main (argv)
258 (declare (ignore argv))
259 (sb-ext:quit :unix-status 0))
260 </pre>
261
262 <p>Buliding it all together looks like this:
263
264
265 <pre class=code>
266 $ <b>buildapp --output utils \
267 --load utils.lisp --dispatched-entry /utils:main \
268 --load ls.lisp --dispatched-entry cl-ls/ls:main \
269 --load echo.lisp --dispatched-entry cl-echo/echo:main \
270 --load true.lisp --dispatched-entry cl-true/true:main</b>
271 ;; loading file #P"/tmp/demo/utils.lisp"
272 ;; loading file #P"/tmp/demo/ls.lisp"
273 ;; loading file #P"/tmp/demo/echo.lisp"
274 ;; loading file #P"/tmp/demo/true.lisp"
275 [undoing binding stack and other enclosing state... done]
276 [saving current Lisp image into utils:
277 writing 6352 bytes from the read-only space at 0x20000000
278 writing 4064 bytes from the static space at 0x20100000
279 writing 45223936 bytes from the dynamic space at 0x1000000000
280 done]
281
282 $ <b>ln -sf utils cl-ls</b>
283
284 $ <b>ln -sf utils cl-echo</b>
285
286 $ <b>ln -sf utils cl-true</b>
287
288 $ <b>./cl-ls</b>
289 /tmp/demo/cl-true
290 /tmp/demo/echo.lisp
291 /tmp/demo/ls.lisp
292 /tmp/demo/true.lisp
293 /tmp/demo/utils
294 /tmp/demo/utils.lisp
295
296 $ <b>./cl-echo Hello world</b>
297 Hello world
298
299 $ <b>./cl-true && echo $?</b>
300 0
301
302 </pre>
303
304 <a name='overview'><h2>Overview</h2>
305
306 <p>Here is the usage output of buildapp:
307
308 <pre>
309 Usage: buildapp --output OUTPUT-FILE [--flag1 value1 ...]
310
311 Required flags:
312 --output OUTPUT-FILE Use OUTPUT-FILE as the name of the executable
313 to create
314
315 Entry-point flags:
316 --entry NAME Use the function identified by NAME as the
317 executable's toplevel function. Called
318 with SB-EXT:*POSIX-ARGV* as its only
319 argument. If NAME has a colon, it is
320 treated as a package separator,
321 otherwise CL-USER is the implied
322 package.
323 --dispatched-entry DNAME Specify one possible entry function, depending
324 on the name of the file that is used to
325 start the application. The syntax of
326 DNAME is APPLICATION-NAME/ENTRY-NAME. If the
327 name used to start the executable matches
328 APPLICATION-NAME, use ENTRY-NAME as the
329 entry point. This can be used to choose
330 one of many possible entry points by
331 e.g. symlinking names to the application
332 executable. If APPLICATION-NAME is empty, the
333 specified ENTRY-NAME is used as a default
334 if no other application names match. There
335 may be any number of dispatched entry points,
336 but only one default.
337
338 Action flags:
339 --load FILE Load FILE. CL:*PACKAGE* is bound to the CL-USER
340 package before loading
341 --load-system NAME Load an ASDF system identified by NAME
342 --require NAME Use CL:REQUIRE to load NAME
343 --eval CODE Use CL:EVAL to evaulate CODE. The code is read
344 with CL:READ-FROM-STRING in the CL-USER package
345
346 There may be any number of load/load-system/require/eval flags. Each
347 is executed in command-line order before creating an executable.
348
349 Load path flags:
350 --load-path DIRECTORY When handling a --load, search DIRECTORY for
351 files to load
352 --asdf-path DIRECTORY When handling a --load-system, search DIRECTORY
353 for ASDF system files to load
354 --asdf-tree DIRECTORY When handling a --load-system, search DIRECTORY
355 and all its subdirectories for ASDF system
356 files to load
357 --manifest-file FILE When handling a --load-system, read a list of
358 ASDF system file pathnames from FILE as
359 possible matching systems.
360
361 There may be any number of load-path/asdf-path/asdf-tree/manifest-file
362 flags. They take priority in command-line order.
363
364 Other flags:
365 --compress-core Compress the core or executable; requires
366 configuration support in SBCL
367 --core-only Make a core file only, not an executable
368 --dynamic-space-size MB Pass a --dynamic-space-size option to SBCL
369 when building; value is megabytes
370 --help Show this usage message
371 --logfile FILE Log compilation and load output to FILE
372 --sbcl PATH-TO-SBCL Use PATH-TO-SBCL instead of the sbcl program
373 found in your PATH environment variable
374
375 For the latest documentation, see http://www.xach.com/lisp/buildapp/
376 </pre>
377
378
379
380 <a name='limitations'><h2>Limitations</h2></a>
381
382 <p>Buildapp is limited in scope. It aims to make the following steps
383 easy:
384
385 <ul>
386 <li> Define an application environment by loading files, loading ASDF
387 systems, evaluating code, and using CL:REQUIRE
388 <li> Dump an executable image with an arbitrary startup function
389 </ul>
390
391 <p>By design, it does <i>not</i> handle the following tasks:
392
393 <ul>
394 <li> Initialization tasks at app startup
395 (use <a href='http://l1sp.org/sbcl/sb-ext:*init-hooks*'>SB-EXT:*INIT-HOOKS*</a>
396 for that)
397 <li> Debugger management (use <tt>*DEBUGGER-HOOK*</tt> for that)
398 <li> Command-line processing (use a library such
399 as <a href='http://common-lisp.net/project/qitab/'>COMMAND-LINE-ARGUMENTS</a>
400 for that)
401 <li> Obtaining libraries
402 (use <a href='http://common-lisp.net/project/clbuild/'>clbuild</a>,
403 <a href='http://libcl.com/'>LibCL</a>, <a href='http://common-lisp.net/project/cl-librarian/'>cl-librarian</a>,
404 asdf-install, etc. for that)
405 </ul>
406
407
408 <a name='implementation'><h2>Implementation</h2></a>
409
410 <p>Buildapp works like this:
411
412 <ol>
413
414 <li>It processes the command-line and creates an object that
415 captures the command-line requirements: the output file, any
416 eval/load/load-system/require actions, the entry function, etc.
417
418 <li>It creates a new Lisp file (the <i>dumpfile</i>) with all the
419 commands needed to implement the command-line options.
420
421 <li>It runs either "sbcl"
422 with <a href='http://l1sp.org/sbcl/sb-ext:run-program'><tt>sb-ext:run-program</tt></a>
423 or "ccl" with
424 <a href='http://ccl.clozure.com/ccl-documentation.html#External-Program-Dictionary'><tt>ccl:run-program</tt></a>.
425 In either case lisp is invoked with no init files (it doesn't read
426 user or system rc files) and loads the dumpfile:
427
428 <ol>
429
430 <li>The first few commands of the dumpfile establish a specialized
431 loading environment:
432
433 <ul>
434 <li> The debugger is changed
435 with <a href='http://l1sp.org/sbcl/sb-ext:*invoke-debugger-hook*'><tt>*invoke-debugger-hook*</tt></a>
436 to simply quit with a special exit code instead of entering the
437 normal debugger (in CCL the same behavior is accomplished using
438 the <tt>:application</tt> and <tt>:error-handler</tt> arguments
439 to <tt>ccl:save-application</tt>)
440 <li> Most output (ASDF system compilation output, low-level error
441 messages, etc) is redirected to a log stream; that stream can be
442 directed to a file with the <tt>--logfile</tt> argument
443 <li> Stale compiled files are automatically recompiled with an <tt>:around</tt>
444 method on <tt>asdf:perform</tt>
445 </ul>
446
447 <li>There are some sanity checks: Is the
448 output file writable? Does this version of sbcl support the
449 required <tt>:save-runtime-options</tt> argument?
450
451 <li>The dumpfile performs the eval/load/load-system/require
452 actions. Each operation is evaluated in the <tt>cl-user</tt> package
453 and with a fresh binding of <tt>sb-ext:*invoke-debugger-hook*</tt>
454 in sbcl or <tt>ccl::*debugger-hook*</tt> in ccl to the buildapp
455 debugger function. If the binding is modified, the new value is
456 saved.
457
458 <li>The dumpfile clears itself out of the environment:
459
460 <ul>
461 <li> Remove extra ASDF methods
462 with <a href='http://l1sp.org/cl/remove-method'><tt>remove-method</tt></a>
463 <li> Reset the debugger hook to the saved value or NIL if no value was
464 saved.
465 <li> Delete the dumpfile package
466 with <a href='http://l1sp.org/cl/delete-package'><tt>delete-package</tt></a>
467 </ul>
468
469 <li>The dumpfile then creates an executable
470 with <a href="http://l1sp.org/sbcl/sb-ext:save-lisp-and-die"><tt>save-lisp-and-die</tt></a>
471 in sbcl or
472 <a href="http://ccl.clozure.com/manual/chapter4.9.html"><tt>ccl:save-application</tt></a>
473 in ccl. This ends the lisp subprocess.
474 </ol>
475
476 <li> It deletes the dumpfile.
477 </ol>
478
479 <p> The ASDF central registry is temporarily extended with
480 the <tt>--asdf-path</tt> and <tt>--asdf-tree</tt> arguments at load
481 time, and reverts back to the default central registry value after
482 that. To avoid conflicts with this behavior, changes to the central
483 registry should be done at startup time instead of application load
484 time.
485
486
487 <a name='feedback'><h2>Feedback</h2></a>
488
489 <p>If you have any questions or comments about buildapp, please email
490 me, <a href='mailto:[email protected]'>Zach Beane</a>.
491
492 <a name='license'><h2>License</h2></a>
493
494 <p>Copyright &copy; 2010 Zachary Beane, All Rights Reserved
495
496 <p> Redistribution and use in source and binary forms, with or without
497 modification, are permitted provided that the following conditions
498 are met:
499
500 <ul>
501 <li>
502 Redistributions of source code must retain the above copyright
503 notice, this list of conditions and the following disclaimer.
504
505 <li> Redistributions in binary form must reproduce the above
506 copyright notice, this list of conditions and the following
507 disclaimer in the documentation and/or other materials
508 provided with the distribution.
509
510 </ul>
511 <p> THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
512 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
513 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
514 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
515 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
516 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
517 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
518 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
519 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
520 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
521 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
522