]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/cbindgen: Revert Makefile to a more pre-cbindgen state
authorJason Ish <jason.ish@oisf.net>
Tue, 14 Jan 2020 15:52:28 +0000 (09:52 -0600)
committerJason Ish <jason.ish@oisf.net>
Fri, 24 Jan 2020 16:16:00 +0000 (10:16 -0600)
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.

configure.ac
rust/Makefile.am

index 54e58e84db4d9b27f9c8cbbb64df18ade37a1c24..54a2cc2356453d99f52ddbf4fce92ee6b1756006 100644 (file)
@@ -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,
index 534a5c8cb71c0e7518946c15a261523ed440c801..f9fff8ffab9bed3b4292ceddb75866f8c41d27df 100644 (file)
@@ -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