Build joltc as a self-contained binary (make joltc-release / joltc-debug)

host/chez/build-joltc.ss builds joltc into target/<profile>/joltc: it emits a
flat source of the full runtime + compiler image + inlined build.ss + every
jolt-core/stdlib file as a baked string literal + a cli.ss-style launcher, then
(in a fresh Chez, so the inlined runtime's redefinition of error doesn't strand
early references and runtime eval still sees the runtime's top-level procedures)
compiles it and cc-links it with the Chez petite/scheme boots and the launcher
stub embedded as C arrays. The launcher reads those arrays via FFI on
(jolt-materialize-bundles!) and registers them so build-self-contained can spill
them. joltc itself is cc-linked (clean signature for Homebrew); only the apps it
later builds use the appended-stub path.

build.ss: skip the csv toolchain check on the self-contained path and create the
build dir with a subprocess-free bld-mkdir-p, so a  from the
distributed binary shells out to nothing.

release = optimize-level 3 + no inspector info + compressed; debug =
optimize-level 0 + inspector + procedure source + debug-on-exception.

joltc-selfbuild-smoke.sh (make joltcsmoke) builds joltc and, with an empty
environment (no chez/cc/PATH), drives it through the build-app fixture, asserting
the produced binary's output. .gitignore ignores target/.
This commit is contained in:
Yogthos 2026-06-29 21:04:23 -04:00
parent 0420cd4d79
commit 242eeac5c6
5 changed files with 320 additions and 14 deletions

View file

@ -41,6 +41,12 @@
(unless (zero? rc)
(error 'jolt-build (string-append "command failed (" (number->string rc) "): " cmd)))))
;; mkdir -p without a subprocess (the self-contained build shells out to nothing).
(define (bld-mkdir-p dir)
(unless (or (string=? dir "") (string=? dir "/") (string=? dir ".") (file-exists? dir))
(bld-mkdir-p (path-parent dir))
(guard (e (#t #f)) (mkdir dir))))
(define (bld-contains? s sub)
(let ((ns (string-length s)) (nsub (string-length sub)))
(let loop ((i 0))
@ -329,7 +335,9 @@
;; no runtime redefinition). Off by default in every mode — release stays
;; dynamically linked.
(define (build-binary entry-ns out-path mode natives embed-dirs ext-roots direct-link? tree-shake?)
(bld-check-toolchain)
;; The self-contained path (jolt-embedded-bytes "stub/launcher") needs no csv
;; kernel files, no Chez, no cc — only the legacy cc path does.
(unless (jolt-embedded-bytes "stub/launcher") (bld-check-toolchain))
;; 1. record app namespaces in dependency order as they finish loading.
(let ((app-order '()))
(set-ns-loaded-hook!
@ -397,7 +405,7 @@
(boot (string-append builddir "/jolt.boot"))
(boot-h (string-append builddir "/boot_data.h"))
(main-c (string-append builddir "/main.c")))
(bld-system (string-append "mkdir -p '" builddir "'"))
(bld-mkdir-p builddir)
;; 3. flat source = runtime + app + launcher.
(let ((out (open-output-file flat-ss 'replace)))
(bld-emit-runtime out drop-compiler? core-strs)
@ -456,23 +464,21 @@
(build-with-cc entry-ns out-path mode builddir flat-ss flat-so boot boot-h main-c)))))))
;; --- self-contained link (in-process compile + append the boot to the stub) ---
;; The system `error` is restored around compile-file/make-boot-file: the loaded
;; jolt runtime shadows it (regex.ss, %chez-error holds the kernel original).
;; flat.ss opens with (import (chezscheme)) so the boot binds the real error
;; regardless, but the save/restore keeps any compile-time diagnostic honest.
;; compile-file runs with a FRESH scheme-environment as the interaction
;; environment: the loaded jolt runtime redefines `error` (regex.ss), and flat.ss
;; inlines that same runtime, so an early reference to `error` (before its define
;; runs) must bind to the kernel primitive — a clean env gives exactly that, the
;; same as the legacy path compiling in a fresh Chez process. Without it the boot
;; dies at startup with "variable error is not bound".
(define (build-self-contained entry-ns out-path mode builddir flat-ss flat-so boot)
(let ((petite (string-append builddir "/petite.boot"))
(scheme (string-append builddir "/scheme.boot")))
(jolt-spill-embedded! "csv/petite.boot" petite)
(jolt-spill-embedded! "csv/scheme.boot" scheme)
(display (string-append "jolt build: compiling " entry-ns " (" mode " mode, self-contained)\n"))
(let ((saved-err error))
(dynamic-wind
(lambda () (set! error %chez-error))
(lambda ()
(compile-file flat-ss flat-so)
(make-boot-file boot '() petite scheme flat-so))
(lambda () (set! error saved-err))))
(parameterize ((interaction-environment (copy-environment (scheme-environment))))
(compile-file flat-ss flat-so)
(make-boot-file boot '() petite scheme flat-so))
;; link: stub bytes ++ boot ++ frame, then make it executable.
(jolt-spill-embedded! "stub/launcher" out-path)
(jolt-append-payload! out-path (read-file-bytes boot))