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

67.14. difftastic-0.71.0

Syntax-aware structural diff

Version 0.71.0, release 1
Shelf devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities
Phase 40_lang (Languages), 22 of 186 in build order
Licence MIT
Homepage https://difftastic.wilfred.me.uk/
Build time 8.2 SBU
Installed size 112.1 MiB in 3 files
Recipe ports/core/devtools/difftastic/kpkgbuild

About

difftastic (difft) is a structural diff: it parses both versions of a file with a tree-sitter grammar for its language and compares the syntax trees, so a reindented block or a moved line break is not reported as a change. It can stand in for git diff’s output through GIT_EXTERNAL_DIFF or diff.external.

Every grammar is compiled into the binary at build time, from the tree-sitter-* crates in the vendor bundle and the vendored_parsers directory of upstream’s source, so syntax-aware diffs work with no grammar downloaded.

Why it is in KDOS

The comment above it in script/phases/40_lang/packages.d/devtools.txt:

Every tree-sitter consumer in an editor downloads and compiles a grammar on first use; difftastic links ~50 of them in at build time, so a syntax-aware diff works on a machine that has never had a network.

Sources

Dependencies

Depends on: rust.

Required by: no port names it.

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/40_lang/phase.env && kpkg install difftastic'

What kpkg does

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

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/devtools/difftastic
echo 'd6afd26103c6492a91307dc6779c7dd0ca4d4c85499f81d7dc53fdfa5107331d  difftastic-0.71.0.tar.gz' | sha256sum -c -
echo '08b4fbcb9c63261d68895142cb0ee5d14e84f29da24c16f1a2a70b8e179df02b  difftastic-vendor-0.71.0.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/difftastic
SRC=$SRC_ROOT/difftastic-0.71.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf difftastic-0.71.0.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

export RUSTFLAGS="-C target-feature=-crt-static"

cargo build --release --frozen --offline
install -Dm755 target/release/difft $PKG/usr/bin/difft
install -Dm644 difft.1 $PKG/usr/share/man/man1/difft.1

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

Contents

Installed programs: difft.

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

Short descriptions

difft a structural diff tool that understands syntax

Notes

The manual page, difft.1, is shipped rendered at the top of the source and installed as it is.