Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

50.4. zstd-1.5.7

Zstandard compression library and tools

Version 1.5.7, release 1
Shelf archiver — Compression libraries and archive tools
Phase 30_foundation (Build Foundation), 5 of 127 in build order
Licence BSD-3-Clause OR GPL-2.0-only
Homepage https://facebook.github.io/zstd/
Build time 0.7 SBU
Installed size 7.0 MiB in 21 files
Recipe ports/core/archiver/zstd/kpkgbuild

About

Zstandard is a compression format whose levels run from very fast to very tight: the library libzstd, the zstd, unzstd, zstdcat and zstdmt commands, and the zstdgrep and zstdless scripts. KDOS uses it in several of its own mechanisms:

It builds in 30_foundation, after zlib, xz and lz4, whose formats its command also reads and writes. It does not exist in 20_selfhost, which is why binutils and gcc are built --without-zstd.

The build is upstream’s plain makefiles, with no configure step; every setting is a make variable, collected in the zstd_vars array and passed to both make lines.

Sources

Dependencies

Depends on: zlib, xz, lz4.

Required by (105): amiberry, android-tools, appstream, atuin, bindgen, binutils-arm-none-eabi, binutils-avr, binutils-riscv64-unknown-elf, blender, boost, bpftool, bpftrace, btrfs-progs, c-blosc, ccache, chromium, curl, diamond, doxx, elfutils, erofs-utils, fcitx5, file, firmware-amd, firmware-broadcom, firmware-intel, firmware-map, firmware-mediatek, firmware-misc, firmware-nvidia, firmware-qualcomm, firmware-realtek, freeciv, gcc-arm-none-eabi, gcc-avr, gcc-riscv64-unknown-elf, gdal, gdb, gnutls, graphicsmagick, imagemagick, imhex, ispc, karchive, kbd, kdos-pack, kdos-tools, kicad, kmod, labplot, libarchive, libime, libreoffice, libsoup3, libstdcxx-arm-none-eabi, libstdcxx-riscv64-unknown-elf, libtiff, libxmlb, libzim, libzip, linux, lld, lld21, llvm, llvm21, luanti, lynx, mednafen, mesa, mesa-opencl, minizip-ng, nbdkit, ncdu, netcdf-c, nodejs, ocaml, openexr, openrct2, ouch, partclone, pdal, perf, plocate, postgresql, ppsspp, python3, python3-zstandard, qemu, qgis, qt-creator, qt5-qtbase, qt6-qtbase, R, ripgrep-all, rizin, rsync, satdump, schismtracker, sdrpp, squashfs-tools, surfer, waypipe, weechat, wireshark, zig.

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/30_foundation/phase.env && kpkg install zstd'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/archiver/zstd.

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/archiver/zstd
echo 'eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3  zstd-1.5.7.tar.gz' | 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/zstd
SRC=$SRC_ROOT/zstd-1.5.7
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf zstd-1.5.7.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:

lto="-flto=auto -ffat-lto-objects -frandom-seed=zstd"
export CFLAGS="${CFLAGS/-O2/-O3} $lto" CXXFLAGS="${CXXFLAGS/-O2/-O3} $lto"
export LDFLAGS="$LDFLAGS -flto=auto"

legacy=("$PWD"/lib/legacy/zstd_v0[5-7].c)
zstd_vars=(
	ZSTD_LEGACY_SUPPORT=5
	ZSTD_LEGACY_FILES="${legacy[*]}"
	HAVE_PTHREAD=1
	HAVE_ZLIB=1
	HAVE_LZMA=1
	HAVE_LZ4=1
)

make "${zstd_vars[@]}"
make "${zstd_vars[@]}" PREFIX=/usr DESTDIR=$PKG install

The switches, and why each is set:

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/zstd, 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 zstd-1.5.7-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/zstd, and runs the triggers its paths call for.

Contents

Installed programs: unzstd, zstd, zstdcat, zstdgrep, zstdless, zstdmt.

Installed libraries: libzstd.a, libzstd.so.

Installed directories: /usr/share/licenses/zstd.

Short descriptions

zstd zstd, zstdmt, unzstd, zstdcat - Compress or decompress zst files
zstdgrep print lines matching a pattern in zstandard-compressed files
zstdless view zstandard-compressed files
libzstd.pc fast lossless compression algorithm library