Skip to content

Commit bcb36c2

Browse files
jdieterclaude
andcommitted
Bundle bindgen-cli from source for Rocky 9.6 builds
The bindgen tool required for kernel Rust support is not packaged in Rocky Linux 9.6. Replace the bindgen BuildRequires with a bundled bindgen-cli crate built from vendored source during the RPM build. Add bundle_bindgen.sh helper script to download, vendor, and tar the bindgen-cli source for inclusion as Source5000. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Jonathan Dieter <jdieter@ciq.com>
1 parent 574cc4f commit bcb36c2

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

ciq/SOURCES/bundle_bindgen.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# Bundle the bindgen-cli source code to be included in the kernel build.
4+
# https://crates.io/crates/bindgen-cli
5+
#
6+
# The bindgen tool, required to build Rust code in the Linux kernel, is
7+
# currently only packaged in Fedora/ELN. In order to build CLK kernels
8+
# on Rocky Linux we need to build bindgen as part of the kernel build.
9+
10+
SOURCES=$1
11+
12+
BINDGEN_CLI=bindgen-cli
13+
BINDGEN_CLI_VERSION="0.71.1"
14+
BINDGEN_CLI_CRATE=bindgen-cli.crate
15+
CRATESIO_API_ENDPOINT=https://crates.io/api/v1/crates/bindgen-cli/${BINDGEN_CLI_VERSION}/download
16+
17+
curl -sL $CRATESIO_API_ENDPOINT -o $SOURCES/$BINDGEN_CLI_CRATE
18+
tar -xf $SOURCES/$BINDGEN_CLI_CRATE -C $SOURCES
19+
mv $SOURCES/$BINDGEN_CLI-$BINDGEN_CLI_VERSION $SOURCES/$BINDGEN_CLI
20+
21+
# vendor bindgen-cli
22+
cd $SOURCES/$BINDGEN_CLI
23+
mkdir .cargo
24+
cat > .cargo/config.toml <<EOF
25+
[source.crates-io]
26+
replace-with = "vendored-sources"
27+
28+
[source.vendored-sources]
29+
directory = "vendor"
30+
EOF
31+
32+
cargo vendor --locked --quiet
33+
34+
cd ..
35+
tar czf $BINDGEN_CLI.tar.gz $BINDGEN_CLI
36+
37+
# clean up
38+
rm -f $SOURCES/$BINDGEN_CLI_CRATE
39+
rm -rf $SOURCES/$BINDGEN_CLI

ciq/SPECS/kernel-clk6.18.spec

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ BuildRequires: bzip2, xz, findutils, m4, perl-interpreter, perl-Carp, perl-devel
715715
BuildRequires: zstd
716716
%endif
717717
BuildRequires: gcc, binutils, redhat-rpm-config, hmaccalc, bison, flex, gcc-c++
718-
BuildRequires: rust, rust-src, bindgen, rustfmt, clippy
718+
BuildRequires: rust, rust-src, rustfmt, clippy
719719
BuildRequires: net-tools, hostname, bc, elfutils-devel
720720
BuildRequires: dwarves
721721
BuildRequires: python3
@@ -1134,6 +1134,9 @@ Source3002: Patchlist.changelog
11341134

11351135
Source4000: README.rst
11361136

1137+
# Bundled bindgen-cli source (not packaged in Rocky 9.6)
1138+
Source5000: bindgen-cli.tar.gz
1139+
11371140
## Patches needed for building this package
11381141

11391142
%if !%{nopatches}
@@ -2238,6 +2241,18 @@ cp_vmlinux()
22382241
%define build_hostldflags %{?build_ldflags}
22392242
%endif
22402243

2244+
# Build bundled bindgen and add to PATH
2245+
%{log_msg "Build bindgen"}
2246+
BINDGEN_DIR=$RPM_BUILD_ROOT/bindgen
2247+
BINDGEN_BUNDLE_NAME=$(basename %{SOURCE5000} .tar.gz)
2248+
mkdir -p $BINDGEN_DIR
2249+
tar -xf %{SOURCE5000} -C $BINDGEN_DIR
2250+
pushd $BINDGEN_DIR/$BINDGEN_BUNDLE_NAME
2251+
cargo build --offline --frozen --release
2252+
export PATH="$PWD/target/release:$PATH"
2253+
popd
2254+
bindgen --version
2255+
22412256
%define make %{__make} %{?cross_opts} %{?make_opts} HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}"
22422257

22432258
InitBuildVars() {

0 commit comments

Comments
 (0)