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

61.1. cargo-c-0.10.25

Cargo subcommand to build and install C-ABI-compatible dynamic and static libraries

Version 0.10.25, release 1
Shelf buildtools — Build systems and build helpers
Phase 31_compilers (Compilers), 13 of 22 in build order
Licence MIT
Homepage https://github.com/lu-zero/cargo-c
Build time 9.6 SBU
Installed size 102.6 MiB in 5 files
Recipe ports/core/buildtools/cargo-c/kpkgbuild

About

cargo-c adds cargo cbuild, cargo cinstall, cargo ctest and cargo capi to cargo. They build a Rust crate that exports a C interface as a C library would be shipped: a versioned shared library, a static archive, a generated C header and a pkg-config file, installed under the usual paths. In KDOS the ports that use it are librsvg, libimagequant and libdovi, C libraries written in Rust that other C programs link.

cargo-c links cargo as a library, so like cargo itself it links libgit2, libssh2, libcurl and OpenSSL from their ports. The source is a vendor bundle of every crate it needs (cargo-c-vendor-<version>.tar.xz, vendoring = rust), so the build is offline; see Vendoring.

Sources

Dependencies

Depends on: rust, openssl, curl, zlib, libssh2, libgit2.

Required by (3): libdovi, libimagequant, librsvg.

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 cargo-c'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/buildtools/cargo-c.

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/buildtools/cargo-c
echo '8054b12ae8b64259e7b63e40368406dd6b6510d5d92b658152b361c5d816a5de  cargo-c-0.10.25.tar.gz' | sha256sum -c -
echo '4a3c7939bd6288aca5487986794ff672fed05a651ad85ded19a6c7ff0fec55ab  cargo-c-vendor-0.10.25.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/cargo-c
SRC=$SRC_ROOT/cargo-c-0.10.25
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf cargo-c-0.10.25.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 LIBSSH2_SYS_USE_PKG_CONFIG=1
export LIBGIT2_NO_VENDOR=1
export RUSTFLAGS="-C target-feature=-crt-static"
cargo install --frozen --offline --path . --root=$PKG/usr
rm -f $PKG/usr/.crates.toml
rm -f $PKG/usr/.crates2.json

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/cargo-c, 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 cargo-c-0.10.25-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/cargo-c, and runs the triggers its paths call for.

Contents

Installed programs: cargo-capi, cargo-cbuild, cargo-cinstall, cargo-ctest.

Installed directories: /usr/share/licenses/cargo-c.

Notes

cargo install also writes .crates.toml and .crates2.json into its root, its record of what it has installed there. build.sh deletes both, so the package holds the four programs and the licence file only.