diff --git a/configure.ac b/configure.ac index 93e728fc2246..e2b23f796f70 100644 --- a/configure.ac +++ b/configure.ac @@ -2270,6 +2270,11 @@ fi fi fi + AC_PATH_PROG([BINDGEN], [bindgen], [no]) + if test "x$BINDGEN" = "xno"; then + AC_MSG_ERROR([bindgen required]) + fi + AC_PATH_PROG(CBINDGEN, cbindgen, "no") if test "x$CBINDGEN" != "xno"; then cbindgen_version=$(cbindgen --version 2>&1 | cut -d' ' -f2-) diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 4e59be1944e6..df0ff3dd3419 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -5,7 +5,6 @@ license = "GPL-2.0-only" description = "Suricata Rust components" edition = "2021" rust-version = "1.67.1" -build = "src/build.rs" [workspace] members = [".", "./derive"] @@ -75,11 +74,3 @@ suricata-lua-sys = { version = "0.1.0-alpha.3" } [dev-dependencies] test-case = "~3.3.1" hex = "~0.4.3" - -[build-dependencies] -# Pin as bindgen 0.70.1 requires Rust 1.70.0+ -bindgen = "=0.69.4" - -# Most recent version to support Rust 1.67. 0.5.9 requires 1.70.0. -# - Not used directly but Suricata, but by bindgen. -home = "=0.5.5" diff --git a/rust/Makefile.am b/rust/Makefile.am index 1de30ee687d0..3c8b1b229f10 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -41,6 +41,7 @@ CARGO_VARS = TOP_BUILDDIR=$(abs_top_builddir) \ all-local: Cargo.toml mkdir -p $(abs_top_builddir)/rust/gen + $(MAKE) gen/bindings.rs if HAVE_CYGPATH cd $(abs_top_srcdir)/rust && \ @rustup_home@ CARGO_HOME="$(CARGO_HOME)" \ @@ -87,6 +88,31 @@ check: vendor: CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) vendor +gen/bindgen.h: $(abs_top_srcdir)/src/app-layer-types.h \ + $(abs_top_srcdir)/src/app-layer-protos.h + rm -f $@ +if HAVE_CYGPATH + for header in $^; do \ + echo "#include \"`cygpath -am $$header`\"" >> gen/bindgen.h; \ + done +else + for header in $^; do \ + echo "#include \"$$header\"" >> gen/bindgen.h; \ + done +endif + +gen/bindings.rs: gen/bindgen.h + rm -f $@ + $(BINDGEN) \ + -o $@ \ + --allowlist-item 'AppProto.*' \ + --allowlist-item 'SCAppLayer.*' \ + --rustified-enum SCAppLayerEventType \ + --rustified-enum AppProtoEnum \ + ./gen/bindgen.h \ + -- \ + -DHAVE_CONFIG_H -I../src $(CPPFLAGS) + if HAVE_CBINDGEN gen/rust-bindings.h: $(RUST_SURICATA_LIB) cd $(abs_top_srcdir)/rust && \ diff --git a/rust/src/build.rs b/rust/src/build.rs deleted file mode 100644 index 86bb6d0430b3..000000000000 --- a/rust/src/build.rs +++ /dev/null @@ -1,45 +0,0 @@ -// builds.rs for Suricata -// -// Currently this build.rs only uses bindgen to build some Rust -// bindings to the Suricata C code. -// -// For more info on Rust and the build.rs file, see: -// https://doc.rust-lang.org/cargo/reference/build-scripts.html -fn main() { - let src_dir = std::env::var("TOP_SRCDIR").unwrap_or_else(|_| "..".to_string()); - let build_dir = std::env::var("TOP_BUILDDIR").unwrap_or_else(|_| "..".to_string()); - - // Pull in a simple header that presents no issues with bindgen at - // this time. Multiple headers can be specified. - let mut builder = bindgen::Builder::default() - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) - .clang_arg("-DHAVE_CONFIG_H") - .clang_arg("-D__SCFILENAME__=\"\"") - .clang_arg(format!("-I{}/src", &build_dir)); - - let headers = &["app-layer-types.h", "app-layer-protos.h"]; - for header in headers { - builder = builder.header(format!("{}/src/{}", &src_dir, header)); - } - - // Patterns. - builder = builder - .allowlist_item("SCAppLayer.*") - .allowlist_item("AppProto.*"); - - // Rustified enums. - builder = builder - .rustified_enum("SCAppLayerEventType") - .rustified_enum("AppProtoEnum"); - - let bindings = builder.generate().unwrap(); - - // Write out the bindings. *Rules* say we should only write into - // the target directory (idiomatically the OUT_DIR env var), so - // we'll pull them into our namespace using an include!() macro - // (current in sys.rs). - let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("bindings.rs")) - .unwrap(); -} diff --git a/rust/src/sys.rs b/rust/src/sys.rs index 9c224b35a540..1ce1a03051eb 100644 --- a/rust/src/sys.rs +++ b/rust/src/sys.rs @@ -16,4 +16,6 @@ */ #![allow(non_camel_case_types)] -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +//include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +//include!("../gen/bindings.rs"); +include!(concat!(env!("CARGO_TARGET_DIR"), "/../gen/bindings.rs"));