Skip to content

Commit

Permalink
bindgen: use bindgen-cli instead of library
Browse files Browse the repository at this point in the history
Replace bindgen usage from build.rs with the bindgen-cli program much
like we use cbindgen.

As bindgen can only accept one header file, we construct a
pseudo-header file of all the headers that need to be
consumed. Makefile dependency checking is done to make sure the
pseudo-header is only generated as needed to avoid rebuilding every
time.

Special handling is required for Windows to use the Windows path.
  • Loading branch information
jasonish committed Nov 20, 2024
1 parent 9f90ccf commit 06e5a5c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 55 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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-)
Expand Down
9 changes: 0 additions & 9 deletions rust/Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"
26 changes: 26 additions & 0 deletions rust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
Expand Down Expand Up @@ -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 && \
Expand Down
45 changes: 0 additions & 45 deletions rust/src/build.rs

This file was deleted.

4 changes: 3 additions & 1 deletion rust/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

0 comments on commit 06e5a5c

Please sign in to comment.