From 8f81792da580d4d205c2cb7d9d3cbae3683fe975 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 16 Mar 2017 15:32:46 -0600 Subject: [PATCH] rust: hook rust into the build 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 | 2 +- configure.ac | 73 +++++++++++++++++++++++++++++- rust/.cargo/config.in | 8 ++++ rust/.gitignore | 7 ++- rust/Cargo.lock | 21 +++++++++ rust/{Cargo.toml => Cargo.toml.in} | 4 +- rust/Makefile.am | 44 ++++++++++++++++++ src/Makefile.am | 6 ++- 8 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 rust/.cargo/config.in create mode 100644 rust/Cargo.lock rename rust/{Cargo.toml => Cargo.toml.in} (73%) create mode 100644 rust/Makefile.am diff --git a/Makefile.am b/Makefile.am index d33150fff3..2b4359fa1a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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]* diff --git a/configure.ac b/configure.ac index aa7900d86c..c0b037c656 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) @@ -214,6 +214,7 @@ ;; *-*-linux*) #for now do nothing + RUST_LDADD="-ldl -lrt -lm" ;; *-*-mingw32*) CFLAGS="${CFLAGS} -DOS_WIN32" @@ -1961,6 +1962,71 @@ 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 index 0000000000..cd24b90e24 --- /dev/null +++ b/rust/.cargo/config.in @@ -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' diff --git a/rust/.gitignore b/rust/.gitignore index a9d37c560c..b8e3c7476f 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -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 index 0000000000..75d791f3af --- /dev/null +++ b/rust/Cargo.lock @@ -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" diff --git a/rust/Cargo.toml b/rust/Cargo.toml.in similarity index 73% rename from rust/Cargo.toml rename to rust/Cargo.toml.in index 5bc1b2515e..010cf0a487 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml.in @@ -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 index 0000000000..3af85e2f13 --- /dev/null +++ b/rust/Makefile.am @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index f9240f7be2..01daa03978 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 -- 2.47.2