Mercurial > core / lisp/lib/cli/multi.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
af486e0a40c9
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; multi.lisp --- Multi-entry Lisp Cores 3 ;; Busybox-style Lisp binaries 7 ;; We have quite a few Lisp 'binaries' at this point, each of which 8 ;; are quite bloated Lisp core images with tons of duplication. 10 ;; This setup isn't ideal and while we can compress each individual 11 ;; core, we are much better off if we can just share the same core 12 ;; image and access multiple top-level entrypoints easily. 14 ;; The problem of course is that we want to be able to execute the 15 ;; single core the same as we would the individual bloated 16 ;; binaries. To do this we have two options: 18 ;; - build (non-lisp) trampoline programs which loads the 19 ;; (non-executable) core as a shared library, and calls 20 ;; foreign-symbols exposed from lisp. 22 ;; - parse argv[0] and dispatch to the correct top-level 23 ;; function. Control argv[0] by symlinking to the executable core. 25 ;; This package currently exposes an API for the latter. 28 (in-package :cli/multi) 30 (defmacro define-multi-main (name default &rest mains) 31 "Define a MAIN function for the current package which dispatches 32 based on the value of '(ARG0)' at runtime to one of the pairs in 35 Each element of MAINS is a list of the form (NAME FUNCTION) where NAME 36 is the filename of the symlink which will be handled by the associated 39 When you save an executable lisp image with this function you should 40 arrange for symlinks for each handled value of (ARG0) to be generated 43 (case (keywordicate (string-upcase (pathname-name (clap:arg0)))) 47 (defun make-symlinks (src &optional directory &rest names) 48 "Make a set of symlinks from SRC to NAMES. 50 If DIRECTORY is non-nil each name in NAMES is considered relative to 53 (setf names (mapcar (lambda (n) (merge-pathnames n directory)) names))) 55 (sb-posix:symlink src n)))