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:
- The live image’s
system.sfsis compressed with zstd bymksquashfs, unlessKDOS_ISO_COMPselects xz (see The live medium and persistence). - A pack is an EROFS image compressed with zstd, and a pack delta is
zstd --patch-frombetween two packs (see Deltas). kpkg deltamakes a package delta withzstd --patch-fromover the uncompressed archives (see Deltas).
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
zstd-1.5.7.tar.gz(2.3 MiB)
sha256eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3
upstream: https://github.com/facebook/zstd/releases/download/v1.5.7/zstd-1.5.7.tar.gz
archive copy: sources-1/archiver--zstd-1.5.7.tar.gz
Dependencies
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:
${CFLAGS/-O2/-O3}— raise the exportedCFLAGSandCXXFLAGSto-O3. zstd’s makefiles default to-O3only whenCFLAGSis unset, and the tree always sets it. This is the “-O3for a hot port by pattern” case of Every port.-flto=auto— compile and link with link-time optimisation, added toLDFLAGSas well. zstd is one of the hot libraries the tree builds with LTO (see Every port, “LTO only for the hot libraries”).-ffat-lto-objects— keep ordinary machine code beside the LTO bytecode, so the shippedlibzstd.alinks with any linker, not only through GCC’s plugin.-frandom-seed=zstd— fix the seed GCC names each object’s.gnu.lto_*sections with, solibzstd.ais the same bytes on every build.ZSTD_LEGACY_SUPPORT=5— keep decoders for the pre-1.0 legacy formats from v0.5.0 on, sozstd -dand every program decompressing through the library still read such frames. This is the makefile’s default, named becauseZSTD_LEGACY_FILESmust agree with it.ZSTD_LEGACY_FILES— the legacy decoder sources to compile,lib/legacy/zstd_v05.ctozstd_v07.c, given as full paths. The makefile otherwise collects them by runninglsandgrepoverlib/legacy. The list must matchZSTD_LEGACY_SUPPORT: the library is compiled with-DZSTD_LEGACY_SUPPORT=5and calls the decoders of every version from there on.HAVE_PTHREAD=1— build the multithreaded compressor,zstd -T, without the makefile’s probe compile.HAVE_ZLIB=1,HAVE_LZMA=1,HAVE_LZ4=1— build the--format=gzip,--format=xz,--format=lzmaand--format=lz4support of thezstdcommand. Each skips the makefile’s probe, which compiles a test program and quietly drops the format when it fails. Set outright, a missing zlib, xz or lz4 is a link error instead of azstdthat reads fewer formats.
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 |