rust: respect RUSTC and CARGO env vars like CC

To support alternative cargo and rustc programs (such as cargo-1.82),
respect CARGO and RUSTC environment variables during ./configure much
like CC.

RUSTFMT is also respected as that is required for the tests, and Cargo
can't figure this out like it can for rustc (perhaps a bug in the
packaging).

For cbindgen, we have also have to make sure the cargo environment
variable is set for each invocation.

To build with Ubuntu's Rust 1.82 packaging:

  CARGO=cargo-1.82 RUSTC=rustc-1.82 RUSTDOC=rustdoc-1.82 \
      ./configure

Note that setting RUSTDOC is only required for commands like "make
check" to pass.

Ticket: #7877
(cherry picked from commit 6d74656bef)
pull/13844/head
Jason Ish 3 months ago committed by Victor Julien
parent cb452434fc
commit 7f49479e9f

@ -1149,6 +1149,81 @@ jobs:
- run: make install-headers
- run: make install-library
ubuntu-24-04-rust-vars:
name: Ubuntu 24.04 (RUSTC+CARGO vars)
runs-on: ubuntu-latest
container: ubuntu:24.04
needs: [prepare-deps]
steps:
- name: Cache ~/.cargo
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ~/.cargo/registry
key: cargo-registry
- name: Determine number of CPUs
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
- name: Install dependencies
run: |
apt update
apt -y install \
autoconf \
automake \
build-essential \
cargo-1.82 \
cbindgen \
clang-14 \
dpdk-dev \
git \
hwloc \
libhwloc-dev \
jq \
libcap-ng-dev \
libevent-dev \
libevent-pthreads-2.1-7 \
libhiredis-dev \
libhyperscan-dev \
libjansson-dev \
libmagic-dev \
libnet1-dev \
libnetfilter-queue-dev \
libnetfilter-queue1 \
libnfnetlink-dev \
libnfnetlink0 \
libnuma-dev \
libpcap-dev \
libpcre2-dev \
libpython3.12 \
libtool \
libyaml-dev \
llvm-14-dev \
make \
parallel \
python-is-python3 \
python3-yaml \
rustc-1.82 \
software-properties-common \
zlib1g \
zlib1g-dev
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- run: git config --global --add safe.directory /__w/suricata/suricata
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
with:
name: prep
path: prep
- run: tar xf prep/libhtp.tar.gz
- run: tar xf prep/suricata-update.tar.gz
- run: tar xf prep/suricata-verify.tar.gz
- run: ./autogen.sh
- run: CARGO=cargo-1.82 RUSTC=rustc-1.82 RUSTDOC=rustdoc-1.82 ./configure --enable-unittests
- run: make -j ${{ env.CPUS }}
- run: make check
- run: python3 ./suricata-verify/run.py -q --debug-failed
- run: make install
- run: make install-headers
- run: make install-library
ubuntu-22-04-cov-ut:
name: Ubuntu 22.04 (unittests coverage)
runs-on: ubuntu-latest

@ -2295,7 +2295,13 @@ fi
# Cargo/Rust
AM_CONDITIONAL([RUST_CROSS_COMPILE], [test "x$cross_compiling" = "xyes"])
AC_PATH_PROG(RUSTC, rustc, "no")
# Check for rustc, respecting RUSTC environment variable
AC_ARG_VAR([RUSTC], [Rustc command])
if test -z "$RUSTC"; then
RUSTC="rustc"
fi
AC_PATH_PROG(RUSTC, $RUSTC, "no")
if test "$RUSTC" = "no"; then
echo ""
echo " ERROR: Rust compiler not found."
@ -2309,11 +2315,26 @@ fi
exit 1
fi
AC_PATH_PROG(CARGO, cargo, "no")
if test "CARGO" = "no"; then
# Check for cargo, respecting CARGO environment variable
AC_ARG_VAR([CARGO], [Cargo command])
if test -z "$CARGO"; then
CARGO="cargo"
fi
AC_PATH_PROG(CARGO, $CARGO, "no")
if test "$CARGO" = "no"; then
AC_MSG_ERROR([cargo required])
fi
# Check for rustdoc, respecting RUSTDOC environment variable
AC_ARG_VAR([RUSTDOC], [Rustdoc command])
if test -z "$RUSTDOC"; then
RUSTDOC="rustdoc"
fi
AC_PATH_PROG(RUSTDOC, $RUSTDOC, "no")
if test "$RUSTDOC" = "no"; then
AC_MSG_ERROR([rustdoc required])
fi
AC_DEFINE([HAVE_RUST],[1],[Enable Rust language])
AM_CONDITIONAL([HAVE_RUST],true)
AC_SUBST([CARGO], [$CARGO])

@ -82,6 +82,7 @@ maintainer-clean-local:
check:
CARGO_HOME="$(CARGO_HOME)" @rustup_home@ \
CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \
RUSTDOC=$(RUSTDOC) \
$(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)"
vendor:
@ -89,18 +90,18 @@ vendor:
if HAVE_CBINDGEN
gen/rust-bindings.h: $(RUST_SURICATA_LIB)
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
CARGO=$(CARGO) cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true
else
gen/rust-bindings.h:
endif
doc:
CARGO_HOME=$(CARGO_HOME) $(CARGO) doc --all-features --no-deps
CARGO_HOME=$(CARGO_HOME) RUSTDOC=$(RUSTDOC) $(CARGO) doc --all-features --no-deps
if HAVE_CBINDGEN
dist/rust-bindings.h:
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
CARGO=$(CARGO) cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
--quiet --output $(abs_top_builddir)/rust/dist/rust-bindings.h
else
dist/rust-bindings.h:
@ -109,5 +110,5 @@ endif
Cargo.toml: Cargo.toml.in
update-lock: Cargo.toml
cargo update
$(CARGO) update
mv Cargo.lock Cargo.lock.in

Loading…
Cancel
Save