From 6d74656befe20cd939de8a97bfe272efa112c90b Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 2 Sep 2025 10:21:35 -0600 Subject: [PATCH] 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 --- .github/workflows/builds.yml | 74 ++++++++++++++++++++++++++++++++++++ configure.ac | 27 +++++++++++-- rust/Makefile.am | 16 ++++---- 3 files changed, 106 insertions(+), 11 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 1370176285..6f8f6a4433 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -1336,6 +1336,80 @@ 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/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-24-04-cov-ut: name: Ubuntu 24.04 (unittests coverage) runs-on: ubuntu-latest diff --git a/configure.ac b/configure.ac index fb19c26922..40297b4156 100644 --- a/configure.ac +++ b/configure.ac @@ -2068,7 +2068,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." @@ -2082,11 +2088,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]) diff --git a/rust/Makefile.am b/rust/Makefile.am index b4c33d74bc..7bb37c6050 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -124,7 +124,7 @@ endif check: cd $(abs_top_srcdir)/rust && \ - $(CARGO_ENV) \ + $(CARGO_ENV) RUSTDOC=$(RUSTDOC) \ $(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)" $(MAKE) check-bindgen-bindings @@ -151,7 +151,7 @@ if HAVE_BINDGEN printf "// This file is automatically generated. Do not edit.\n\n" > sys/src/sys.rs cat sys/src/sys.rs.tmp >> sys/src/sys.rs rm -f sys/src/sys.rs.tmp - $(CBINDGEN) --quiet --config cbindgen.toml src/jsonbuilder.rs -o gen/jsonbuilder.h + CARGO=$(CARGO) $(CBINDGEN) --quiet --config cbindgen.toml src/jsonbuilder.rs -o gen/jsonbuilder.h $(BINDGEN) \ -o sys/src/jsonbuilder.rs.tmp \ --rust-target 1.68 \ @@ -172,7 +172,7 @@ endif if HAVE_CBINDGEN gen/rust-bindings.h: $(RUST_SURICATA_LIB) cbindgen.toml cd $(abs_top_srcdir)/rust && \ - $(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: @@ -181,18 +181,18 @@ endif if HAVE_CBINDGEN gen/htp/htp_rs.h: $(RUST_SURICATA_LIB) htp/cbindgen.toml cd $(abs_top_srcdir)/rust/htp && \ - cbindgen --config $(abs_top_srcdir)/rust/htp/cbindgen.toml \ + CARGO=$(CARGO) $(CBINDGEN) --config $(abs_top_srcdir)/rust/htp/cbindgen.toml \ --quiet --verify --output $(abs_top_builddir)/rust/gen/htp/htp_rs.h || true else gen/htp/htp_rs.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: @@ -201,7 +201,7 @@ endif if HAVE_CBINDGEN dist/htp/htp_rs.h: cd $(abs_top_srcdir)/rust/htp && \ - cbindgen --config cbindgen.toml \ + CARGO=$(CARGO) $(CBINDGEN) --config cbindgen.toml \ --quiet --output $(abs_top_builddir)/rust/dist/htp/htp_rs.h else dist/htp/htp_rs.h: @@ -210,5 +210,5 @@ endif Cargo.toml: Cargo.toml.in update-lock: Cargo.toml - cargo update + $(CARGO) update mv Cargo.lock Cargo.lock.in