diff --git a/cli/default.nix b/cli/default.nix index 80913d8..5e8ee65 100644 --- a/cli/default.nix +++ b/cli/default.nix @@ -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 ''; } diff --git a/cli/zilch-go.scm b/cli/zilch-go.scm index c8ffb3d..09b5f42 100644 --- a/cli/zilch-go.scm +++ b/cli/zilch-go.scm @@ -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) diff --git a/cli/zilch-rust.scm b/cli/zilch-rust.scm index 213f1cb..44d724f 100644 --- a/cli/zilch-rust.scm +++ b/cli/zilch-rust.scm @@ -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) diff --git a/docs/manpages.nix b/docs/manpages.nix new file mode 100644 index 0000000..b1967ed --- /dev/null +++ b/docs/manpages.nix @@ -0,0 +1,13 @@ +{ pkgs, asciidoctor, groff, ... }: let + generateManpage = name: file: pkgs.runCommandNoCC name {} '' + ${asciidoctor}/bin/asciidoctor -b manpage -o $out ${file} + ''; + textifyManpage = name: manpage: pkgs.runCommandNoCC name {} '' + ${groff}/bin/groff -t -e -mandoc -Tascii ${manpage} > $out + ''; + + generateBoth = name: file: rec { man = generateManpage name file; txt = textifyManpage "${name}.txt" man; }; +in { + rust = generateBoth "zilch-cli-rust.1" ./modules/ROOT/pages/rust/man.adoc; + go = generateBoth "zilch-cli-go.1" ./modules/ROOT/pages/go/man.adoc; +}