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

64.4. crubit-0.20260909

Crubit's cc_bindings_from_rs, which writes C++ headers for calling Rust crates, and its C++ support library

Version 0.20260909, release 1
Shelf toolchain — The native compilers, the linker, the C library, and the LLVM family
Phase 40_lang (Languages), 180 of 186 in build order
Licence Apache-2.0 WITH LLVM-exception
Homepage https://github.com/google/crubit
Build time 3.1 SBU
Installed size 8.1 MiB in 190 files
Recipe ports/core/toolchain/crubit/kpkgbuild

About

Crubit is Google’s tool set for calls between C++ and Rust. This port builds one program from it, cc_bindings_from_rs, which reads a compiled Rust crate and writes the C++ headers through which C++ code calls it, and installs the C++ support library those headers include, with Crubit’s GN rules and licence, under /usr/share/crubit. chromium is its one consumer: its build.sh links the program into third_party/rust-toolchain/bin and /usr/share/crubit into third_party/rust-toolchain/lib/third_party/crubit, the Rust toolchain directory Chromium’s build reads, beside rustc and cargo.

The source is a commit, not a release, and Crubit’s own build is Bazel. The cargo/ tree in it holds generated Cargo.toml files, so cargo can build the tool from its vendor bundle, the second sha256 = line. The bundle carries vendor/, Cargo.lock and .cargo/config.toml; it is unpacked at the top of the tree and cargo runs from there, which is where it finds that configuration (see Where the bundle goes).

Why it is in KDOS

The comment above crubit and musl-locales in script/phases/40_lang/packages.d/toolchain.txt:

Rust-to-C++ binding generator (cc_bindings_from_rs) and its support library: Chromium calls its Rust crates through the headers it writes.

Sources

Dependencies

Depends on: rust.

Required by (1): chromium.

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/40_lang/phase.env && kpkg install crubit'

What kpkg does

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

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/toolchain/crubit
echo 'a7d9149cdbe49a4ca49074d5b80ca3afd572bb5f7aa45b1eb15a5bd424ba292d  crubit-0.20260909.tar.gz' | sha256sum -c -
echo 'd11d5be1aaa19170061ba707c9e40b57aa1f7bb002572041236c9846274e6648  crubit-vendor-0.20260909.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/crubit
SRC=$SRC_ROOT/crubit-0.20260909
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf crubit-0.20260909.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 recipe’s helpers _commit 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"
export RUSTC_BOOTSTRAP=1
cargo build --release --frozen --offline --bin cc_bindings_from_rs \
	--manifest-path cargo/cc_bindings_from_rs/cc_bindings_from_rs/Cargo.toml
install -Dm755 target/release/cc_bindings_from_rs "$PKG/usr/bin/cc_bindings_from_rs"

install -d "$PKG/usr/share/crubit"
cp -r BUILD.gn LICENSE crubit.gni support "$PKG/usr/share/crubit/"

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

Contents

Installed programs: cc_bindings_from_rs.

Installed directories: /usr/share/crubit, /usr/share/licenses/crubit.

Notes

cc_bindings_from_rs runs only with the compiler library it was linked against: its NEEDED entries name librustc_driver-<hash>.so, whose hash identifies one build of the rust port. A new version of rust leaves the installed program unable to start until this port is rebuilt against it.

The commit in _commit has to be the CRUBIT_REVISION that Chromium’s tools/rust/update_rust.py names. The headers the tool writes include the support library installed beside it, and Chromium’s build is written against that revision of both, so a version change of the chromium port reads that line from the new release and moves _commit with it.