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

67.8. tree-sitter-0.27.0

The parser library and CLI — grammars compiled here, never fetched

Version 0.27.0, release 1
Shelf devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities
Phase 40_lang (Languages), 16 of 186 in build order
Licence MIT
Homepage https://tree-sitter.github.io/
Build time 4.9 SBU
Installed size 12.6 MiB in 8 files
Recipe ports/core/devtools/tree-sitter/kpkgbuild

About

tree-sitter is a parser generator and an incremental parsing library. The port installs two things: the tree-sitter command, which generates a grammar’s C parser from its grammar.js and compiles it, and libtree-sitter, the C runtime every generated parser runs against, with its header and tree-sitter.pc. lldb names it in depends for its tree-sitter syntax highlighting (LLDB_ENABLE_TREESITTER). neovim does not: it builds its own copy of the library from a tree-sitter release its recipe pins.

The command is also there for working offline. An editor plugin that downloads and compiles a grammar the first time a file of that language is opened cannot do so with no network; with the CLI installed, a grammar’s source can be compiled locally instead.

Why it is in KDOS

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

nvim-treesitter and Helix download and compile a grammar on FIRST USE, which offline is a permanently broken feature that looks like a config bug.

Sources

Dependencies

Depends on: rust, clang.

Required by (1): lldb.

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 tree-sitter'

What kpkg does

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

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/tree-sitter
echo 'd35c96e68736bd9569d2757c3cc71052485f33082c3825f1aed9d0e86013a159  tree-sitter-0.27.0.tar.gz' | sha256sum -c -
echo '679d34ad857e312e0454eedbe1effecd7606b1c8b75f80b003462e709a3e8ad5  tree-sitter-vendor-0.27.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/tree-sitter
SRC=$SRC_ROOT/tree-sitter-0.27.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf tree-sitter-0.27.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"
export LIBCLANG_PATH=/usr/lib

cargo build --release --frozen --offline
install -Dm755 target/release/tree-sitter $PKG/usr/bin/tree-sitter

export CFLAGS="${CFLAGS/-O2/-O3}"
make PREFIX=/usr LIBDIR=/usr/lib
make PREFIX=/usr LIBDIR=/usr/lib 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/tree-sitter, 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 tree-sitter-0.27.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/tree-sitter, and runs the triggers its paths call for.

Contents

Installed programs: tree-sitter.

Installed libraries: libtree-sitter.a, libtree-sitter.so.

Installed directories: /usr/include/tree_sitter, /usr/share/licenses/tree-sitter.

Short descriptions

tree-sitter.pc An incremental parsing system for programming tools

Notes

The CLI and the library come from two build systems in one tree: cargo build makes the tree-sitter binary, and the top-level Makefile, not one in lib/, builds and installs libtree-sitter.so and libtree-sitter.a from the sources under lib/src. Both come from the same release, so a parser the CLI generates declares an ABI version this library accepts.