155.9. numbat-1.24.0
Calculator with physical units and dimension checking
| Version | 1.24.0, release 1 |
| Shelf | math — Mathematics applications and libraries: computer algebra, arbitrary precision, solvers, calculators, statistics and plotting apps |
| Phase | 41_system (System), 744 of 1047 in build order |
| Licence | MIT OR Apache-2.0 |
| Homepage | https://numbat.dev/ |
| Build time | 4.0 SBU |
| Installed size | 5.6 MiB in 66 files |
| Recipe | ports/core/math/numbat/kpkgbuild |
About
numbat is a calculator whose type system knows physical units: it adds a length to a length, converts metres per second to kilometres per hour, and refuses to add a voltage to a resistance, which bc does without complaint. It is an interactive shell and a one-shot command (numbat -e '...'). The recipe writes a terminal desktop entry for it, named Numbat; the plain name Calculator would put it ahead of KCalc and Kalk for anyone typing “calc”.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/math.txt:
bcwill add a voltage to a resistance. On a bench the arithmetic mistake that actually happens is a unit one.
Sources
numbat-1.24.0.tar.gz(841.3 KiB)
sha25603c84d1d30bce73f2fcbfa79c8df51e580293918fef9c35966b158eaae234a08
upstream: https://github.com/sharkdp/numbat/archive/refs/tags/v1.24.0.tar.gz
archive copy: sources-3/math--numbat-1.24.0.tar.gznumbat-vendor-1.24.0.tar.xz(18.1 MiB)
sha2563c0926424c97b28bb8ddfa82b40d8f41dc3823b65b419698db14aaa9c1308805
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-3/math--numbat-vendor-1.24.0.tar.xz
Dependencies
Depends on: rust.
Required by: no port names it.
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/41_system/phase.env && kpkg install numbat'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/math/numbat.
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/math/numbat
echo '03c84d1d30bce73f2fcbfa79c8df51e580293918fef9c35966b158eaae234a08 numbat-1.24.0.tar.gz' | sha256sum -c -
echo '3c0926424c97b28bb8ddfa82b40d8f41dc3823b65b419698db14aaa9c1308805 numbat-vendor-1.24.0.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/numbat
SRC=$SRC_ROOT/numbat-1.24.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf numbat-1.24.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:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export RUSTFLAGS="-C target-feature=-crt-static"
cargo build --release --frozen --offline --bin numbat
install -Dm755 target/release/numbat $PKG/usr/bin/numbat
install -dm755 $PKG/usr/share/numbat
cp -a numbat/modules $PKG/usr/share/numbat/modules
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/numbat.desktop" <<'EOF'
[Desktop Entry]
Type=Application
Name=Numbat
GenericName=Unit Calculator
Comment=Arithmetic that knows its units
Exec=numbat
Icon=accessories-calculator
Terminal=true
Categories=Utility;Calculator;
Keywords=calculator;units;convert;maths;numbat;
EOF
chmod 644 "$PKG/usr/share/applications/numbat.desktop"
The switches, and why each is set:
-C target-feature=-crt-static— link the program against musl dynamically. Rust’s musl target links statically unless told otherwise; every cargo build in the tree sets the flag, and preflight fails one that does not (see rust).--bin numbat— Build only thenumbatprogram from the workspace, whose other members are the language library and the exchange-rate crate it links.
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/numbat, 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 numbat-1.24.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/numbat, and runs the triggers its paths call for.
Contents
Installed programs: numbat.
Installed directories: /usr/share/licenses/numbat, /usr/share/numbat.
Notes
The crates come from the vendor bundle, numbat-vendor-<version>.tar.xz, pinned with its own sha256 = line and unpacked at the top of the tree; cargo builds --frozen --offline from it (see Vendoring).
The unit, constant and function definitions are Numbat source files, the modules tree. The library compiles a copy into the binary, and the program also looks for modules on disk: NUMBAT_MODULES_PATH, then ~/.config/numbat/modules, then /usr/share/numbat/modules, which build.sh fills from the same release. A module found on disk is used ahead of the compiled-in copy, so the installed tree and the binary must come from the same version.
The default features are built, so numbat fetches the European Central Bank’s daily exchange rates over the network: the interactive shell starts the download in the background when it opens, and a one-shot command fetches when a calculation first uses a currency. fetching-policy under [exchange-rates] in ~/.config/numbat/config.toml changes that, and never turns it off. Upstream’s release profile sets strip = true, so cargo builds the binary without its symbol table.