]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: hook rust into the build
authorJason Ish <ish@unx.ca>
Thu, 16 Mar 2017 21:32:46 +0000 (15:32 -0600)
committerJason Ish <ish@unx.ca>
Mon, 5 Jun 2017 20:56:51 +0000 (14:56 -0600)
Rust is currently optional, use the --enable-rust configure
argument to enable Rust.

By default Rust will be built in release mode. If debug is enabled
then it will be built in debug mode.

On make dist, "cargo vendor" will be run to make a local copy
of Rust dependencies for the distribution archive file.

Add autoconf checks to test for the vendored source, and if it
exists setup the build to use the vendored code instead of
fetching it from the network.

Also, as Cargo requires semantic versioning, the Suricata version
had to change from 4.0dev to 4.0.0-dev.

Makefile.am
configure.ac
rust/.cargo/config.in [new file with mode: 0644]
rust/.gitignore
rust/Cargo.lock [new file with mode: 0644]
rust/Cargo.toml.in [moved from rust/Cargo.toml with 73% similarity]
rust/Makefile.am [new file with mode: 0644]
src/Makefile.am

index d33150fff3b22fb1058cf5c19d565cf417bbf8ea..2b4359fa1a5612fa9d508211a711979c3dc07db5 100644 (file)
@@ -5,7 +5,7 @@ ACLOCAL_AMFLAGS = -I m4
 EXTRA_DIST = ChangeLog COPYING LICENSE suricata.yaml.in \
              classification.config threshold.config \
              reference.config
-SUBDIRS = $(HTP_DIR) src qa rules doc contrib scripts
+SUBDIRS = $(HTP_DIR) rust src qa rules doc contrib scripts
 
 CLEANFILES = stamp-h[0-9]*
 
index aa7900d86c482301613afeb41e4a6991310f9ef1..c0b037c656fe69f46dadebd142b986d957201e6b 100644 (file)
@@ -1,4 +1,4 @@
-    AC_INIT(suricata, 4.0dev)
+    AC_INIT(suricata, 4.0.0-dev)
     m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])AM_SILENT_RULES([yes])
     AC_CONFIG_HEADERS([config.h])
     AC_CONFIG_SRCDIR([src/suricata.c])
             ;;
         *-*-linux*)
             #for now do nothing
+           RUST_LDADD="-ldl -lrt -lm"
             ;;
         *-*-mingw32*)
             CFLAGS="${CFLAGS} -DOS_WIN32"
     fi
     AM_CONDITIONAL([HAVE_PDFLATEX], [test "x$enable_pdflatex" != "xno"])
 
+# Cargo/Rust.
+    dnl enable_rust="no"
+    dnl AC_ARG_ENABLE(rust, AS_HELP_STRING([--enable-rust], [Enable Rust]),
+    dnl     [enable_rust="$enableval"], [enable_rust=no])
+    AC_ARG_ENABLE([rust], AS_HELP_STRING([--enable-rust], [Enable Rust]))
+
+    rust_vendor_comment="# "
+    have_rust_vendor="no"
+
+    if test "x$enable_rust" != "xyes"; then
+      enable_rust="no"
+    else
+      AC_PATH_PROG(HAVE_CARGO, cargo, "no")
+      AC_PATH_PROG(HAVE_RUSTC, rustc, "no")
+
+      # Deal with the case where Rust was requested but rustc or cargo
+      # cannot be found.
+      if test "x$HAVE_CARGO" = "xno"; then
+        echo ""
+        echo "   ERROR! Rust support requested but cargo not found."
+        echo ""
+        exit 1
+      fi
+      if test "x$HAVE_RUST" = "xno"; then
+        echo ""
+        echo "   ERROR! Rust support requested but rustc not found."
+        echo ""
+        exit 1
+      fi
+
+      if test "x$HAVE_CARGO" != "xno"; then
+        if test "x$HAVE_RUSTC" != "xno"; then
+          enable_rust="yes"
+          AC_DEFINE([HAVE_RUST],[1],[Enable Rust language])
+          if test "x$enable_debug" = "xyes"; then
+            RUST_SURICATA_LIB="../rust/target/debug/libsuricata.a"
+          else
+            RUST_SURICATA_LIB="../rust/target/release/libsuricata.a"
+          fi
+          RUST_LDADD="${RUST_SURICATA_LIB} ${RUST_LDADD}"
+          CFLAGS="${CFLAGS} -I../rust/gen/c-headers"
+          AC_SUBST(RUST_SURICATA_LIB)
+          AC_SUBST(RUST_LDADD)
+          AC_CHECK_FILES([$srcdir/rust/vendor], [have_rust_vendor="yes"])
+          if test "x$have_rust_vendor" = "xyes"; then
+          rust_vendor_comment=""
+          fi
+        fi
+      fi
+    fi
+
+    AM_CONDITIONAL([HAVE_RUST], [test "x$enable_rust" = "xyes"])
+    AC_SUBST(rust_vendor_comment)
+    AM_CONDITIONAL([HAVE_RUST_VENDOR], [test "x$have_rust_vendor" = "xyes"])
+
+    if test "x$enable_rust" = "xyes"; then
+      AC_PATH_PROG(HAVE_CARGO_VENDOR, cargo-vendor, "no")
+      if test "x$HAVE_CARGO_VENDOR" = "xno"; then
+        echo "   Warning: cargo-vendor not found, but it is only required"
+        echo "       for building the distribution"
+        echo "   To install: cargo install cargo-vendor"
+      fi
+    fi
+    AM_CONDITIONAL([HAVE_CARGO_VENDOR], [test "x$HAVE_CARGO_VENDOR" != "xno"])
+
 # get revision
     if test -f ./revision; then
         REVISION=`cat ./revision`
@@ -2038,8 +2104,9 @@ EXPAND_VARIABLE(localstatedir, CONFIGURE_LOCALSTATEDIR)
 AC_SUBST(CONFIGURE_PREFIX)
 AC_SUBST(CONFIGURE_SYSCONDIR)
 AC_SUBST(CONFIGURE_LOCALSTATEDIR)
+AC_SUBST(PACKAGE_VERSION)
 
-AC_OUTPUT(Makefile src/Makefile qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml scripts/Makefile scripts/suricatasc/Makefile scripts/suricatasc/suricatasc)
+AC_OUTPUT(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml scripts/Makefile scripts/suricatasc/Makefile scripts/suricatasc/suricatasc)
 
 SURICATA_BUILD_CONF="Suricata Configuration:
   AF_PACKET support:                       ${enable_af_packet}
@@ -2071,6 +2138,8 @@ SURICATA_BUILD_CONF="Suricata Configuration:
   Hyperscan support:                       ${enable_hyperscan}
   Libnet support:                          ${enable_libnet}
 
+  Rust support:                            ${enable_rust}
+
   Suricatasc install:                      ${enable_python}
 
   Profiling enabled:                       ${enable_profiling}
diff --git a/rust/.cargo/config.in b/rust/.cargo/config.in
new file mode 100644 (file)
index 0000000..cd24b90
--- /dev/null
@@ -0,0 +1,8 @@
+@rust_vendor_comment@[source]
+@rust_vendor_comment@
+@rust_vendor_comment@[source.crates-io]
+@rust_vendor_comment@registry = 'https://github.com/rust-lang/crates.io-index'
+@rust_vendor_comment@replace-with = 'vendored-sources'
+@rust_vendor_comment@
+@rust_vendor_comment@[source.vendored-sources]
+@rust_vendor_comment@directory = './vendor'
index a9d37c560c6ab8d4afbf47eda643e8c42e857716..b8e3c7476f7cce7e29c4fe887d78a51f08e92b4e 100644 (file)
@@ -1,2 +1,5 @@
-target
-Cargo.lock
+!Cargo.toml.in
+/.cargo/config
+/Cargo.toml
+/target
+/vendor
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
new file mode 100644 (file)
index 0000000..75d791f
--- /dev/null
@@ -0,0 +1,21 @@
+[root]
+name = "suricata"
+version = "4.0.0-dev"
+dependencies = [
+ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "nom 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "nom"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135"
+"checksum nom 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d4598834859fedb9a0a69d5b862a970e77982a92f544d547257a4d49469067"
similarity index 73%
rename from rust/Cargo.toml
rename to rust/Cargo.toml.in
index 5bc1b2515ef8429113cfed4bacff01948449c3d0..010cf0a48763b4c9a76e6f5e8c14fc24a1657a67 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "suricata"
-version = "4.0.0-dev"
+version = "@PACKAGE_VERSION@"
 
 [lib]
 crate-type = ["staticlib"]
@@ -9,5 +9,5 @@ crate-type = ["staticlib"]
 debug = true
 
 [dependencies]
-nom = "^2.1.0"
+nom = "2.1.0"
 libc = "0.2.0"
diff --git a/rust/Makefile.am b/rust/Makefile.am
new file mode 100644 (file)
index 0000000..3af85e2
--- /dev/null
@@ -0,0 +1,44 @@
+EXTRA_DIST =   Cargo.toml \
+               Cargo.lock \
+               src/lib.rs \
+               .cargo/config.in
+
+if HAVE_RUST
+EXTRA_DIST +=  vendor
+endif
+
+if HAVE_RUST_VENDOR
+FROZEN = --frozen
+endif
+
+if !DEBUG
+RELEASE = --release
+endif
+
+if HAVE_RUST
+all-local:
+       cd $(top_srcdir)/rust && CARGO_TARGET_DIR=$(abs_builddir)/target \
+               cargo build $(RELEASE) $(FROZEN)
+
+clean-local:
+       cd $(top_srcdir)/rust && CARGO_TARGET_DIR=$(abs_builddir)/target \
+               cargo clean
+
+distclean-local:
+       rm -rf vendor
+
+check:
+       cd $(top_srcdir)/rust && CARGO_TARGET_DIR=$(abs_builddir)/target \
+               cargo test
+else
+all-local clean-local check:
+endif
+
+if HAVE_CARGO_VENDOR
+vendor:
+       cargo vendor > /dev/null
+else
+vendor:
+       @echo "error: cargo vendor not installed"
+       exit 1
+endif
index f9240f7be2ca37b4b6f6c7b6b290a34e57740e07..01daa039786ccfae128a85f98bd888d5ffcd13a0 100644 (file)
@@ -469,7 +469,11 @@ AM_CPPFLAGS = $(all_includes)
 
 # the library search path.
 suricata_LDFLAGS = $(all_libraries) ${SECLDFLAGS}
-suricata_LDADD = $(HTP_LDADD)
+suricata_LDADD = $(HTP_LDADD) $(RUST_LDADD)
+
+if HAVE_RUST
+suricata_DEPENDENCIES = $(RUST_SURICATA_LIB)
+endif
 
 # Rules to build CUDA ptx modules
 if BUILD_CUDA