Subject: [bug#75501] [PATCH] gnu: mandoc: Support zstd-compressed man pages.

From: Maxim Cournoyer <[email-masked]>
Date: Wed, 15 Jan 2025 14:09:47 +0900

Hello!

[email-masked] writes:

> From: Sören Tempel <[email-masked]>
>
> Since #68242 Guix uses zstd compression for man pages.  Unfortunately,
> upstream mandoc only supports gzip compressed man pages.  Luckily, zstd
> provides a wrapper library which easily allows adapting software using
> zlib to zstd compression.  This patch uses this wrapper library in
> conjunction with mandoc to add support for zstd compression to it,
> thereby allowing Guix man pages to be viewed with mandoc again.

Oh!  I have never used mandoc, only man-db.

> * gnu/packages/man.scm (mandoc): Support zstd compression.
> * gnu/local.mk: Add new patch.
> * gnu/packages/patches/mandoc-support-zstd-compression.patch: New
> file.

[...]

>      (arguments
>       `(#:test-target "regress"
> -       #:phases (modify-phases %standard-phases
> -                  (add-before 'configure 'set-prefix
> -                    (lambda* (#:key outputs #:allow-other-keys)
> -                      (substitute* "configure"
> -                        (("^CC=.*")
> -                         (string-append "CC=" ,(cc-for-target) "\n"))
> -                        (("^DEFCFLAGS=\\\\\"")
> -                         "DEFCFLAGS=\"-O2 ")
> -                        (("^UTF8_LOCALE=.*")      ;used for tests
> -                         "UTF8_LOCALE=en_US.UTF-8\n")
> -                        (("^MANPATH_(BASE|DEFAULT)=.*" _ which)
> -                         (string-append "MANPATH_" which "="
> -                                        "/run/current-system/profile/share/man\n"))
> -                        (("^PREFIX=.*")
> -                         (string-append "PREFIX=" (assoc-ref outputs "out")
> -                                        "\n"))))))))
> +       #:make-flags
> +       (list "VPATH=./zstd-src/zlibWrapper"
> +             (string-join
> +               (list "CFLAGS=-DZWRAP_USE_ZSTD=1"
> +                     (string-append "-I./zstd-src/zlibWrapper"))
> +               " "))
> +       #:phases ,#~(modify-phases %standard-phases
> +                     (add-after 'unpack 'unpack-zstd
> +                       (lambda _
> +                         (mkdir "zstd-src")
> +                         (invoke "tar" "--strip-components=1" "-C" "zstd-src"
> +                                 "-xf" #$(package-source zstd))))
> +                     (add-before 'configure 'set-prefix
> +                       (lambda* (#:key outputs #:allow-other-keys)
> +                         (substitute* "configure"
> +                           (("^CC=.*")
> +                            (string-append "CC=" #$(cc-for-target) "\n"))
> +                           (("^DEFCFLAGS=\\\\\"")
> +                            "DEFCFLAGS=\"-O2 ")
> +                           (("^UTF8_LOCALE=.*")      ;used for tests
> +                            "UTF8_LOCALE=en_US.UTF-8\n")
> +                           (("^MANPATH_(BASE|DEFAULT)=.*" _ which)
> +                            (string-append "MANPATH_" which "="
> +                                           "/run/current-system/profile/share/man\n"))
> +                           (("^PREFIX=.*")
> +                            (string-append "PREFIX=" (assoc-ref outputs "out")
> +                                           "\n"))))))))

While moving things around, I'd use a plain list for the arguments, and
format the phases under the #:phases argument (newline), to satisfy our
max 80 columns of width convention.

>      (native-inputs (list (libc-utf8-locales-for-target) perl)) ;used to run tests
> -    (inputs (list zlib))
> +    (inputs (list zlib (list zstd "lib")))
>      (native-search-paths
>       (list (search-path-specification
>              (variable "MANPATH")
> diff --git a/gnu/packages/patches/mandoc-support-zstd-compression.patch b/gnu/packages/patches/mandoc-support-zstd-compression.patch
> new file mode 100644
> index 0000000000..b8cbeb6782
> --- /dev/null
> +++ b/gnu/packages/patches/mandoc-support-zstd-compression.patch
> @@ -0,0 +1,58 @@
> +mandoc upstream does not support zstd compression. However, Guix uses zstd
> +compression for its man pages, therefore—without support for this compression
> +method—mandoc would be quite useless. Hence, this patchset uses zlibWrapper
> +from the zstd project to add zstd compression support to mandoc.

Interesting solution!  The issue should be ideally be brought upstream
though, and referenced here.  With the leading implementation man-db
having gained zstd support, others should follow suite.  They may be
interested in using your solution, or otherwise adding "native" support
for it.

Could you please create such an issue with them, cross-reference it in
your patch, and send a v2?

-- 
Thanks,
Maxim