Skip to content

Commit 4581485

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. For cbindgen, we have also have to make sure the cargo environment variable is set for each invocation.
1 parent 30d8ae8 commit 4581485

3 files changed

Lines changed: 106 additions & 11 deletions

File tree

.github/workflows/builds.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,80 @@ jobs:
13361336
- run: make install-headers
13371337
- run: make install-library
13381338

1339+
ubuntu-24-04-rust-vars:
1340+
name: Ubuntu 24.04 (RUSTC+CARGO vars)
1341+
runs-on: ubuntu-latest
1342+
container: ubuntu:24.04
1343+
needs: [prepare-deps]
1344+
steps:
1345+
- name: Cache ~/.cargo
1346+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
1347+
with:
1348+
path: ~/.cargo/registry
1349+
key: cargo-registry
1350+
1351+
- name: Determine number of CPUs
1352+
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV
1353+
1354+
- name: Install dependencies
1355+
run: |
1356+
apt update
1357+
apt -y install \
1358+
autoconf \
1359+
automake \
1360+
build-essential \
1361+
cargo-1.82 \
1362+
cbindgen \
1363+
clang-14 \
1364+
dpdk-dev \
1365+
git \
1366+
hwloc \
1367+
libhwloc-dev \
1368+
jq \
1369+
libcap-ng-dev \
1370+
libevent-dev \
1371+
libevent-pthreads-2.1-7 \
1372+
libhiredis-dev \
1373+
libhyperscan-dev \
1374+
libjansson-dev \
1375+
libmagic-dev \
1376+
libnet1-dev \
1377+
libnetfilter-queue-dev \
1378+
libnetfilter-queue1 \
1379+
libnfnetlink-dev \
1380+
libnfnetlink0 \
1381+
libnuma-dev \
1382+
libpcap-dev \
1383+
libpcre2-dev \
1384+
libpython3.12 \
1385+
libtool \
1386+
libyaml-dev \
1387+
llvm-14-dev \
1388+
make \
1389+
parallel \
1390+
python-is-python3 \
1391+
python3-yaml \
1392+
rustc-1.82 \
1393+
software-properties-common \
1394+
zlib1g \
1395+
zlib1g-dev
1396+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
1397+
- run: git config --global --add safe.directory /__w/suricata/suricata
1398+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
1399+
with:
1400+
name: prep
1401+
path: prep
1402+
- run: tar xf prep/suricata-update.tar.gz
1403+
- run: tar xf prep/suricata-verify.tar.gz
1404+
- run: ./autogen.sh
1405+
- run: CARGO=cargo-1.82 RUSTC=rustc-1.82 RUSTDOC=rustdoc-1.82 ./configure --enable-unittests
1406+
- run: make -j ${{ env.CPUS }}
1407+
- run: make check
1408+
- run: python3 ./suricata-verify/run.py -q --debug-failed
1409+
- run: make install
1410+
- run: make install-headers
1411+
- run: make install-library
1412+
13391413
ubuntu-24-04-cov-ut:
13401414
name: Ubuntu 24.04 (unittests coverage)
13411415
runs-on: ubuntu-latest

configure.ac

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

20692069
# Cargo/Rust
20702070
AM_CONDITIONAL([RUST_CROSS_COMPILE], [test "x$cross_compiling" = "xyes"])
2071-
AC_PATH_PROG(RUSTC, rustc, "no")
2071+
2072+
# Check for rustc, respecting RUSTC environment variable
2073+
AC_ARG_VAR([RUSTC], [Rustc command])
2074+
if test -z "$RUSTC"; then
2075+
RUSTC="rustc"
2076+
fi
2077+
AC_PATH_PROG(RUSTC, $RUSTC, "no")
20722078
if test "$RUSTC" = "no"; then
20732079
echo ""
20742080
echo " ERROR: Rust compiler not found."
@@ -2082,11 +2088,26 @@ fi
20822088
exit 1
20832089
fi
20842090

2085-
AC_PATH_PROG(CARGO, cargo, "no")
2086-
if test "CARGO" = "no"; then
2091+
# Check for cargo, respecting CARGO environment variable
2092+
AC_ARG_VAR([CARGO], [Cargo command])
2093+
if test -z "$CARGO"; then
2094+
CARGO="cargo"
2095+
fi
2096+
AC_PATH_PROG(CARGO, $CARGO, "no")
2097+
if test "$CARGO" = "no"; then
20872098
AC_MSG_ERROR([cargo required])
20882099
fi
20892100

2101+
# Check for rustdoc, respecting RUSTDOC environment variable
2102+
AC_ARG_VAR([RUSTDOC], [Rustdoc command])
2103+
if test -z "$RUSTDOC"; then
2104+
RUSTDOC="rustdoc"
2105+
fi
2106+
AC_PATH_PROG(RUSTDOC, $RUSTDOC, "no")
2107+
if test "$RUSTDOC" = "no"; then
2108+
AC_MSG_ERROR([rustdoc required])
2109+
fi
2110+
20902111
AC_DEFINE([HAVE_RUST],[1],[Enable Rust language])
20912112
AM_CONDITIONAL([HAVE_RUST],true)
20922113
AC_SUBST([CARGO], [$CARGO])

rust/Makefile.am

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ endif
124124

125125
check:
126126
cd $(abs_top_srcdir)/rust && \
127-
$(CARGO_ENV) \
127+
$(CARGO_ENV) RUSTDOC=$(RUSTDOC) \
128128
$(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)"
129129
$(MAKE) check-bindgen-bindings
130130

@@ -151,7 +151,7 @@ if HAVE_BINDGEN
151151
printf "// This file is automatically generated. Do not edit.\n\n" > sys/src/sys.rs
152152
cat sys/src/sys.rs.tmp >> sys/src/sys.rs
153153
rm -f sys/src/sys.rs.tmp
154-
$(CBINDGEN) --quiet --config cbindgen.toml src/jsonbuilder.rs -o gen/jsonbuilder.h
154+
CARGO=$(CARGO) $(CBINDGEN) --quiet --config cbindgen.toml src/jsonbuilder.rs -o gen/jsonbuilder.h
155155
$(BINDGEN) \
156156
-o sys/src/jsonbuilder.rs.tmp \
157157
--rust-target 1.68 \
@@ -172,7 +172,7 @@ endif
172172
if HAVE_CBINDGEN
173173
gen/rust-bindings.h: $(RUST_SURICATA_LIB) cbindgen.toml
174174
cd $(abs_top_srcdir)/rust && \
175-
$(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
175+
CARGO=$(CARGO) $(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
176176
--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true
177177
else
178178
gen/rust-bindings.h:
@@ -181,18 +181,18 @@ endif
181181
if HAVE_CBINDGEN
182182
gen/htp/htp_rs.h: $(RUST_SURICATA_LIB) htp/cbindgen.toml
183183
cd $(abs_top_srcdir)/rust/htp && \
184-
cbindgen --config $(abs_top_srcdir)/rust/htp/cbindgen.toml \
184+
CARGO=$(CARGO) $(CBINDGEN) --config $(abs_top_srcdir)/rust/htp/cbindgen.toml \
185185
--quiet --verify --output $(abs_top_builddir)/rust/gen/htp/htp_rs.h || true
186186
else
187187
gen/htp/htp_rs.h:
188188
endif
189189

190190
doc:
191-
CARGO_HOME=$(CARGO_HOME) $(CARGO) doc --all-features --no-deps
191+
CARGO_HOME=$(CARGO_HOME) RUSTDOC=$(RUSTDOC) $(CARGO) doc --all-features --no-deps
192192

193193
if HAVE_CBINDGEN
194194
dist/rust-bindings.h:
195-
$(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
195+
CARGO=$(CARGO) $(CBINDGEN) --config $(abs_top_srcdir)/rust/cbindgen.toml \
196196
--quiet --output $(abs_top_builddir)/rust/dist/rust-bindings.h
197197
else
198198
dist/rust-bindings.h:
@@ -201,7 +201,7 @@ endif
201201
if HAVE_CBINDGEN
202202
dist/htp/htp_rs.h:
203203
cd $(abs_top_srcdir)/rust/htp && \
204-
cbindgen --config cbindgen.toml \
204+
CARGO=$(CARGO) $(CBINDGEN) --config cbindgen.toml \
205205
--quiet --output $(abs_top_builddir)/rust/dist/htp/htp_rs.h
206206
else
207207
dist/htp/htp_rs.h:
@@ -210,5 +210,5 @@ endif
210210
Cargo.toml: Cargo.toml.in
211211

212212
update-lock: Cargo.toml
213-
cargo update
213+
$(CARGO) update
214214
mv Cargo.lock Cargo.lock.in

0 commit comments

Comments
 (0)