changeset 295: |
61f88f16e0f1 |
parent: |
9c37db8ed167
|
child: |
310cc699f766 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Wed, 19 Jun 2024 22:38:17 +0000 |
permissions: |
-rw-r--r-- |
description: |
autogen updates |
1 ;;; autogen.lisp --- Auto-generate CC Infrastructure 3 ;; This script must be ran with a compliant CC lisp core image from a complian 4 ;; CC lisp compiler. The easiest way to get started is by running the 5 ;; 'bootstrap.sh' script first which will download these for you into the 6 ;; local 'STASH' directory and run this script automatically. 9 # download pre-compiled binaries and run autogen.lisp 12 # or run manually with local lisp runtime and core 13 sbcl --core $LISP_HOME/user.core --script autogen.lisp \ 14 --eval "(infra/autogen:autogen)" 18 (in-package :std-user) 20 (defpkg :infra/autogen 21 (:use :cl :skel :log :std/named-readtables 22 :dat/json :dat/sxp :net/fetch :net/util 23 :cli/progress :cli/ansi :cli/ed :cli/prompt 24 :cli/shell :std/hash-table :std/alien :std/macs 28 (in-package :infra/autogen) 31 (defvar *all-features* 32 (list :default :org :demo :emacs-mini :ts :ts-langs :rust-tools :quicklisp :pod :box :packy)) 34 (defparameter *profile* (uiop:read-file-forms 35 (if-let ((profile (sb-posix:getenv "INFRA_PROFILE"))) 37 (when-let ((default (probe-file "default.sxp"))) 38 (sb-posix:setenv "INFRA_PROFILE" (namestring default) 1) 40 (defparameter *host* (uiop:read-file-forms 41 (let ((hcfg (format nil "~a.sxp" (sb-unix:unix-gethostname)))) 42 (unless (probe-file hcfg) 43 (print #0$./check.sh$#)) 45 (defparameter *host-env* (let ((table (make-hash-table :test 'equal)) 46 (keys (list "STASH" "STORE" "DIST" "PACKY_URL" "VC_URL" "INSTALL_PREFIX" 47 "CC" "AR" "HG" "GIT" "LISP" "RUSTC" "LD" "SHELL" "DEV" "DEV_HOME" 48 "DEV_ID" "WORKER" "WORKER_ID" "WORKER_HOME" "CARGO_HOME" "RUSTUP_HOME" 49 "LISP_HOME" "INFRA_PROFILE" "LOG_LEVEL"))) 50 (dolist (k keys table) 51 (setf (gethash k table) (sb-posix:getenv k))))) 54 (defun gethost (k) (getf *host* k)) 55 (defun getprofile (k) (getf *profile* k)) 57 (defun getenv (k) (gethash *host-env* k)) 60 (sb-posix:setenv k v 1) 61 (setf (gethash k *host-env*) v)) 63 (defmacro setenv* (&rest forms) 65 ,@(loop for (k v) on forms by #'cddr while v 66 collect `(setenv ,k (or ,v ""))))) 68 (defmacro check-err (is-warn ctrl &rest args) 72 :format-arguments (list ,@args)) 73 (std:simple-program-error 77 (defun setenv-exe (k v &optional warn) 78 (if-let ((path (cli:find-exe v))) 79 (setenv k (namestring path)) 80 (check-err warn "~A not found: ~A" k v))) 82 (defun setenv-probe (k v &optional warn) 83 (if-let ((path (probe-file v))) 84 (setenv k (namestring path)) 85 (check-err warn "~A not found: ~A" k v))) 87 (defun check-shared-lib (name &optional warn) 88 "Check for a shared library by loading it in the current session with dlopen. 89 When WARN is non-nil, signal a warning instead of an error." 90 (let ((local-lib-name (format nil "/usr/local/lib/lib~a.so" name)) 91 (sys-lib-name (format nil "/usr/lib/lib~a.so" name))) 92 (if-let ((lib (or (ignore-errors (sb-alien:load-shared-object local-lib-name)) 93 (ignore-errors (sb-alien:load-shared-object sys-lib-name))))) 94 (unwind-protect (format t "found shared lib: ~A~%" lib) 95 (sb-alien:unload-shared-object lib)) 96 (check-err warn "shared library missing in /usr/lib/ or /usr/local/lib/: ~x" name)))) 98 (defun check-exe (name &optional warn) 99 "Check for an executable in current $PATH by NAME. When WARN is non-nil, signal 100 a warning instead of an error." 101 (if-let ((bin (cli:find-exe name))) 102 (progn (format t "found executable: ~A~%" bin) t) 103 (check-err warn "executable missing: ~x" name))) 105 (defun check-default () 106 (check-shared-lib "rocksdb") 107 (check-shared-lib "uring") 108 (check-shared-lib "zstd") 109 (check-shared-lib "tree-sitter") 110 (check-shared-lib "xkbcommon")) 113 (check-exe "emacs" t)) 116 (check-exe "podman")) 119 (check-exe "qemu-system-x86_64")) 127 (defun check-feature (name) 128 "Dispatch a host check based on feature NAME." 130 (:default (check-default)) 135 (t (warn "unsupported feature: ~A" name)))) 137 (defun getpro-else (k else) (or (getprofile k) else)) 140 (defun init-profile () 141 (info! "initializing profile...") 142 (let* ((packy-url (uri:uri (getpro-else :packy-url "https://packy.compiler.company"))) 143 (vc-url (uri:uri (getpro-else :packy-url "https://vc.compiler.company"))) 144 (ar (getpro-else :ar "tar")) 145 (git (getpro-else :git "git")) 146 (hg (getpro-else :hg "hg")) 147 (cc (getpro-else :cc "clang")) 148 (ld (getpro-else :ld "lld")) 149 (install-prefix (getpro-else :install-prefix "/usr/local")) 150 (stash (getpro-else :stash ".stash")) 151 (store (getpro-else :store (namestring (merge-pathnames "share/store" stash)))) 152 (dist (getpro-else :dist (namestring (merge-pathnames "dist" store)))) 153 (lisp (getpro-else :lisp (lisp-implementation-type))) 154 (lisp-version (getpro-else :lisp-version (lisp-implementation-version))) 155 (log-level (getprofile :log-level)) 156 (lisp-home (getprofile :lisp-home)) 157 (quicklisp-home (getprofile :quicklisp-home)) 158 (rustc (getpro-else :rustc "rustc")) 159 (rust-home (getprofile :rust-home)) 160 (rustup-home (getprofile :rustup-home)) 161 (cargo-home (getprofile :cargo-home)) 162 (features (getprofile :features))) 163 (setq *log-level* log-level) 165 (trace! "env before update:") 166 (loop for k being the hash-key 167 using (hash-value v) of *host-env* 168 do (format t " ~A = ~A~%" k (or v "")) 170 (setenv-probe "STASH" stash t) 171 (setenv-probe "STORE" store t) 172 (setenv-probe "DIST" dist t) 173 (setenv-probe "INSTALL_PREFIX" install-prefix) 177 (setenv-exe "GIT" git) 179 (setenv-exe "RUSTC" rustc t) 180 (setenv-exe "LISP" lisp t) 182 "PACKY_URL" (uri:uri-to-string packy-url) 183 "VC_URL" (uri:uri-to-string vc-url) 184 "LISP_VERSION" lisp-version 185 "LISP_HOME" lisp-home 186 "QUICKLISP_HOME" quicklisp-home 187 "RUST_HOME" rust-home 188 "RUSTUP_HOME" rustup-home 189 "CARGO_HOME" cargo-home 190 "INSTALL_PREFIX" install-prefix 191 "LOG_LEVEL" (symbol-name log-level)) 194 (loop for f in features 196 (format t "checking host for feature: ~A~%" f) 204 (defun make-default () 205 (std/thread:wait-for-threads 206 (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos)) :name "repos"))) 207 (std/thread:wait-for-threads 209 (sb-thread:make-thread (lambda () (vc:run-hg-command "clone" (list ".stash/src/core.hg" ".stash/src/core"))) 211 (sb-thread:make-thread (lambda () (vc:run-hg-command "clone" (list ".stash/src/home.hg" ".stash/src/home"))) 213 (sb-thread:make-thread (lambda () (vc:run-hg-command "clone" (list ".stash/src/etc.hg" ".stash/src/etc"))) 217 (vc:run-hg-command "clone" (list ".stash/src/pod.hg" ".stash/src/pod")) 218 (std/thread:wait-for-threads 219 (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box))) 220 (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker)))))) 223 (vc:run-hg-command "clone" (list ".stash/src/box.hg" ".stash/src/box"))) 226 (sk-call* *skel-project* :packy-repos)) 229 (vc:run-hg-command "clone" (list ".stash/src/org.hg" ".stash/src/org"))) 232 (vc:run-hg-command "clone" (list ".stash/src/demo.hg" ".stash/src/demo"))) 234 (defun make-quicklisp () 235 (sk-call *skel-project* :quicklisp)) 237 (defun make-emacs-mini () 238 (sk-run (sk-find-script "install-emacs-mini-pack" *skel-project*))) 241 (sk-call *skel-project* :tree-sitter)) 243 (defun make-ts-langs () 244 (sk-call *skel-project* :tree-sitter-langs)) 247 (info! (machine-version) 248 "starting autogen...") 249 (in-readtable :shell) 254 (setq *skel-project* (find-skelfile *default-pathname-defaults* :load t)) 255 (unless (probe-file #p".stash") 256 (sk-call* *skel-project* :bootstrap)) 258 ;; print post-init info 261 (format t "lisp: ~A ~A~%"(lisp-implementation-type) (lisp-implementation-version)) 263 (format t "core: ~A~%" sb-ext:*core-pathname*) 266 (loop for (k v) on *host* by 'cddr 267 do (format t " ~A = ~A~%" k v)) 270 (loop for (k v) on *profile* by 'cddr 271 do (format t " ~A = ~A~%" k v)) 274 (loop for k being the hash-key 275 using (hash-value v) of *host-env* 276 do (format t " ~A = ~A~%" k (or v "")))) 277 ;; process all features 278 (let ((features (getprofile :features))) 279 (when (member :all features) (setf features *all-features*)) 280 (when (member :default features) (make-default)) 281 (std/thread:wait-for-threads 284 (when (member :org features) (sb-thread:make-thread #'make-org :name "org")) 285 (when (member :pod features) (sb-thread:make-thread #'make-pods :name "pod")) 286 (when (member :quicklisp features) (sb-thread:make-thread #'make-quicklisp :name "quicklisp")) 287 (when (member :emacs-mini features) (sb-thread:make-thread #'make-emacs-mini :name "emacs-mini")) 288 (when (member :ts features) (sb-thread:make-thread #'make-ts :name "ts")) 289 (when (member :ts-langs features) (sb-thread:make-thread #'make-ts-langs :name "ts-langs")) 290 (when (member :box features) (sb-thread:make-thread #'make-boxes :name "box")) 291 (when (member :packy features) (sb-thread:make-thread #'make-packy :name "packy")))))))