Skip to content

Commit

Permalink
rust: put all rust/cargo env vars in CARGO_ENV
Browse files Browse the repository at this point in the history
To ensure that all calls to cargo use the same environment variables,
put the environment variables in CARGO_ENV so every call to cargo can
easily use the same vars.

The Cargo build system is smarter than make, it can detect a change in
an environment variable that affects the build, and the setting of
SURICATA_LUA_SYS_HEADER_DST changing could cause a rebuild.

Also update suricata-lua-sys, which is smarter about copying headers. It
will only copy if the destination does not exist, or the source header
is newer than the target, which can also prevent unnecessary rebuilds.

This is mainly to fix an issue where subsequent builds may fail,
especially when running an editor with a LSP enabled:

    Update lua crate to 0.1.0-alpha.5. This update will force a rewrite of
    the headers if the env var SURICATA_LUA_SYS_HEADER_DST changes. This
    fixes the issue where the headers may not be written.

    The cause is that Rust dependencies are cached, and if your editor is
    using rust-analyzer, it might cache the build without this var being
    set, so these headers are not available to Suricata. This crate update
    forces the re-run of the Lua build.rs if this env var changes, fixing
    this issue.
  • Loading branch information
jasonish authored and victorjulien committed Nov 21, 2024
1 parent 138898f commit 13841c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions rust/Cargo.lock.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ time = "~0.3.36"

suricata-derive = { path = "./derive", version = "@PACKAGE_VERSION@" }

suricata-lua-sys = { version = "0.1.0-alpha.3" }
suricata-lua-sys = { version = "0.1.0-alpha.5" }

[dev-dependencies]
test-case = "~3.3.1"
28 changes: 14 additions & 14 deletions rust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,24 @@ if RUST_CROSS_COMPILE
RUST_TARGET = --target $(host_triplet)
endif

all-local: Cargo.toml
mkdir -p $(abs_top_builddir)/rust/gen
if HAVE_CYGPATH
cd $(abs_top_srcdir)/rust && \
@rustup_home@ CARGO_HOME="$(CARGO_HOME)" \
CARGO_ENV = @rustup_home@ \
CARGO_HOME="$(CARGO_HOME)" \
CARGO_TARGET_DIR="$(e_rustdir)/target" \
SURICATA_LUA_SYS_HEADER_DST="$(e_rustdir)/gen" \
$(CARGO) build $(RELEASE) \
--features "$(RUST_FEATURES)" $(RUST_TARGET)
SURICATA_LUA_SYS_HEADER_DST="$(e_rustdir)/gen"
else
cd $(abs_top_srcdir)/rust && \
@rustup_home@ CARGO_HOME="$(CARGO_HOME)" \
CARGO_ENV = @rustup_home@ \
CARGO_HOME="$(CARGO_HOME)" \
CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \
SURICATA_LUA_SYS_HEADER_DST="$(abs_top_builddir)/rust/gen" \
SURICATA_LUA_SYS_HEADER_DST="$(abs_top_builddir)/rust/gen"
endif

all-local: Cargo.toml
mkdir -p $(abs_top_builddir)/rust/gen
cd $(abs_top_srcdir)/rust && \
$(CARGO_ENV) \
$(CARGO) build $(RELEASE) $(NIGHTLY_ARGS) \
--features "$(RUST_FEATURES)" $(RUST_TARGET)
endif
if test -e $(RUST_SURICATA_LIBDIR)/suricata.lib; then \
cp -a $(RUST_SURICATA_LIBDIR)/suricata.lib \
$(RUST_SURICATA_LIBDIR)/${RUST_SURICATA_LIBNAME}; \
Expand All @@ -76,12 +77,11 @@ distclean-local:

check:
cd $(abs_top_srcdir)/rust && \
CARGO_HOME="$(CARGO_HOME)" @rustup_home@ \
CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \
$(CARGO_ENV) \
$(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)"

vendor:
CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) vendor
$(CARGO_ENV) $(CARGO) vendor

if HAVE_CBINDGEN
gen/rust-bindings.h: $(RUST_SURICATA_LIB)
Expand Down

0 comments on commit 13841c0

Please sign in to comment.