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
crubit-0.20260909.tar.gz(3.4 MiB)
sha256a7d9149cdbe49a4ca49074d5b80ca3afd572bb5f7aa45b1eb15a5bd424ba292d
upstream: https://github.com/google/crubit/archive/a355b02da81bc9f350925c73ec0322ce4d5140f1.tar.gz
archive copy: sources-4/toolchain--crubit-0.20260909.tar.gzcrubit-vendor-0.20260909.tar.xz(5.4 MiB)
sha256d11d5be1aaa19170061ba707c9e40b57aa1f7bb002572041236c9846274e6648
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-4/toolchain--crubit-vendor-0.20260909.tar.xz
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:
-C target-feature=-crt-static— link against musl dynamically rather than statically, the rule for every cargo build in the tree (see rust). Here a static link is not even possible: the program links the compiler’s ownlibrustc_driver-<hash>.so.RUSTC_BOOTSTRAP=1— let the stable compiler accept the nightly-only#![feature(...)]attributes the program and the Crubit crates it is built from declare, among themrustc_private,never_typeandcfg_accessible.rustc_privateis what gives it the compiler’s internal crates, through which it reads a crate’s types.--bin cc_bindings_from_rs— build that one binary target and nothing else of the manifest.--manifest-path— the generated manifest of the tool,cargo/cc_bindings_from_rs/cc_bindings_from_rs/Cargo.toml. TheCargo.tomlat the top of the tree is a workspace manifest with no package of its own; cargo still reads it, as the workspace this manifest belongs to, for the shared dependency versions.
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.