# HG changeset patch # User Richard Westhaver # Date 1718579728 14400 # Node ID cd797f4eb846ee1b75d2d3af3e2b70b08bc51190 # Parent 147c13d8a5b4db54d26901b48688a0ad20cb87f8 rm infra.asd diff -r 147c13d8a5b4 -r cd797f4eb846 autogen.lisp --- a/autogen.lisp Sun Jun 16 15:02:42 2024 -0400 +++ b/autogen.lisp Sun Jun 16 19:15:28 2024 -0400 @@ -1,6 +1,18 @@ -;;; autogen.lisp --- Setup the current directory for +;;; autogen.lisp --- Auto-generate CC Infrastructure + +;; This script must be ran with a compliant CC lisp core image from a complian +;; CC lisp compiler. The easiest way to get started is by running the +;; 'bootstrap.sh' script first which will download these for you into the +;; local 'STASH' directory and run this script automatically. -;; sbcl --core .stash/share/lisp/user.core --load autogen.lisp +#| +# download pre-compiled binaries and run autogen.lisp +./bootstrap.sh + +# or run manually with local lisp runtime and core +sbcl --core $LISP_HOME/user.core --script autogen.lisp \ + --eval "(infra/autogen:autogen)" +|# ;;; Code: (in-package :std-user) @@ -10,27 +22,22 @@ :dat/json :dat/sxp :net/fetch :net/util :cli/progress :cli/ansi :cli/ed :cli/prompt :cli/shell :std/hash-table :std/alien :std/macs - :std/fmt)) + :std/fmt) + (:export :autogen)) (in-package :infra/autogen) - (in-readtable :shell) - +;;; Vars (defparameter *profile* (uiop:read-file-forms (if-let ((profile (sb-posix:getenv "INFRA_PROFILE"))) - profile - #P"default.sxp"))) + profile + #P"default.sxp"))) (defparameter *core* sb-ext:*core-pathname*) (defparameter *host* (uiop:read-file-forms (let ((hcfg (format nil "~a.sxp" (sb-unix:unix-gethostname)))) (unless (probe-file hcfg) (print #0$./check.sh$#)) hcfg))) - -(defun gethost (k) (getf *host* k)) -(defun getprofile (k) (getf *profile* k)) -(init-skel-vars) -(setq *skel-project* (find-skelfile *default-pathname-defaults* :load t)) (defparameter *host-env* (let ((table (make-hash-table :test 'equal)) (keys (list "STASH" "STORE" "DIST" "PACKY_URL" "VC_URL" "INSTALL_PREFIX" "CC" "AR" "HG" "GIT" "LISP" "RUST" "LD" "SHELL" "DEV" "DEV_HOME" @@ -38,20 +45,49 @@ "LISP_HOME" "INFRA_PROFILE"))) (dolist (k keys table) (setf (gethash k table) (sb-posix:getenv k))))) + +;;; Utils +(defun gethost (k) (getf *host* k)) +(defun getprofile (k) (getf *profile* k)) + (defun getenv (k) (gethash *host-env* k)) -(defun build-default () - (let ((comp-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos)))) - (packy-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :packy-repos)))) - (operator-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box)))) - (worker-builder (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker))))) - (std/thread:wait-for-threads - (list comp-builder packy-builder)))) +(defun setenv (k v) + (sb-posix:setenv k v 1) + (setf (gethash k *host-env*) v)) + +;;; Config +(defun init-profile () + (let ((stash (getprofile :stash)) + (cc (getprofile :cc))) + (if-let ((stash (probe-file stash))) + (setenv "STASH" (namestring stash)) + (error "STASH not found: ~A" stash)) + (if-let ((cc (cli:find-exe cc))) + (setenv "CC" (namestring cc)) + (error "STASH not found: ~A" cc)))) + +;;; Build +(defun make-default () + (std/thread:wait-for-threads + (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :repos))) + (sb-thread:make-thread (lambda () (sk-call* *skel-project* :packy-repos)))))) + +(defun make-pods () + (std/thread:wait-for-threads + (list (sb-thread:make-thread (lambda () (sk-call* *skel-project* :archlinux :box))) + (sb-thread:make-thread (lambda () (sk-call* *skel-project* :alpine :worker)))))) (defun autogen () "Auto-generate the INFRA system." - (info! "starting autogen.lisp" sb-ext:*core-pathname*) + (info! "starting autogen") + (in-readtable :shell) (terpri) + (init-profile) + (init-skel-vars) + (setq *skel-project* (find-skelfile *default-pathname-defaults* :load t)) + (unless (probe-file #p".stash") + (sk-call* *skel-project* :bootstrap)) ;; print host, env, profile (format t "core: ~A~%" *core*) (terpri) @@ -65,8 +101,7 @@ (println "profile:") (loop for (k v) on *profile* by 'cddr do (format t " ~A = ~A~%" k v)) - - (build-default)) + (make-default)) ;;; *host* ;; The host profile is generated automatically by 'check.sh'. After running @@ -75,12 +110,3 @@ ;;; *profile* ;; The default profile is defined in 'default.sxp'. You can use that as a base ;; configuration and override it with INFRA_PROFILE - -;; (sb-ext:quit) - -(unless (probe-file #p".stash") - (sk-call* *skel-project* :bootstrap)) - -;; (build-default) -(autogen) - diff -r 147c13d8a5b4 -r cd797f4eb846 bootstrap.sh --- a/bootstrap.sh Sun Jun 16 15:02:42 2024 -0400 +++ b/bootstrap.sh Sun Jun 16 19:15:28 2024 -0400 @@ -55,7 +55,11 @@ rm -rf *.tar say "successfully unpacked core" say "starting lisp..." - cd .. && .stash/bin/sbcl --core .stash/share/lisp/prelude.core --script autogen.lisp + cd .. && \ + .stash/bin/sbcl --core .stash/share/lisp/user.core \ + --load autogen.lisp \ + --eval "(infra/autogen:autogen)" \ + --non-interactive say "OK" } diff -r 147c13d8a5b4 -r cd797f4eb846 infra.asd --- a/infra.asd Sun Jun 16 15:02:42 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -(defsystem :infra - :depends-on (:std :dat :cli :skel :log :net :packy :pod :box :organ) - :components ((:file "autogen") - (:file "deploy")) - :build-pathname ".stash/bin/infra") diff -r 147c13d8a5b4 -r cd797f4eb846 readme.org --- a/readme.org Sun Jun 16 15:02:42 2024 -0400 +++ b/readme.org Sun Jun 16 19:15:28 2024 -0400 @@ -1,8 +1,9 @@ -{{{header(infra, -Richard Westhaver, -ellis@rwest.io, -The Compiler Company Infrastructure)}}} +#+title: infra +#+author: Richard Westhaver +#+email: richard.westhaver@gmail.com +#+description: The Compiler Company Infrastructure #+EXPORT_FILE_NAME: index +#+setupfile: https://cdn.compiler.company/org/clean.theme This project contains scripts, utils, and applications used to host and maintain The Compiler Company infrastructure.