Skip to content

Commit bd23b92

Browse files
committed
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: OISF#7877 (cherry picked from commit 955927f)
1 parent cb45243 commit bd23b92

3 files changed

Lines changed: 103 additions & 7 deletions

File tree

.github/workflows/builds.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,80 @@ jobs:
11491149
- run: make install-headers
11501150
- run: make install-library
11511151

1152+
ubuntu-24-04-rust-vars:
1153+
name: Ubuntu 24.04 (RUSTC+CARGO vars)
1154+
runs-on: ubuntu-latest
1155+
container: ubuntu:24.04
1156+
needs: [prepare-deps]
1157+
steps:
1158+
- name: Cache ~/.cargo
1159+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
1160+
with:
1161+
path: ~/.cargo/registry
1162+
key: cargo-registry
1163+
1164+
- name: Determine number of CPUs
1165+
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
1166+
1167+
- name: Install dependencies
1168+
run: |
1169+
apt update
1170+
apt -y install \
1171+
autoconf \
1172+
automake \
1173+
build-essential \
1174+
cargo-1.82 \
1175+
cbindgen \
1176+
clang-14 \
1177+
dpdk-dev \
1178+
git \
1179+
hwloc \
1180+
libhwloc-dev \
1181+
jq \
1182+
libcap-ng-dev \
1183+
libevent-dev \
1184+
libevent-pthreads-2.1-7 \
1185+
libhiredis-dev \
1186+
libhyperscan-dev \
1187+
libjansson-dev \
1188+
libmagic-dev \
1189+
libnet1-dev \
1190+
libnetfilter-queue-dev \
1191+
libnetfilter-queue1 \
1192+
libnfnetlink-dev \
1193+
libnfnetlink0 \
1194+
libnuma-dev \
1195+
libpcap-dev \
1196+
libpcre2-dev \
1197+
libpython3.12 \
1198+
libtool \
1199+
libyaml-dev \
1200+
llvm-14-dev \
1201+
make \
1202+
parallel \
1203+
python-is-python3 \
1204+
python3-yaml \
1205+
rustc-1.82 \
1206+
software-properties-common \
1207+
zlib1g \
1208+
zlib1g-dev
1209+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1210+
- run: git config --global --add safe.directory /__w/suricata/suricata
1211+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
1212+
with:
1213+
name: prep
1214+
path: prep
1215+
- run: tar xf prep/suricata-update.tar.gz
1216+
- run: tar xf prep/suricata-verify.tar.gz
1217+
- run: ./autogen.sh
1218+
- run: CARGO=cargo-1.82 RUSTC=rustc-1.82 RUSTDOC=rustdoc-1.82 ./configure --enable-unittests
1219+
- run: make -j ${{ env.CPUS }}
1220+
- run: make check
1221+
- run: python3 ./suricata-verify/run.py -q --debug-failed
1222+
- run: make install
1223+
- run: make install-headers
1224+
- run: make install-library
1225+
11521226
ubuntu-22-04-cov-ut:
11531227
name: Ubuntu 22.04 (unittests coverage)
11541228
runs-on: ubuntu-latest

configure.ac

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,13 @@ fi
22952295

22962296
# Cargo/Rust
22972297
AM_CONDITIONAL([RUST_CROSS_COMPILE], [test "x$cross_compiling" = "xyes"])
2298-
AC_PATH_PROG(RUSTC, rustc, "no")
2298+
2299+
# Check for rustc, respecting RUSTC environment variable
2300+
AC_ARG_VAR([RUSTC], [Rustc command])
2301+
if test -z "$RUSTC"; then
2302+
RUSTC="rustc"
2303+
fi
2304+
AC_PATH_PROG(RUSTC, $RUSTC, "no")
22992305
if test "$RUSTC" = "no"; then
23002306
echo ""
23012307
echo " ERROR: Rust compiler not found."
@@ -2309,11 +2315,26 @@ fi
23092315
exit 1
23102316
fi
23112317

2312-
AC_PATH_PROG(CARGO, cargo, "no")
2313-
if test "CARGO" = "no"; then
2318+
# Check for cargo, respecting CARGO environment variable
2319+
AC_ARG_VAR([CARGO], [Cargo command])
2320+
if test -z "$CARGO"; then
2321+
CARGO="cargo"
2322+
fi
2323+
AC_PATH_PROG(CARGO, $CARGO, "no")
2324+
if test "$CARGO" = "no"; then
23142325
AC_MSG_ERROR([cargo required])
23152326
fi
23162327

2328+
# Check for rustdoc, respecting RUSTDOC environment variable
2329+
AC_ARG_VAR([RUSTDOC], [Rustdoc command])
2330+
if test -z "$RUSTDOC"; then
2331+
RUSTDOC="rustdoc"
2332+
fi
2333+
AC_PATH_PROG(RUSTDOC, $RUSTDOC, "no")
2334+
if test "$RUSTDOC" = "no"; then
2335+
AC_MSG_ERROR([rustdoc required])
2336+
fi
2337+
23172338
AC_DEFINE([HAVE_RUST],[1],[Enable Rust language])
23182339
AM_CONDITIONAL([HAVE_RUST],true)
23192340
AC_SUBST([CARGO], [$CARGO])

rust/Makefile.am

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,26 @@ maintainer-clean-local:
8282
check:
8383
CARGO_HOME="$(CARGO_HOME)" @rustup_home@ \
8484
CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \
85+
RUSTDOC=$(RUSTDOC) \
8586
$(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)"
8687

8788
vendor:
8889
CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) vendor
8990

9091
if HAVE_CBINDGEN
9192
gen/rust-bindings.h: $(RUST_SURICATA_LIB)
92-
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
93+
CARGO=$(CARGO) cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
9394
--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true
9495
else
9596
gen/rust-bindings.h:
9697
endif
9798

9899
doc:
99-
CARGO_HOME=$(CARGO_HOME) $(CARGO) doc --all-features --no-deps
100+
CARGO_HOME=$(CARGO_HOME) RUSTDOC=$(RUSTDOC) $(CARGO) doc --all-features --no-deps
100101

101102
if HAVE_CBINDGEN
102103
dist/rust-bindings.h:
103-
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
104+
CARGO=$(CARGO) cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
104105
--quiet --output $(abs_top_builddir)/rust/dist/rust-bindings.h
105106
else
106107
dist/rust-bindings.h:
@@ -109,5 +110,5 @@ endif
109110
Cargo.toml: Cargo.toml.in
110111

111112
update-lock: Cargo.toml
112-
cargo update
113+
$(CARGO) update
113114
mv Cargo.lock Cargo.lock.in

0 commit comments

Comments
 (0)