Cargo.toml & cbindgen seems to be broken?

Hello,

Currently I am trying to 'compiling' suricata 7.0.2-DEV git version for OpenWrt x86-64, currently I am stuck with somehow Suricata's Cargo.toml seems to be broken in one of the line?, as I am a rust newbie, I cann't quite figuring it out in which one of Cargo.toml is the problematic one :

   Compiling bendy v0.3.3
   Compiling asn1-rs v0.5.2
   Compiling kerberos-parser v0.7.1
   Compiling nom-derive v0.10.1
   Compiling ntp-parser v0.6.0
   Compiling num_enum v0.5.11
   Compiling sawp-modbus v0.12.1
   Compiling der-parser v8.2.0
   Compiling snmp-parser v0.9.0
   Compiling x509-parser v0.15.0
   Compiling suricata v7.0.2-dev (/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 30.36s
if test -e ../rust/target/debug/suricata.lib; then \
        cp -a ../rust/target/debug/suricata.lib \
                ../rust/target/debug/libsuricata_rust.a; \
fi
if test -e ../rust/target/debug/libsuricata.a; then \
        cp -a ../rust/target/debug/libsuricata.a \
                ../rust/target/debug/libsuricata_rust.a; \
fi
make gen/rust-bindings.h
make[5]: Entering directory '/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust'
/home/username/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/cargo/bin/cbindgen --config /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust/cbindgen.toml \
        --quiet --verify --output /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust/gen/rust-bindings.h || true
ERROR: Couldn't execute `cargo metadata` with manifest "/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust/Cargo.toml": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
ERROR: Couldn't generate bindings for /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust.
make[5]: Leaving directory '/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust'
make[4]: Leaving directory '/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust'
Making all in src
make[4]: Entering directory '/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/src'
make  all-am

Now let's going directly at the issues :

ERROR: Couldn't execute `cargo metadata` with manifest "/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust/Cargo.toml": Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })
ERROR: Couldn't generate bindings for /home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust.

I am curious whether No such file or directory is about rust dependencies or just cbindgen runtime libraries is not found.
My Env :

export CARGO_HOME=$(STAGING_DIR)/host/cargo
export RUSTC=$(CARGO_HOME)/bin/rustc
export CBINDGEN=$(CARGO_HOME)/bin/cbindgen

I have tried the following :
By appending the LD_LIBRARY_PATH before the $(CBINDGEN) in ./rust/Makefile.am

diff -Naur a/rust/Makefile.am b/rust/Makefile.am
--- a/rust/Makefile.am
+++ b/rust/Makefile.am
@@ -81,7 +81,7 @@
 
 if HAVE_CBINDGEN
 gen/rust-bindings.h: $(RUST_SURICATA_LIB)
-	cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
+	LD_LIBRARY_PATH=$(CARGO_HOME)/lib $(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
 		--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true
 else
 gen/rust-bindings.h:
@@ -92,7 +92,7 @@
 
 if HAVE_CBINDGEN
 dist/rust-bindings.h:
-	cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
+	LD_LIBRARY_PATH=$(CARGO_HOME)/lib $(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
 		--quiet --output $(abs_top_builddir)/rust/dist/rust-bindings.h
 else
 dist/rust-bindings.h:

But still getting the same errors.

For references :
Suricata's Cargo.toml
Suricata's cbindgen.toml

This is cross-compilation linux x6-64 host for OpenWrt x86-64 target, the weird part is, somehow I have tried to install Cargo in my linux host which are used for Compiling. And
the Suricata 7 rust Cargo.toml seems doesn't have any trouble using it (running "cargo check" in the directory)

   Compiling nom-derive-impl v0.10.1
   Compiling sawp-flags-derive v0.12.1
   Compiling der-oid-macro v0.5.0
   Compiling num_enum_derive v0.5.11
   Compiling suricata-derive v7.0.2-dev (/home/echelon/works/openwrt/build_dir/target-x86_64_glibc_siliwangi/suricata-7.0.2/rust/derive)
    Checking der-parser v6.0.1
    Checking sawp-flags v0.12.1
    Checking failure v0.1.8
    Checking bendy v0.3.3
    Checking asn1-rs v0.5.2
    Checking kerberos-parser v0.7.1
    Checking num_enum v0.5.11
    Checking sawp-modbus v0.12.1
    Checking nom-derive v0.10.1
    Checking ntp-parser v0.6.0
    Checking der-parser v8.2.0
    Checking snmp-parser v0.9.0
    Checking x509-parser v0.15.0
    Checking suricata v7.0.2-dev (/home/username/works/openwrt/build_dir/target-x86_64_glibc_custom/suricata-7.0.2/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 3m 30s

Perhaps "Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })" is regarding my rust cross compilation tool dependencies ?.

My rust cross compiler is installed at "/home/username/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/cargo"

I have tried :

export CARGO_HOME=/home/username/works/openwrt/staging_dir/target-x86_64_glibc_custom/host/cargo
export PATH=$(CARGO_HOME)/bin:$(TOOLCHAIN_DIR)/bin:/usr/sbin:/usr/bin:/sbin:/bin:$$$$PATH
export LD_LIBRARY_PATH="$(CARGO_HOME)/lib:$(STAGING_DIR_HOST)/llvm-bpf/lib:$LD_LIBRARY_PATH"

Turns out it seems not related with rust compiler ecosystem at all :

  • cbindgen need to be defined in $PATH/PATH env variable
  • cbindgen cannot be inside a variable which containing a patch to it , so the fix for Suricata Makefile.am :
gen/rust-bindings.h: $(RUST_SURICATA_LIB)
	PATH=$(CARGO_HOME)/bin:$(PATH) \
	cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
		--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true