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
libgit2-1.9.7.tar.gz(7.4 MiB)
sha2561a4fbe7589e814777ae76b64734ad80f4ecad22cd33a22682a2aaea4ae5375e7
upstream: https://github.com/libgit2/libgit2/archive/refs/tags/v1.9.7.tar.gz
archive copy: sources-4/vcs--libgit2-1.9.7.tar.gz
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.
-DUSE_GSSAPI=OFF, line 27: krb5 (explained with the switches below)
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:
-DBUILD_SHARED_LIBS=ON— buildlibgit2.sorather than a static archive; upstream’s default, stated.libgit2-sysandkicadlink this shared library.-DBUILD_TESTS=OFF,-DBUILD_CLI=OFF,-DBUILD_EXAMPLES=OFF— skip the test suite, thegit2command-line program and the example programs. The first two are on by default.-DUSE_HTTPS=OpenSSL— use OpenSSL for HTTPS, from theopensslport. The default picks a TLS library by itself.-DUSE_SHA1=CollisionDetection— compute SHA-1 with libgit2’s bundled SHA-1DC code, which detects the known collision attack on SHA-1 and refuses an object built with it, rather than with OpenSSL’s plain SHA-1. This is upstream’s default, stated.-DUSE_SHA256=HTTPS— take SHA-256 from the HTTPS library, here OpenSSL. Also the default.-DUSE_SSH=libssh2— supportssh://remotes through thelibssh2library. Off by default; the other provider,exec, runs thesshprogram instead.-DUSE_HTTP_PARSER=builtin— parse HTTP with the copy of llhttp indeps/llhttp. The other choices are a systemhttp-parserorllhttp, and neither is a port.-DREGEX_BACKEND=pcre2— use the system PCRE2 for regular expressions. Left unset, libgit2 takes the C library’sregcomp_l, which musl does not have, then a system PCRE (version 1, not a port), and otherwise compiles the PCRE2 copy it carries indeps/pcre2.-DUSE_BUNDLED_ZLIB=OFF— link the system zlib rather than the copy indeps/zlib.-DUSE_GSSAPI=OFF— no Kerberos (SPNEGO) authentication for HTTP. GSSAPI comes fromkrb5, which is built in41_system, well after this phase.-DUSE_NTLMCLIENT=ON— NTLM authentication for HTTP servers and proxies, through the ntlmclient code indeps/ntlmclient, which uses the HTTPS library’s cryptography. On by default whenever HTTPS is.-DUSE_THREADS=ON,-DUSE_NSEC=ON— thread support, and nanosecond file times in the index so a change within one second is still noticed. Both are defaults, stated.-DENABLE_REPRODUCIBLE_BUILDS=ON— runarandranlibin deterministic mode (D), so a static archive carries no timestamps or owner ids. This build makes no archive that reaches the package, so it changes nothing installed.
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 |