(zilch lang ninja): process depfile, elide .h files where posssible

Incremental builds now take depfiles in account! Using a file that
contains a mapping of depfile to its cached contents, Zilch now
rebuilds less targets unnecessarily! If a build fails because an
include is added, it transparently rebuilds it with all possible header
dependencies, using the custom build scheduler built into Zilch. If an
include is removed, the target will be rebuilt with the new set of
headers the next time the CLI is invoked.

Change-Id: I6a6a6964c2fb191af4a474c45fd0f29623c588b0
This commit is contained in:
puck 2025-06-18 17:07:16 +00:00
parent 31bdc68f8c
commit 781e2b5534
5 changed files with 107 additions and 32 deletions

View file

@ -73,37 +73,42 @@ Arguments:
(import
(scheme base) (scheme file) (scheme read)
(chicken format) (chicken process)
(chicken format) (chicken process) (chicken file)
(zilch lang ninja) (zilch lang ninja build)
(zilch lang ninja nixpkgs)
(zilch lang ninja config)
(zilch magic) (zilch nixpkgs) (zilch vfs)
(zilch nix drv)
(zilch zexpr)
(srfi 152))
(srfi 128) (srfi 146) (srfi 152))
(define source (and (assoc 'source options) (cdr (assoc 'source options))))
(define config-path (if (assoc 'config-file options) (cdr (assoc 'config-file options)) "zilch.scm"))
(define config (parse-ninja-config `(override-source: ,source ,@(call-with-input-file config-path read))))
(when (and (ninja-build-config-depfile-path config) (file-exists? (ninja-build-config-depfile-path config)))
(set-ninja-build-config-depfile! config (alist->mapping (make-default-comparator) (call-with-input-file (ninja-build-config-depfile-path config) read))))
(cond
((string=? (car args) "source")
(let*-values
(((_ configured-drv _ _ _) (setup-ninja-environment config))
(((_ configured-drv _ _ _ _) (setup-ninja-environment config))
((realised) (store-path-realised configured-drv))
((path) (if (null? (cdr args)) "src" (cadr args))))
(system* (string-append "cp -rf --no-preserve=ownership " realised "/src " (qs path)))
(system* (string-append "chmod -R u+rw " (qs path)))))
((string=? (car args) "build")
(if (null? (cdr args))
(let ((built (build-nixpkgs-drv-reproducibly config)))
(let-values (((built export-depfile) (build-nixpkgs-drv-reproducibly config)))
(for-each
(lambda (output-and-path)
(store-path-realised (cdr output-and-path))
(printf "~A\t-> ~S\n" (car output-and-path) (cdr output-and-path)))
built))
(let-values (((_ _ _ edge-ref defaults) (setup-ninja-environment config)))
built)
(when (ninja-build-config-depfile-path config)
(call-with-output-file (ninja-build-config-depfile-path config) (lambda (p) (write (mapping->alist (export-depfile)) p)))))
(let-values (((_ _ _ edge-ref defaults _) (setup-ninja-environment config)))
(for-each
(lambda (target)
(define built-target (edge-ref target))
@ -111,7 +116,7 @@ Arguments:
(cdr args)))))
((string=? (car args) "diff")
(let*-values
(((_ configured-drv _ _ _) (setup-ninja-environment config))
(((_ configured-drv _ _ _ _) (setup-ninja-environment config))
((realised) (store-path-realised configured-drv))
((path) (or source "src")))
(process-execute "git" (list "diff" "--no-index" "--" (string-append realised "/src") path))))