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

62.1. rust-1.98.1

The Rust compiler, with cargo, clippy, rustdoc and rustfmt

Version 1.98.1, release 2
Shelf lang — Language implementations, plus the modules of any language that has no module shelf of its own
Phase 31_compilers (Compilers), 4 of 22 in build order
Licence MIT OR Apache-2.0
Homepage https://www.rust-lang.org/
Build time 51.3 SBU
Installed size 767.8 MiB in 6917 files
Recipe ports/core/lang/rust/kpkgbuild

About

This port is the Rust compiler, rustc, with cargo, clippy, rustdoc and rustfmt. A large part of KDOS is built with it: command-line programs such as ripgrep, fd, bat and helix, the Mozilla browsers and Chromium, librsvg, mesa, linux, typst and the Python packages with Rust extensions all name it in depends. It is built in 31_compilers, the phase that holds the long compiler builds, so that a failure there restores 30_foundation and loses minutes, not the foundation work before it (see How KDOS is built).

KDOS builds Rust differently from upstream’s release in three ways. It links the system LLVM, the llvm port, instead of compiling the LLVM inside the source tarball. It links rustc and the standard library dynamically against musl, where the musl target’s default is static. And cargo links the system libgit2, libssh2, curl, OpenSSL and zlib rather than compiling the copies their -sys crates carry.

Rust is written in Rust, so the build starts from a released compiler: the previous stable rustc, rust-std and cargo for x86_64-unknown-linux-musl, the three extra sources in the recipe. They are the stage0 compiler that x.py starts from to compile this release.

Sources

Dependencies

Depends on: curl, cmake, python3, llvm, libssh2, libgit2, openssl, xz.

Required by (94): aardvark-dns, akonadi-search, angelfish, atuin, bandwhich, bat, bindgen, bottom, caligula, cargo-c, cbindgen, chess-tui, chromium, clamav, corrosion, crubit, cxx-rust-cssparser, ddnet, delta, difftastic, doxx, dust, espflash, eza, fd, firefox-esr, helix, hexyl, hurl, hyperfine, iamb, impression, inlyne, jujutsu, just, kdepim-addons, kdeplasma-addons, libdovi, libimagequant, librepcb, librewolf, librsvg, linux, lnav, mesa, mesa-opencl, mqttui, netavark, newsboat, nodejs, numbat, ouch, oxipng, pizauth, presenterm, probe-rs, procs, python3-bcrypt, python3-cryptography, python3-jellyfish, python3-maturin, python3-orjson, python3-pydantic-core, python3-rpds-py, python3-setuptools-rust, resources, resvg, ripgrep, ripgrep-all, rmpc, ruby, ruff, rust-analyzer, sd, sniffnet, starship, surfer, taskwarrior, taskwarrior-tui, tealdeer, termusic, thin-provisioning-tools, thunderbird, tokei, tree-sitter, trippy, ttyper, typst, virtiofsd, waypipe, wiremix, xh, yazi, zoxide.

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/31_compilers/phase.env && kpkg install rust'

What kpkg does

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

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/lang/rust
echo 'be1816e7f6c40abb90245ad6e024bed2a7e88d7dda4561e4d5470207df616b9f  rust-1.98.1.tar.xz' | sha256sum -c -
echo '623a1315bdbddc5e7a807aaf7e1911d1435a294758e170b8758f49fc57a3e67c  cargo-1.97.1-x86_64-unknown-linux-musl.tar.xz' | sha256sum -c -
echo '51d83178680556f73a5fa8ad865b76a1ff541867445c00fc65dc67246bc2de66  rust-std-1.97.1-x86_64-unknown-linux-musl.tar.xz' | sha256sum -c -
echo '1b1f926d3b5bf8036c858180dbc9518c6c317154718ee5c5460bb23d23bacf5d  rustc-1.97.1-x86_64-unknown-linux-musl.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/rust
SRC=$SRC_ROOT/rust-1.98.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf rust-1.98.1.tar.xz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf rust-std-1.97.1-x86_64-unknown-linux-musl.tar.xz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf rustc-1.97.1-x86_64-unknown-linux-musl.tar.xz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf cargo-1.97.1-x86_64-unknown-linux-musl.tar.xz -C "$SRC_ROOT"

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 recipe’s helpers _date, _rust, _cargo, _triplet, watch and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

patch -p1 -i $PORT_SRC/rust-llvm23-amx-tf32.patch
patch -p1 -i $PORT_SRC/rust-llvm23-assign-guid.patch

mkdir -p build/cache/$_date
cp $PORT_SRC/rust-std-$_rust-$_triplet.tar.xz build/cache/$_date/
cp $PORT_SRC/rustc-$_rust-$_triplet.tar.xz build/cache/$_date/
cp $PORT_SRC/cargo-$_cargo-$_triplet.tar.xz build/cache/$_date/

cat << EOF > config.toml
[llvm]
targets = "X86"
link-shared = true

[build]
docs = false
extended = true
locked-deps = true
vendor = true
python = "/usr/bin/python3"
tools = ["cargo", "clippy", "rustdoc", "rustfmt", "src", "rust-analyzer-proc-macro-srv"]
description = "kdos"
profiler = true

[install]
prefix = "/usr"

[rust]
channel = "stable"
jemalloc = true
codegen-units-std = 1
rustflags = ["-Cstrip=debuginfo"]

[target.$_triplet]
llvm-config = "/usr/bin/llvm-config"
llvm-filecheck = "/usr/lib/llvm/utils/FileCheck"
crt-static = false
EOF

mkdir "$SRC/rust"
export CARGO_HOME="$SRC/rust"
export RUST_BACKTRACE=1

export LIBSSH2_SYS_USE_PKG_CONFIG=1
export LIBGIT2_NO_VENDOR=1

python3 ./x.py build --jobs "$KDOS_JOBS"
DESTDIR=$PKG python3 ./x.py install -v --jobs "$KDOS_JOBS"

python3 ./x.py dist rustc-dev --jobs "$KDOS_JOBS"
mkdir "$SRC/rustc-dev"
tar -xf build/dist/rustc-dev-$version-$_triplet.tar.xz -C "$SRC/rustc-dev" --strip-components=1
"$SRC/rustc-dev/install.sh" --prefix=/usr --destdir="$PKG" --disable-ldconfig
for f in "$PKG"/usr/lib/rustlib/$_triplet/lib/*.so; do
	[ -e "$PKG/usr/lib/${f##*/}" ] || continue
	ln -sf "../../../${f##*/}" "$f"
done

rm -f "$PKG"/usr/lib/rustlib/{components,install.log,rust-installer-version,uninstall.sh} \
	"$PKG"/usr/lib/rustlib/manifest-*

install -d "$PKG/usr/share/bash-completion/completions"
mv "$PKG/etc/bash_completion.d/cargo" "$PKG/usr/share/bash-completion/completions/cargo"
rmdir "$PKG/etc/bash_completion.d"

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/rust, 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 rust-1.98.1-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/rust, and runs the triggers its paths call for.

Contents

Installed programs: cargo, cargo-clippy, cargo-fmt, clippy-driver, rust-gdb, rust-gdbgui, rust-lldb, rustc, rustdoc, rustfmt.

Installed libraries: librustc_driver-9a4c673f3cd4e306.so.

Installed directories: /usr/lib/rustlib, /usr/share/doc/cargo, /usr/share/doc/clippy, /usr/share/doc/rustc, /usr/share/doc/rustfmt, /usr/share/licenses/rust.

Short descriptions

cargo The Rust package manager
rustc The Rust compiler
rustdoc generate documentation from Rust source code

Notes

The stage0 tarballs are copied into build/cache/<date>/, where x.py looks before it downloads anything. The recipe’s _date and _rust must be the compiler_date and compiler_version that src/stage0 in the new source names; when they differ, x.py looks for a directory that is not there, tries the network, and the build fails in the chroot. After a version bump, read src/stage0 and set both.

rustc-dev is the compiler’s own crates (rustc_driver, rustc_middle and the rest) as .rmeta files under lib/rustlib/x86_64-unknown-linux-musl/lib. x.py install installs it only when tools names it, and the list above does not. A tool built against rustc’s internals with #![feature(rustc_private)] links them; crubit, which Chromium needs, is one. build.sh makes the rustc-dev dist tarball with x.py dist rustc-dev and runs the tarball’s own install.sh into the package. That tarball carries its own copies of the compiler’s shared libraries; each one /usr/lib already holds is replaced with a symbolic link to it, so the two can never differ.

The rest of build.sh tidies the install: it deletes the installer’s bookkeeping in lib/rustlib (components, install.log, manifest-*, uninstall.sh, rust-installer-version), which describes an installation kpkg already tracks, and moves cargo’s bash completion from /etc/bash_completion.d to /usr/share/bash-completion/completions, where bash-completion loads it on demand.

Both patches adapt rustc to LLVM 23, the series the llvm port carries, which is newer than the LLVM this Rust release is built against. The header of rust-llvm23-assign-guid.patch says only that it reapplies an upstream commit; what it does is add LLVM’s AssignGUIDPass ahead of the two places rustc writes ThinLTO bitcode, when built against LLVM 23 or later. That LLVM assigns the global identifiers ThinLTO’s summaries are keyed on only when the pass pipeline asks for them.