From: Scott Weaver <scwea...@redhat.com>

redhat: bundle and build bindgen

Currently, RHEL does not package the bindgen tool, which is necessary
for building kernel-ark in brew as it's required to build Rust code in
the kernel. To address this, a step has been added to build bindgen if
the build environment is rhel or centos.

bindgen is available in Fedoar/ELN and therefore the bundle should not
be used in those build environments.

Signed-off-by: Scott Weaver <scwea...@redhat.com>

diff --git a/redhat/Makefile b/redhat/Makefile
index blahblah..blahblah 100644
--- a/redhat/Makefile
+++ b/redhat/Makefile
@@ -689,8 +689,12 @@ generate-testpatch-tmp:
                ":(exclude,top)makefile" \
                ":(exclude,top)Makefile.rhelver" \
                ":(exclude,top)redhat" > $(TESTPATCH).tmp
-
-sources-rh: $(TARBALL) $(KABI_TARBALL) $(KABIDW_TARBALL) 
generate-testpatch-tmp setup-source dist-configs-check
+bundle-bindgen:
+       @if [[ ("$(DISTRO)" = "rhel") && ! ("$(DIST)" == ".eln"*) ]]; then \
+               echo "Bundling bindgen"; \
+               $(REDHAT)/scripts/bundle_bindgen.sh $(SOURCES); \
+       fi
+sources-rh: $(TARBALL) $(KABI_TARBALL) $(KABIDW_TARBALL) bundle-bindgen 
generate-testpatch-tmp setup-source dist-configs-check
        @cp -l $(TARBALL) $(KABI_TARBALL) $(KABIDW_TARBALL) $(SOURCES)/ || \
                cp $(TARBALL) $(KABI_TARBALL) $(KABIDW_TARBALL) $(SOURCES)/
        @touch $(TESTPATCH)
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index blahblah..blahblah 100644
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -736,7 +736,11 @@ BuildRequires: bzip2, xz, findutils, m4, perl-interpreter, 
perl-Carp, perl-devel
 BuildRequires: zstd
 %endif
 BuildRequires: gcc, binutils, redhat-rpm-config, hmaccalc, bison, flex, gcc-c++
-BuildRequires: rust, rust-src, bindgen, rustfmt, clippy
+BuildRequires: rust, rust-src, rustfmt, clippy
+# bindgen is only available in fedora/eln
+%if 0%{?fedora}%{?eln}
+BuildRequires: bindgen
+%endif
 BuildRequires: net-tools, hostname, bc, elfutils-devel
 BuildRequires: dwarves
 BuildRequires: python3
@@ -1108,6 +1112,11 @@ Source4000: README.rst
 Source4001: rpminspect.yaml
 Source4002: gating.yaml
 
+# temporaray workaround: bundle bindgen source until the package is available
+%if 0%{?include_rhel} && !0%{?fedora}%{?eln}
+Source5000: bindgen-cli.tar.gz
+%endif
+
 ## Patches needed for building this package
 
 %if !%{nopatches}
@@ -2159,6 +2168,20 @@ cp_vmlinux()
 %define build_hostldflags %{?build_ldflags}
 %endif
 
+# temporary workaround: build bindgen until the package is available
+%if 0%{?rhel}%{?centos} && !0%{?fedora}%{?eln}
+%{log_msg "Build bindgen"}
+BINDGEN_DIR=$RPM_BUILD_ROOT/bindgen
+BINDGEN_BUNDLE_NAME=$(basename %{SOURCE5000} .tar.gz)
+mkdir -p $BINDGEN_DIR
+tar -xf %{SOURCE5000} -C $BINDGEN_DIR
+pushd $BINDGEN_DIR/$BINDGEN_BUNDLE_NAME
+cargo build --offline --frozen --release
+export PATH="$PWD/target/release:$PATH"
+popd
+bindgen --version
+%endif
+
 %define make %{__make} %{?cross_opts} %{?make_opts} 
HOSTCFLAGS="%{?build_hostcflags}" HOSTLDFLAGS="%{?build_hostldflags}"
 
 InitBuildVars() {
diff --git a/redhat/scripts/bundle_bindgen.sh b/redhat/scripts/bundle_bindgen.sh
new file mode 100755
index blahblah..blahblah 100755
--- /dev/null
+++ b/redhat/scripts/bundle_bindgen.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Bundle the bingen-cli source code to be included in the kernel build.
+# https://crates.io/crates/bindgen-cli
+
+# The bindgen tool, required to buid Rust code in the Linux kernel, is
+# currently only packaged in Fedora/ELN. In order to build kernel-ark
+# in brew we will temporarily need to build bindgen in the the kernel
+# build until the bindgen package is added.
+
+SOURCES=$1
+
+BINDGEN_CLI=bindgen-cli
+BINDGEN_CLI_VERSION="0.71.1"
+BINDGEN_CLI_CRATE=bindgen-cli.crate
+CRATESIO_API_ENDPOINT=https://crates.io/api/v1/crates/bindgen-cli/${BINDGEN_CLI_VERSION}/download
+
+curl -sL $CRATESIO_API_ENDPOINT -o $SOURCES/$BINDGEN_CLI_CRATE
+tar -xf $SOURCES/$BINDGEN_CLI_CRATE -C $SOURCES
+mv $SOURCES/$BINDGEN_CLI-$BINDGEN_CLI_VERSION $SOURCES/$BINDGEN_CLI
+
+# vendor bindgen-cli
+cd $SOURCES/$BINDGEN_CLI
+mkdir .cargo 
+cat > .cargo/config.toml <<EOF
+[source.crates-io]
+replace-with = "vendored-sources"
+
+[source.vendored-sources]
+directory = "vendor"
+EOF
+
+cargo vendor --locked --quiet
+
+cd ..
+tar czf $BINDGEN_CLI.tar.gz $BINDGEN_CLI
+
+# clean up
+rm -f $SOURCES/$BINDGEN_CLI_CRATE
+rm -rf $SOURCES/$BINDGEN_CLI

--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/3880

-- 
_______________________________________________
kernel mailing list -- kernel@lists.fedoraproject.org
To unsubscribe send an email to kernel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/kernel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to