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

60.4. cbindgen-0.29.4

A project for generating C bindings from Rust code

Version 0.29.4, release 1
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 31_compilers (Compilers), 5 of 22 in build order
Licence MPL-2.0
Homepage https://github.com/mozilla/cbindgen
Build time 3.1 SBU
Installed size 6.3 MiB in 2 files
Recipe ports/core/toolchain/cbindgen/kpkgbuild

About

cbindgen goes the other way from bindgen: it reads Rust source and writes the C and C++ headers through which C code calls a Rust library. It is a build tool for the ports that mix the two languages: firefox-esr, librewolf and thunderbird generate their headers for Gecko’s Rust components with it, and mesa and mesa-opencl for their Rust code.

It is a Rust program, built with cargo from its vendor bundle, the second sha256 = line. The bundle carries the crates under vendor/, the Cargo.lock they were resolved from and a .cargo/config.toml that points cargo’s crates.io source at vendor/, so --frozen --offline builds it with no network (see Vendoring).

Sources

Dependencies

Depends on: rust.

Required by (5): firefox-esr, librewolf, mesa, mesa-opencl, thunderbird.

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 cbindgen'

What kpkg does

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

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/toolchain/cbindgen
echo '9b5757e915cf8be523d3aca282b9b5651bafa112e14bf1ba488562ba282807d6  cbindgen-0.29.4.tar.gz' | sha256sum -c -
echo 'defee865928897fc8850fd964869e1ed1f6976199bd0a3569a94f8ac8eb07c6d  cbindgen-vendor-0.29.4.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/cbindgen
SRC=$SRC_ROOT/cbindgen-0.29.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf cbindgen-0.29.4.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/cbindgen $PKG/usr/bin/cbindgen

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

Contents

Installed programs: cbindgen.

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