63.2. pandoc-3.11
Converts between markup formats — Markdown, HTML, LaTeX, DOCX, ODT, EPUB and more
| Version | 3.11, release 1 |
| Shelf | doctools — Documentation toolchains, man pages, markup converters and TeX typesetting |
| Phase | 31_compilers (Compilers), 22 of 22 in build order |
| Licence | GPL-2.0-or-later |
| Homepage | https://pandoc.org |
| Build time | 20.5 SBU |
| Installed size | 229.6 MiB in 7 files |
| Recipe | ports/core/doctools/pandoc/kpkgbuild |
About
pandoc converts between document formats: Markdown in its several dialects, HTML, LaTeX, DOCX, ODT, EPUB, man pages, typst and many more. KDOS needs it to build this book: the kdos-kfs port, which ships KDOS from Scratch, depends on it, and so does openjdk; ghostwriter runs it to preview and export Markdown, and ripgrep-all to search inside documents.
It is a Haskell program, built with the ghc and cabal-install ports of the same phase. The source is Hackage’s pandoc-cli package, which holds only the pandoc executable and its three manual pages; the converter itself is the pandoc library, and the Lua engine and the HTTP server are pandoc-lua-engine and pandoc-server. Those, and every other Haskell package they need, come from the vendor bundle pandoc-vendor-<version>.tar.xz, which build.sh serves to cabal as a local repository; see The Haskell bundle.
Sources
pandoc-3.11.tar.gz(102.1 KiB)
sha256a9f3fc8c64962c8778b379cc2238c7c554541e1e94fd36a210c3f92e1729e929
upstream: https://hackage.haskell.org/package/pandoc-cli-3.11/pandoc-cli-3.11.tar.gz
archive copy: sources-1/doctools--pandoc-3.11.tar.gzpandoc-vendor-3.11.tar.xz(33.7 MiB)
sha256478af84e39d210dedbee49b54beb891df4c24737ef2eb2298ba7664189c2204d
a vendor bundle, made byports/hackage-vendor, not an upstream file
archive copy: sources-1/doctools--pandoc-vendor-3.11.tar.xz
Dependencies
Depends on: ghc, cabal-install, zlib, gmp, libffi.
Required by (4): ghostwriter, kdos-kfs, openjdk, ripgrep-all.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/31_compilers/phase.env && kpkg install pandoc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/doctools/pandoc.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/doctools/pandoc
echo 'a9f3fc8c64962c8778b379cc2238c7c554541e1e94fd36a210c3f92e1729e929 pandoc-3.11.tar.gz' | sha256sum -c -
echo '478af84e39d210dedbee49b54beb891df4c24737ef2eb2298ba7664189c2204d pandoc-vendor-3.11.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/pandoc
SRC=$SRC_ROOT/pandoc-3.11
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf pandoc-3.11.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf "$PORT_SRC/$name-vendor-$version.tar.xz" -C "$SRC_ROOT"
cp "$SRC_ROOT/vendor/cabal.project.freeze" .
export CABAL_DIR="$SRC_ROOT/cabal"
mkdir -p "$CABAL_DIR"
printf 'repository hackage.haskell.org\n url: file+noindex://%s\n' "$SRC_ROOT/vendor" \
> "$CABAL_DIR/config"
cabal v2-install -j"$KDOS_JOBS" \
--flags="+lua +server" \
--constraint="pandoc +embed_data_files" \
--enable-split-sections \
--enable-executable-stripping \
--installdir="$PKG/usr/bin" --install-method=copy \
exe:pandoc
ln -s pandoc "$PKG/usr/bin/pandoc-server"
ln -s pandoc "$PKG/usr/bin/pandoc-lua"
install -Dm644 -t "$PKG/usr/share/man/man1" \
man/pandoc.1 man/pandoc-server.1 man/pandoc-lua.1
The switches, and why each is set:
--flags="+lua +server"— buildpandoc-cliwith the Lua engine (--lua-filter, custom readers and writers, thepandoc-luainterpreter) and the HTTP server (pandoc-server). Both are on by default inpandoc-cli.cabal; the Notes say why they are named.--constraint="pandoc +embed_data_files"— compile pandoc’s data files (templates, reference DOCX and ODT documents, abbreviation lists) into the executable. Without it the program reads them at run time from the cabal store of the build, a path under the build’s work directory that does not exist on an installed system, so every DOCX, ODT and EPUB conversion would fail.--enable-split-sections— compile every Haskell function into a section of its own, so the linker can drop the unused code of the many libraries pandoc links.--enable-executable-stripping— strip the installed executable, which also leaves out any debug information.--installdir="$PKG/usr/bin",--install-method=copy— install the builtpandocas a file in$PKG/usr/bin. cabal’s default is a symbolic link into its store, which is under the work directory and is deleted with it.-j"$KDOS_JOBS"— build that many Haskell packages at once, the tree’s job count.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/pandoc, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf pandoc-3.11-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/pandoc, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: cabal.project.freeze.
Contents
Installed programs: pandoc, pandoc-lua, pandoc-server.
Installed directories: /usr/share/licenses/pandoc.
Short descriptions
pandoc |
general markup converter |
pandoc-lua |
Lua interface to pandoc API |
pandoc-server |
web server exposing pandoc API |
Notes
The port directory carries cabal.project.freeze, a freeze pinned by hand, and the vendor bundle is built from it. An unpinned cabal freeze is free to turn flags off to reach a solution, and it settles on pandoc-cli -lua -server and pandoc -embed_data_files: a smaller program, and one whose document conversions fail once installed. The freeze pins those flags on, and the --flags and --constraint above repeat them, so a freeze that disagrees makes the offline solve fail instead of quietly building the smaller program. The freeze also pins the pandoc library to the release this recipe builds, so a version bump regenerates it first, in the new source, with the ghc and cabal the recipes name:
cabal freeze --constraint="pandoc-cli +lua +server" --constraint="pandoc +embed_data_files"
and then ports/fetch pandoc. Lua is the copy of Lua compiled into the lua Haskell package (-system-lua in the freeze), so filters see the Lua pandoc was written against whatever the system’s lua port is.
One binary is all three programs. pandoc-cli decides by the name it was started under: as pandoc-server it serves conversions over HTTP, and as pandoc-lua it is a Lua interpreter with the pandoc modules loaded. build.sh installs the two names as symbolic links to pandoc.