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

40.3. libffi-3.8.0

Portable foreign function interface library

Version 3.8.0, release 1
Shelf base-libs — Low-level C libraries that the base system links
Phase 30_foundation (Build Foundation), 29 of 127 in build order
Licence MIT
Homepage https://sourceware.org/libffi/
Build time 0.1 SBU
Installed size 288.8 KiB in 14 files
Recipe ports/core/base-libs/libffi/kpkgbuild

About

libffi lets a program call a C function whose argument types it learns only at run time, and create a C function pointer, a closure, that calls back into it. Interpreters and binding layers use it to reach C libraries: python3 (its ctypes module), glib, gobject-introspection, wayland, and the runtimes of Ruby, Guile, Node.js and GHC all link it. It is built early in 30_foundation, in the phase’s first run, which installs the build tools one at a time before anything else, because python3 is one of those tools and depends on it.

Sources

Dependencies

Depends on: nothing a recipe names.

Required by (21): chromium, firefox-esr, ghc, glib, glib-introspection, gobject-introspection, guile, librewolf, llvm, llvm21, nodejs, p11-kit, pandoc, python3, python3-cffi, python3-gobject, ruby, shellcheck, thunderbird, wayland, yosys.

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

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base-libs/libffi.

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/base-libs/libffi
echo '7da3e2d9a171eb0a038f592ecad3ff2bb2550f3496d87b3b29ad0cf4430c0db4  libffi-3.8.0.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/libffi
SRC=$SRC_ROOT/libffi-3.8.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libffi-3.8.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:

./configure \
	--prefix=/usr \
	--disable-multi-os-directory \
	--enable-exec-static-tramp \
	--enable-portable-binary
make
make 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/libffi, 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 libffi-3.8.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/libffi, and runs the triggers its paths call for.

Contents

Installed libraries: libffi.a, libffi.so.

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

Short descriptions

libffi.pc Library supporting Foreign Function Interfaces