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
cargo-c-0.10.25.tar.gz(40.5 KiB)
sha2568054b12ae8b64259e7b63e40368406dd6b6510d5d92b658152b361c5d816a5de
upstream: https://github.com/lu-zero/cargo-c/archive/refs/tags/v0.10.25.tar.gz
archive copy: sources-1/buildtools--cargo-c-0.10.25.tar.gzcargo-c-vendor-0.10.25.tar.xz(33.1 MiB)
sha2564a3c7939bd6288aca5487986794ff672fed05a651ad85ded19a6c7ff0fec55ab
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/buildtools--cargo-c-vendor-0.10.25.tar.xz
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:
LIBSSH2_SYS_USE_PKG_CONFIG=1— makes thelibssh2-syscrate look for the system libssh2 through pkg-config; without it the crate compiles the copy of libssh2 it carries.LIBGIT2_NO_VENDOR=1— makeslibgit2-syslink the system libgit2, and fail if it is missing, instead of compiling its bundled copy.script/env/chroot.envexports this for every phase from40_langon; cargo-c is built in31_compilers, so the recipe exports it itself (see Writing ports).-C target-feature=-crt-static— link the four programs dynamically against musl’slibc.soand the system libraries; the musl target links statically unless told otherwise (see Writing ports).--root=$PKG/usr— wherecargo installputs what it installs: the four programs go to$PKG/usr/bin.
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.