]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: respect RUSTC and CARGO env vars like CC
authorJason Ish <jason.ish@oisf.net>
Tue, 2 Sep 2025 16:21:35 +0000 (10:21 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 4 Sep 2025 02:50:57 +0000 (04:50 +0200)
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
configure.ac
rust/Makefile.am

index 13701762859e96118b8de3349db0c0baf4d2dcf4..6f8f6a44331c9bd24dd95f35f7b0b69dadea1e48 100644 (file)
@@ -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
index fb19c26922d586998945e07bd6ed5f6b66a13139..40297b4156f9e575b9a8b8da4da32d60dc10616c 100644 (file)
@@ -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])
index b4c33d74bc0faf590c54990592f8e0fd1309f276..7bb37c6050590833d7627056d40aaa50e52e36ec 100644 (file)
@@ -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