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

165.1. onnxruntime-1.30.0

ONNX Runtime: inference for ONNX models on the CPU, as a C/C++ library and a Python module

Version 1.30.0, release 2
Shelf ai — Machine learning inference, speech recognition, computer vision and neural translation
Phase 41_system (System), 56 of 1047 in build order
Licence MIT
Homepage https://onnxruntime.ai/
Build time 31.6 SBU
Installed size 64.4 MiB in 658 files
Recipe ports/core/ai/onnxruntime/kpkgbuild

About

ONNX Runtime runs neural-network models saved in the ONNX format. This port builds its CPU execution provider only, as the C and C++ library libonnxruntime and the Python module onnxruntime. The Python module is what piper, the text-to-speech engine, imports to run its voice models; it is built against numpy.

Every third-party library ONNX Runtime uses is compiled into libonnxruntime at the version this release pins: abseil, protobuf, re2, flatbuffers, Eigen, the ONNX definitions and the rest. The installed library needs nothing but the C and C++ runtime libraries. Each of those sources is a further source = line of the recipe, named ort-, the dependency’s name in cmake/deps.txt, a hyphen, and the file name of its URL.

Sources

Dependencies

Depends on: cmake, ninja, patch, python3, numpy, python3-setuptools, python3-wheel, python3-packaging, python3-pip, zlib.

Required by (1): piper.

Patches

build.sh applies these; kpkg applies nothing by itself.

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

What kpkg does

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

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/ai/onnxruntime
echo 'f6681ecbddf53898adf0cc9e8e9e84657485b84d2eca3c8aa353de6d7dd417ef  onnxruntime-1.30.0.tar.gz' | sha256sum -c -
echo 'b2bdcf6682d8cb53df365bcc5d6c318a22e55821d9978a10fdb61404c026daff  ort-abseil_cpp-20250814.0.zip' | sha256sum -c -
echo 'f4300b96f7a304d4ef9bf6e0fa3ded72159f7f2d0f605bdde3e030a0dba7cf9f  ort-date-v3.0.1.zip' | sha256sum -c -
echo '14e8b3f03ab7461f56b3fa7ffd4acfb6e6a65f895dc4b50548cab259229afcbd  ort-dlpack-5c210da409e7f1e51ddf445134a4376fdbd70d7d.zip' | sha256sum -c -
echo '6a60d76351f97132669daeeb721d6bf14b008101883ad2d687a3201c5c461eb0  ort-eigen-eigen-1d8b82b0740839c0de7f1242a3585e3390ff5f33.zip' | sha256sum -c -
echo '57bd580c0772fd1a726c34ab8bf05325293bc5f9c165060a898afa1feeeb95e1  ort-flatbuffers-v23.5.26.zip' | sha256sum -c -
echo '04022b05d806eb5ff73023c280b68697d12b93e1b7267a0b22a1a39ec7578069  ort-json-v3.11.3.zip' | sha256sum -c -
echo 'c9291d95f5f6e5c561990d06a589b01d89e553d0f366f0ce723dd1788e7a6076  ort-microsoft_gsl-v4.2.1.zip' | sha256sum -c -
echo '81431bdc44c439a324e02c07ed067f8f556419fd86f2d8b486ff568df6aac899  ort-mp11-boost-1.82.0.zip' | sha256sum -c -
echo '8dc1181d33529a1249e031226126d0699ac9bdfc571ee530ee3a12f4656f2be3  ort-onnx-v1.22.0.zip' | sha256sum -c -
echo '16498d7dc7967e9b100632138babd4b86b61592beeccdd556f67539d9c231355  ort-protobuf-protobuf-33.6.tar.gz' | sha256sum -c -
echo 'e3754d16ea536bdc968ce1464fa822e198a1217881d31bd9bf3d287fed2bbf4c  ort-pybind11-v3.0.2.zip' | sha256sum -c -
echo 'b93044263ee072e9be3577bda52f48d5a4dd9fcb80091529471c8d2bfe59219d  ort-pytorch_cpuinfo-66ee79c038d70dad9f08705b2c9b3e58f6d8f512.zip' | sha256sum -c -
echo 'a835fe55fbdcd8e80f38584ab22d0840662c67f2feb36bd679402da9641dc71e  ort-re2-2024-07-02.zip' | sha256sum -c -
echo '3ffbd9a2fdff45da77da3e7269e9aa512ea43bed5c38ce8fd8f3d1068a032c3f  ort-safeint-3.0.28.zip' | 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/onnxruntime
SRC=$SRC_ROOT/onnxruntime-1.30.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf onnxruntime-1.30.0.tar.gz -C "$SRC" --strip-components=1
cp ort-abseil_cpp-20250814.0.zip "$SRC"
cp ort-re2-2024-07-02.zip "$SRC"
tar --no-same-permissions --warning=no-unknown-keyword -xf ort-protobuf-protobuf-33.6.tar.gz -C "$SRC_ROOT"
cp ort-date-v3.0.1.zip "$SRC"
cp ort-mp11-boost-1.82.0.zip "$SRC"
cp ort-json-v3.11.3.zip "$SRC"
cp ort-pytorch_cpuinfo-66ee79c038d70dad9f08705b2c9b3e58f6d8f512.zip "$SRC"
cp ort-microsoft_gsl-v4.2.1.zip "$SRC"
cp ort-safeint-3.0.28.zip "$SRC"
cp ort-flatbuffers-v23.5.26.zip "$SRC"
cp ort-onnx-v1.22.0.zip "$SRC"
cp ort-eigen-eigen-1d8b82b0740839c0de7f1242a3585e3390ff5f33.zip "$SRC"
cp ort-pybind11-v3.0.2.zip "$SRC"
cp ort-dlpack-5c210da409e7f1e51ddf445134a4376fdbd70d7d.zip "$SRC"

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:

patch -p1 -i "$PORT_SRC/gcc16-cstdint.patch"

export ASMFLAGS="-Wa,--noexecstack" LDFLAGS="$LDFLAGS -Wl,-z,noexecstack"

_mirror="$SRC/mirror"
for s in $source; do
	case $s in ort-*::https://*) ;; *) continue ;; esac
	f=${s%%::*}
	u=${s#*::https://}
	for d in "$SRC" "$PORT_SRC" "$SOURCE_DIR"; do
		[ -f "$d/$f" ] && break
	done
	[ -f "$d/$f" ] || { echo "onnxruntime: $f is missing" >&2; exit 1; }
	mkdir -p "$_mirror/${u%/*}"
	ln -sf "$d/$f" "$_mirror/$u"
done

cmake -S cmake -B build -G Ninja \
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DPython_EXECUTABLE=/usr/bin/python3 \
	-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=NEVER \
	-Donnxruntime_CMAKE_DEPS_MIRROR_DIR="$_mirror" \
	-Donnxruntime_BUILD_SHARED_LIB=ON \
	-Donnxruntime_BUILD_UNIT_TESTS=OFF \
	-Donnxruntime_BUILD_BENCHMARKS=OFF \
	-Donnxruntime_ENABLE_PYTHON=ON \
	-Donnxruntime_USE_TELEMETRY=OFF \
	-Donnxruntime_ENABLE_LTO=OFF \
	-Donnxruntime_BUILD_FOR_NATIVE_MACHINE=OFF \
	-Donnxruntime_USE_XNNPACK=OFF \
	-Donnxruntime_USE_MIMALLOC=OFF \
	-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build

cd build
python3 ../setup.py bdist_wheel --dist-dir="$SRC_ROOT/ort-dist"
pip3 install --ignore-installed --no-deps --no-index --no-build-isolation \
	--root="$PKG" --prefix=/usr "$SRC_ROOT"/ort-dist/onnxruntime-*.whl
_capi=$(echo "$PKG"/usr/lib/python3*/site-packages/onnxruntime/capi)
[ -f "$_capi/onnxruntime_pybind11_state.so" ] ||
	{ echo "onnxruntime: the Python module was not installed" >&2; exit 1; }
if readelf -lW "$_capi/onnxruntime_pybind11_state.so" | grep GNU_STACK | grep -q RWE; then
	echo "onnxruntime: the Python module asks for an executable stack" >&2
	exit 1
fi
for lib in "$_capi"/libonnxruntime*.so*; do
	[ -f "$lib" ] || continue
	b=${lib##*/}
	[ -e "$PKG/usr/lib/$b" ] && ln -sf "../../../../$b" "$lib"
done

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/onnxruntime, 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 onnxruntime-1.30.0-2.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/onnxruntime, and runs the triggers its paths call for.

Contents

Installed programs: onnxruntime_test.

Installed libraries: libonnxruntime.so, libonnxruntime_providers_shared.so.

Installed directories: /usr/include/onnxruntime, /usr/lib/cmake/onnxruntime, /usr/lib/python3.14/site-packages/onnxruntime, /usr/lib/python3.14/site-packages/onnxruntime-1.30.0.dist-info, /usr/share/licenses/onnxruntime.

Short descriptions

libonnxruntime.pc ONNX runtime

Notes

patch is in depends because CMake applies upstream’s patches from cmake/patches to several fetched dependencies, protobuf, GSL and flatbuffers among them, with patch.

The mirror loop in build.sh looks for each ort-* file in $SRC, $PORT_SRC and $SOURCE_DIR, in that order, and stops the build naming the first one that is in none of them. The case that picks the files reads the recipe’s source lines, so a dependency added to the recipe needs no change to build.sh, but its name must keep the ort- prefix.

The Python module is built as a wheel by setup.py, run from the build directory, where the module and the two shared libraries were built, and installed with pip3. The wheel carries its own copies of libonnxruntime.so.<version> and libonnxruntime_providers_shared.so; build.sh replaces each with a link to the file already installed in /usr/lib, so the package holds one copy of each library.