mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.29k stars 294 forks source link

ERROR: Couldn't execute `cargo metadata` with manifest #889

Closed trippleflux closed 9 months ago

trippleflux commented 9 months ago

Hello,

I am a rust newbie, honestly I am coming here asking for help regarding suricata 7.0.2-DEV compilation in which involving RUST, CARGO, cbindgen. My platform is OpenWrt running on x86-64 hardware.

Here are the errors log :

   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

I have come quite far enough by patching the suricata 7.0.2-DEV ./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 \
+   $(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 \
+   $(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
        --quiet --output $(abs_top_builddir)/rust/dist/rust-bindings.h
 else
 dist/rust-bindings.h:

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.

trippleflux commented 9 months ago

Turns out it seems not related with cbindgen directly :