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.
pull/2746/head
Jason Ish 9 years ago
parent cf0b9dd45f
commit 8f81792da5

@ -5,7 +5,7 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = ChangeLog COPYING LICENSE suricata.yaml.in \ EXTRA_DIST = ChangeLog COPYING LICENSE suricata.yaml.in \
classification.config threshold.config \ classification.config threshold.config \
reference.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]* CLEANFILES = stamp-h[0-9]*

@ -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]) m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([src/suricata.c]) AC_CONFIG_SRCDIR([src/suricata.c])
@ -214,6 +214,7 @@
;; ;;
*-*-linux*) *-*-linux*)
#for now do nothing #for now do nothing
RUST_LDADD="-ldl -lrt -lm"
;; ;;
*-*-mingw32*) *-*-mingw32*)
CFLAGS="${CFLAGS} -DOS_WIN32" CFLAGS="${CFLAGS} -DOS_WIN32"
@ -1961,6 +1962,71 @@
fi fi
AM_CONDITIONAL([HAVE_PDFLATEX], [test "x$enable_pdflatex" != "xno"]) 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 # get revision
if test -f ./revision; then if test -f ./revision; then
REVISION=`cat ./revision` REVISION=`cat ./revision`
@ -2038,8 +2104,9 @@ EXPAND_VARIABLE(localstatedir, CONFIGURE_LOCALSTATEDIR)
AC_SUBST(CONFIGURE_PREFIX) AC_SUBST(CONFIGURE_PREFIX)
AC_SUBST(CONFIGURE_SYSCONDIR) AC_SUBST(CONFIGURE_SYSCONDIR)
AC_SUBST(CONFIGURE_LOCALSTATEDIR) 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: SURICATA_BUILD_CONF="Suricata Configuration:
AF_PACKET support: ${enable_af_packet} AF_PACKET support: ${enable_af_packet}
@ -2071,6 +2138,8 @@ SURICATA_BUILD_CONF="Suricata Configuration:
Hyperscan support: ${enable_hyperscan} Hyperscan support: ${enable_hyperscan}
Libnet support: ${enable_libnet} Libnet support: ${enable_libnet}
Rust support: ${enable_rust}
Suricatasc install: ${enable_python} Suricatasc install: ${enable_python}
Profiling enabled: ${enable_profiling} Profiling enabled: ${enable_profiling}

@ -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'

7
rust/.gitignore vendored

@ -1,2 +1,5 @@
target !Cargo.toml.in
Cargo.lock /.cargo/config
/Cargo.toml
/target
/vendor

21
rust/Cargo.lock generated

@ -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"

@ -1,6 +1,6 @@
[package] [package]
name = "suricata" name = "suricata"
version = "4.0.0-dev" version = "@PACKAGE_VERSION@"
[lib] [lib]
crate-type = ["staticlib"] crate-type = ["staticlib"]
@ -9,5 +9,5 @@ crate-type = ["staticlib"]
debug = true debug = true
[dependencies] [dependencies]
nom = "^2.1.0" nom = "2.1.0"
libc = "0.2.0" libc = "0.2.0"

@ -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

@ -469,7 +469,11 @@ AM_CPPFLAGS = $(all_includes)
# the library search path. # the library search path.
suricata_LDFLAGS = $(all_libraries) ${SECLDFLAGS} 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 # Rules to build CUDA ptx modules
if BUILD_CUDA if BUILD_CUDA

Loading…
Cancel
Save