docs: Generate manpages from docs, use in CLI

Change-Id: I6a6a69646c6ff4c4b70cb928dc1df06890144429
This commit is contained in:
puck 2025-06-23 12:22:20 +00:00
parent 5332df82bb
commit 30814de5e4
4 changed files with 26 additions and 45 deletions

View file

@ -1,5 +1,7 @@
{ pkgs, eggDerivation, chickenPackages, xxd }:
eggDerivation {
let
manPages = pkgs.callPackage ../docs/manpages.nix {};
in eggDerivation {
name = "zilch-cli";
src = ./.;
@ -13,5 +15,7 @@ eggDerivation {
preBuild = ''
(cat ${./overrides.json}; printf '\0') | ${xxd}/bin/xxd -i -n stock_overrides > stock_overrides.h
(cat ${manPages.rust.txt}; printf '\0') | ${xxd}/bin/xxd -i -n man_rust > man_rust.h
(cat ${manPages.go.txt}; printf '\0') | ${xxd}/bin/xxd -i -n man_go > man_go.h
'';
}

View file

@ -4,29 +4,13 @@
(foreign-lambda* int ()
"cpu_set_t set; sched_getaffinity(0, sizeof(set), &set); C_return(CPU_COUNT(&set));"))
(foreign-declare "#include \"man_go.h\"")
(define man-page (foreign-value "man_go" nonnull-c-string))
(define (print-help msg)
(when msg
(write-string (string-append msg "\n\n") (current-error-port)))
(write-string "Usage: zilch-cli-go [OPTION] [PACKAGE...]
Process the given module (or the current directory, if unspecified) and
output the store path for each package given on the command line (or
all executables in the module, if unspecified)
-h, --help Print this help message.
-j, --max-jobs COUNT The maximum amount of builds to run. Defaults
to the amount of cores.
-v, --verbose Increase the verbosity configured in the Nix
daemon.
-L, --print-build-logs Print derivation logs as they come in.
-m, --module-dir DIR The directory to use as root module.
-r, --replace DIR Replace the module specified by the go.mod
with this source directory, rather than using
the upstream module. Can be specified more
than once.
--debug Crash on the first error, rather than
continuing with the next package.
" (current-error-port))
(write-string man-page (current-error-port))
(exit (or (not msg) 1)))
(define-values (options args)

View file

@ -3,6 +3,9 @@
(foreign-declare "#include \"stock_overrides.h\"")
(define stock-overrides (foreign-value "stock_overrides" nonnull-c-string))
(foreign-declare "#include \"man_rust.h\"")
(define man-page (foreign-value "man_rust" nonnull-c-string))
(define get-cpu-count
(foreign-lambda* int ()
"cpu_set_t set; sched_getaffinity(0, sizeof(set), &set); C_return(CPU_COUNT(&set));"))
@ -10,30 +13,7 @@
(define (print-help msg)
(when msg
(write-string (string-append msg "\n\n") (current-error-port)))
(write-string "Usage: zilch-cli-rust [OPTION] [TARGET...]
Process the given crate directory (or the current directory, if unspecified)
and output derivations for each target given on the command line (or all
executables in the crate, if unspecified)
-h, --help Print this help message.
-j, --max-jobs COUNT The maximum amount of builds to run. Defaults
to the amount of cores.
-v, --verbose Increase the verbosity configured in the Nix
daemon.
-L, --print-build-logs Print derivation logs as they come in.
-m, --crate-dir DIR The directory to use as root crate.
-r, --replace DIR Replace the crate specified by the Cargo.toml
with this source directory, rather than using
the upstream crate. Can be specified more
than once.
-z, --overrides PATH Read build script overrides from this file.
By default, a stock set of overrides is read.
This can be disabled by passing `-z \"\"`
(a blank string).
--debug Crash on the first error, rather than
continuing with the next package.
" (current-error-port))
(write-string man-page (current-error-port))
(exit (or (not msg) 1)))
(define-values (options args)