From: Jason Ish Date: Tue, 14 Jan 2020 15:52:28 +0000 (-0600) Subject: rust/cbindgen: Revert Makefile to a more pre-cbindgen state X-Git-Tag: suricata-6.0.0-beta1~842 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fbe02058576f76d00928535538fc597b8992fd7;p=thirdparty%2Fsuricata.git rust/cbindgen: Revert Makefile to a more pre-cbindgen state The modifications as part of the cbindgen commit caused issues with distcheck, revert the Makefile to how it was with the Python generator, but still using cbindgen. Also always assume we'll include the generated headers in the distribution archive to fix make distcheck from distribution archives with headers included, but no cbindgen. --- diff --git a/configure.ac b/configure.ac index 54e58e84db..54a2cc2356 100644 --- a/configure.ac +++ b/configure.ac @@ -2460,26 +2460,36 @@ fi fi AC_CHECK_FILES([$srcdir/rust/gen], [have_rust_headers="yes"]) - AC_DEFINE([HAVE_RUST_HEADERS],[1],[Enable Rust language]) - AM_CONDITIONAL([HAVE_RUST_HEADERS], [test "x$have_rust_headers" = "xyes"]) + AC_PATH_PROG(CBINDGEN, cbindgen, "no") + if test "x$CBINDGEN" != "xno"; then + cbindgen_version=$(cbindgen --version | cut -d' ' -f2-) + min_cbindgen_version="0.10.0" + AS_VERSION_COMPARE([$cbindgen_version], [$min_cbindgen_version], + [cbindgen_ok="no"], + [cbindgen_ok="yes"], + [cbindgen_ok="yes"]) + if test "x$cbindgen_ok" != "xyes"; then + echo " Warning: cbindgen must be at least version $min_cbindgen_version," + echo " found $cbindgen_version." + echo " To update: cargo install --force cbindgen" + CBINDGEN="no" + else + have_rust_headers="no" + fi + fi + + # Require cbindgen if generated headers are not bundled. if test "x$have_rust_headers" != "xyes"; then - AC_PATH_PROG(HAVE_CARGO_CBINDGEN, cbindgen, "no") - if test "x$HAVE_CARGO_CBINDGEN" = "xno"; then - echo " Warning: cbindgen not found, it is required to generate header files" + if test "x$CBINDGEN" = "xno"; then + echo " Warning: cbindgen too old or not found, it is required to " + echo " generate header files." echo " To install: cargo install --force cbindgen" AC_MSG_ERROR([cbindgen required]) fi - required_version=0.9.0 - cbindgen_version=$(cbindgen --version | cut -d' ' -f2-) - lowest_version=$(printf '%s\n' $required_version $cbindgen_version | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | head -n1) - if test "x$lowest_version" != "x$required_version"; then - HAVE_CARGO_BINDGEN="no" - echo " Warning: cbindgen must be at least version $required_version, version was $cbindgen_version, lowest version was $lowest_version" - echo " To install: cargo install --force cbindgen" - AC_MSG_ERROR([incorrect cbindgen version]) - fi fi + AM_CONDITIONAL([HAVE_RUST_HEADERS], [test "x$have_rust_headers" = "xyes"]) + AM_CONDITIONAL([HAVE_CBINDGEN], [test "x$CBINDGEN" != "xno"]) AM_CONDITIONAL([HAVE_CARGO_VENDOR], [test "x$have_cargo_vendor" != "xno"]) AC_ARG_ENABLE(rust_strict, diff --git a/rust/Makefile.am b/rust/Makefile.am index 534a5c8cb7..f9fff8ffab 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -1,7 +1,7 @@ EXTRA_DIST = src \ .cargo/config.in \ - gen \ - cbindgen.toml + cbindgen.toml \ + gen/rust-bindings.h if HAVE_CARGO_VENDOR EXTRA_DIST += vendor @@ -23,9 +23,11 @@ if RUST_CROSS_COMPILE RUST_TARGET = --target $(host_triplet) endif -build-rust: - cd $(top_srcdir)/rust - +all-local: +if HAVE_CBINDGEN + cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \ + --quiet --output $(abs_top_builddir)/rust/gen/rust-bindings.h +endif if HAVE_CYGPATH @rustup_home@ \ CARGO_HOME="$(CARGO_HOME)" \ @@ -40,30 +42,12 @@ else --features "$(RUST_FEATURES)" $(RUST_TARGET) endif -if HAVE_RUST_HEADERS - -all-local: build-rust - echo Rust headers available - -clean-local: - -rm -rf target - -distclean-local: clean-local - rm -rf vendor Cargo.lock - -else - -all-local: gen-headers build-rust - $(info Generating rust headers) - clean-local: -rm -rf target gen distclean-local: clean-local rm -rf vendor gen Cargo.lock -endif - check: CARGO_HOME="$(CARGO_HOME)" @rustup_home@ \ CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \ @@ -76,6 +60,11 @@ else vendor: endif -gen-headers: FORCE - cbindgen --config cbindgen.toml --output "gen/rust-bindings.h" > /dev/null -FORCE: +# Can only include the headers if we have Python to generate them. +if HAVE_CBINDGEN +gen/rust-bindings.h: + cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \ + --quiet --output $(abs_top_builddir)/rust/gen/rust-bindings.h +else +gen/rust-bindings.h: +endif