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

45.2. libgit2-1.9.7

Portable, linkable C implementation of the Git core methods

Version 1.9.7, release 1
Shelf vcs — Version control and diff/merge tools
Phase 30_foundation (Build Foundation), 124 of 127 in build order
Licence GPL-2.0-only WITH GCC-exception-2.0
Homepage https://libgit2.org/
Build time 0.3 SBU
Installed size 2.7 MiB in 102 files
Recipe ports/core/vcs/libgit2/kpkgbuild

About

libgit2 is Git’s core — repositories, objects, references, the index, fetch and push — as a C library with a stable API, written separately from Git itself. KDOS builds it in 30_foundation for the Rust toolchain: cargo, which the rust port builds in 31_compilers, and cargo-c link it through the git2 crate, as do Rust programs such as delta, eza and bat. Each of them would otherwise compile the copy of libgit2 that libgit2-sys carries. How a Rust port is made to take the system library is in Writing ports. kicad, horizon-eda and kup, whose bup: worker reads bup’s git object store, link it directly.

Only the shared library, its headers, libgit2.pc and the CMake package files are installed; the git2 command-line program upstream builds by default is left out.

Why it is in KDOS

The comment above it in script/phases/30_foundation/packages.txt:

libgit2 is linked by cargo and cargo-c in 31_compilers and by every Rust port's git2 crate, which would otherwise compile a bundled copy.

Sources

Dependencies

Depends on: cmake, ninja, pkgconf, openssl, libssh2, pcre2, zlib.

Required by (8): bat, cargo-c, delta, eza, horizon-eda, kicad, kup, rust.

Optional, off in KDOS

These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.

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

What kpkg does

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

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/vcs/libgit2
echo '1a4fbe7589e814777ae76b64734ad80f4ecad22cd33a22682a2aaea4ae5375e7  libgit2-1.9.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/libgit2
SRC=$SRC_ROOT/libgit2-1.9.7
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libgit2-1.9.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:

cmake -S . -B build -G Ninja \
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DBUILD_SHARED_LIBS=ON \
	-DBUILD_TESTS=OFF \
	-DBUILD_CLI=OFF \
	-DBUILD_EXAMPLES=OFF \
	-DUSE_HTTPS=OpenSSL \
	-DUSE_SHA1=CollisionDetection \
	-DUSE_SHA256=HTTPS \
	-DUSE_SSH=libssh2 \
	-DUSE_HTTP_PARSER=builtin \
	-DREGEX_BACKEND=pcre2 \
	-DUSE_BUNDLED_ZLIB=OFF \
	-DUSE_GSSAPI=OFF \
	-DUSE_NTLMCLIENT=ON \
	-DUSE_THREADS=ON \
	-DUSE_NSEC=ON \
	-DENABLE_REPRODUCIBLE_BUILDS=ON
cmake --build build
DESTDIR=$PKG cmake --install build

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

Contents

Installed libraries: libgit2.so.

Installed directories: /usr/include/git2, /usr/lib/cmake/libgit2, /usr/share/licenses/libgit2.

Short descriptions

libgit2.pc The git library, take 2