changeset 456: |
8d7aa0af2367 |
parent: |
8e94959e96bd
|
child: |
702498601326 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Tue, 18 Jun 2024 21:29:07 -0400 |
permissions: |
-rwxr-xr-x |
description: |
graphwork |
1 #!/usr/bin/env -S sbcl --script 10 #-(or sbcl cl) (error "unsupported Lisp compiler") 12 (let ((quicklisp-init (or (probe-file #p"~/.stash/quicklisp/setup.lisp") 13 (probe-file #p"/usr/local/share/lisp/quicklisp/setup.lisp") 14 (probe-file #p "~/quicklisp/setup.lisp")))) 15 (when (probe-file quicklisp-init) 16 (load quicklisp-init))) 17 (require 'sb-rotate-byte) 18 (require 'sb-introspect) 22 ;; (require 'sb-sprof) 24 (asdf:load-system (asdf:find-system :cl-ppcre)) 25 (asdf:load-asd (probe-file (merge-pathnames "std.asd" "lisp/std/"))) 26 (asdf:load-system :std) 29 (:use :cl :std :std/named-readtables :cl-user) 30 (:export :*core-path* :*lisp-path* :*lib-path* :*std-path* :*ffi-path* :*stash-path* :*web-path* :*bin-path* 31 :*compression-level*)) 34 (use-package :sb-gray) 35 ;; (require 'sb-aclrepl) 36 (sb-ext:enable-debugger) 37 (defvar *core-path* (directory-namestring #.(or *load-truename* *compile-file-truename* (error "run me as an executable!")))) 39 (defvar *lisp-path* (merge-pathnames "lisp/" *core-path*)) 40 (defvar *bin-path* (merge-pathnames "bin/" *lisp-path*)) 41 (defvar *web-path* (merge-pathnames "web/" *lisp-path*)) 42 (defvar *lib-path* (merge-pathnames "lib/" *lisp-path*)) 43 (defvar *std-path* (merge-pathnames "std/" *lisp-path*)) 44 (defvar *ffi-path* (merge-pathnames "ffi/" *lisp-path*)) 45 (defvar *stash-path* (merge-pathnames ".stash/" *core-path*)) 47 (defvar *compression-level* nil) 49 (push *core-path* asdf:*central-registry*) 50 (push *lisp-path* ql:*local-project-directories*) 51 (push *lib-path* ql:*local-project-directories*) 52 (push *bin-path* ql:*local-project-directories*) 53 (push *ffi-path* ql:*local-project-directories*) 55 (ql:register-local-projects) 57 (unless (asdf:find-system :log nil) 58 (asdf:load-asd (probe-file (merge-pathnames "log/log.asd" *lib-path*)))) 60 (asdf:load-system :log) 63 (unless (asdf:find-system :rocksdb nil) 64 (asdf:load-asd (probe-file (merge-pathnames "rocksdb/rocksdb.asd" *ffi-path*))) 65 (asdf:load-system :rocksdb)) 67 (unless (asdf:find-system :cli nil) 68 (asdf:load-asd (probe-file (merge-pathnames "cli/cli.asd" *lib-path*)))) 70 (asdf:load-system :cli) 73 (defun done () (print :OK)) 75 (defmethod asdf:perform ((o asdf:image-op) (c asdf:system)) 76 (uiop:dump-image (merge-pathnames (car (last (std::ssplit #\/ (asdf:component-name c)))) *stash-path*) :executable t :compression *compression-level*)) 78 (defun compile-std (&optional force save) 81 (in-package :std-user) 82 (sb-ext:save-lisp-and-die (merge-pathnames "std.core" *stash-path*) :compression *compression-level*))) 84 (defun compile-prelude (&optional force save) 86 (asdf:compile-system :prelude :force force) 87 (asdf:load-system :prelude :force force) 88 ;; (rocksdb:load-rocksdb save) 90 (in-package :std-user) 91 (use-package :cl-user) 92 (sb-ext:save-lisp-and-die (merge-pathnames "prelude.core" *stash-path*) :compression *compression-level*))) 94 (defun compile-user (&optional force save) 95 (asdf:compile-system :user :force force) 96 (asdf:load-system :user :force force) 99 (use-package :cl-user) 100 (sb-ext:save-lisp-and-die (merge-pathnames "user.core" *stash-path*) :compression *compression-level*))) 102 (defun compile-tests (&optional force save) 103 (asdf:compile-system :core/tests :force force) 104 (asdf:load-system :core/tests :force force) 106 (in-package :core/tests) 107 (sb-ext:save-lisp-and-die (merge-pathnames "tests.core" *stash-path*) :compression *compression-level*))) 109 (defun compile-core (&optional force save) 110 (asdf:compile-system :core :force force) 111 (asdf:load-system :core :force force) 114 (sb-ext:save-lisp-and-die (merge-pathnames "core.core" *stash-path*) :compression *compression-level*))) 116 (defun save-foreign (name exports &rest args) 117 (apply #'sb-ext:save-lisp-and-die name (append `(:executable nil :callable-exports ,exports) args))) 119 (sb-alien:define-alien-callable compile-prelude sb-alien:void () (compile-prelude)) 120 (sb-alien:define-alien-callable compile-std sb-alien:void () (compile-std)) 121 (sb-alien:define-alien-callable compile-user sb-alien:void () (compile-user)) 125 (setq *print-level* 32 127 ;; collect args from shell 128 (defvar *args* (cdr sb-ext:*posix-argv*)) 131 (help "x.lisp --- core build tool 154 (defun parse-flag (arg) 156 (if (or (characterp k) (= (length k) 1)) 157 (case (char-downcase (character k)) 161 (if (char-equal (aref arg 0) #\-) 162 (if (= (length arg) 2) ;; short 164 (if (char-equal (aref arg 1) #\-) ;; long 166 (bail "invalid flag")))))) 168 ;; (defun parse-arg (arg)) 169 (defun x-compile (args) 171 (let ((name (car args))) 173 (asdf:compile-system name :force t)) 174 (compile-prelude t nil))) 177 (format t "saving ~A to: ~A~%" name (merge-pathnames name *stash-path*)) 178 (let ((sys (sb-int:keywordicate (format nil "BIN/~A" (string-upcase name))))) 180 (push :ssl *features*) 181 ;; (std/sys:forget-shared-objects) 184 (defun x-build (args) 186 (let ((name (car args))) 187 (ensure-directories-exist *stash-path*) 189 (std:wait-for-threads (mapcar 191 (sb-thread:make-thread 193 (sb-ext:run-program "x.lisp" (list "build" x) :wait t :output t)) 195 (list "skel" "rdb" "organ" "homer" "packy"))))) 197 (defun stash-output (name) 198 (let* ((sys (asdf:find-system name)) 200 :name (asdf/system:component-build-pathname sys) 201 :type (if (string-equal name "std") 204 (uiop:rename-file-overwriting-target 205 (merge-pathnames fasl (asdf:system-source-directory sys)) 206 (merge-pathnames fasl *stash-path*)))) 209 (let ((sys (sb-int:keywordicate (string-upcase name)))) 210 (std/sys:forget-shared-objects) 211 (asdf:load-system sys) 212 (in-package :std-user) 220 (let ((name (car args))) 221 (ensure-directories-exist *stash-path*) 223 (std:wait-for-threads (mapcar 225 (sb-thread:make-thread 227 (sb-ext:run-program "x.lisp" (list "make" x) :wait t :output t)) 229 (list "core" "user" "prelude" "core/tests" "core/bench" "core/lib" "core/ffi"))))) 233 (let ((name (car args))) 234 (ensure-directories-exist *stash-path*) 235 (format t "saving core to: ~A~%" (merge-pathnames name *stash-path*)) 237 ("prelude" (compile-prelude t t)) 238 ("core" (compile-core t t)) 239 ("std" (compile-std t t)) 240 ("user" (compile-user t t)) 241 ("tests" (compile-tests t t)))) 242 ;; (sb-ext:run-program "x.lisp" nil :input t :output t) 245 (asdf:load-asd (probe-file (merge-pathnames "log.asd" "lisp/lib/log/"))) 246 (asdf:load-asd (probe-file (merge-pathnames "rt.asd" "lisp/lib/rt/"))) 247 (asdf:load-system :log) 248 (asdf:load-system :rt) 253 (let ((name (car args))) 255 (ql:quickload (string-upcase (format nil "~A/tests" name))) 256 (rt:do-tests (string-upcase name) t)) 257 (bail "missing arg"))) 261 (let* ((name (car args)) 262 (path (merge-pathnames name *stash-path*))) 263 (unless (probe-file path) 264 (sb-ext:run-program "x" (list "build" name) :wait t :output t)) 265 (sb-ext:run-program path (cdr args) :output t)) 266 (bail "missing arg"))) 268 (defun %install (name) 269 (let ((path (merge-pathnames name *stash-path*))) 270 (unless (probe-file path) 271 (sb-ext:run-program "x" (list "build" name) :wait t :output t)) 272 (sb-ext:run-program "/bin/sudo" 273 (list "install" "-C" "-m" "755" (namestring path) "/usr/local/bin/") 277 (format t "installed ~A to ~A~%" name (merge-pathnames name "/usr/local/bin/")))) 279 (defun x-install (args) 282 (list "skel" "rdb" "organ" "homer" "packy")))) 284 (defun x-parse-args () 287 (println "Welcome to CORE/X") 288 (use-package :cl-user) 289 (use-package :sb-ext) 290 (use-package :std-user) 291 (sb-impl::toplevel-repl nil)) 292 (let ((cmd (pop *args*))) 294 ((equal cmd "compile") (setq *thunk* #'x-compile)) 295 ((equal cmd "build") (setq *thunk* #'x-build)) 296 ((equal cmd "run") (setq *thunk* #'x-run)) 297 ((equal cmd "test") (setq *thunk* #'x-test)) 298 ((equal cmd "save") (setq *thunk* #'x-save)) 299 ((equal cmd "make") (setq *thunk* #'x-make)) 300 ((equal cmd "install") (setq *thunk* #'x-install)) 301 (t (princ (getflag (parse-flag cmd))) (terpri) (sb-ext:exit :code 0)))))) 305 (let ((*args* (cdr sb-ext:*posix-argv*)) 308 (log:debug! "running command" *thunk* *args*) 309 (funcall *thunk* *args*))) 311 ;; (format t "saving self to ./x~%") 312 ;; (sb-ext:save-lisp-and-die 314 ;; :toplevel #'x-init 315 ;; ;; :callable-exports '("compile_std" "compile_prelude") 318 ;; :save-runtime-options t)