Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft -- lua: example of using crate to vendor/bundle lua 5.4.6 - v0 #10843

Closed
wants to merge 5 commits into from

Conversation

jasonish
Copy link
Member

Use a Rust crate to bundle Lua.

I first started using mlua (https://crates.io/crates/mlua) but it requires too new of a Rust toolchain and bundles multiple versions, so has a larger footprint than we need. Instead I created a minimal crate: https://github.com/jasonish/suricata-lua-sys

Might need fixups for other platforms not covered by GitHub CI.

Comment on lines +1984 to +1881
AC_DEFINE([HAVE_LUA], [1], [lua support available])
AM_CONDITIONAL([HAVE_LUA], [true])
AC_SUBST([LUA_INT8], ["lua_int8"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easy to keep a --disable-lua. What is harder is letting a distribution opt-out of our Lua in favor of theirs. I'm tempted to not support that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the "lua_int8" feature can go away now that we pin to a specific version of Lua.

Comment on lines +56 to +58
mkdir -p $(abs_top_builddir)/rust/gen
cp -a $(RUST_SURICATA_LIBDIR)/build/suricata-lua-sys-*/out/lua/*.h \
$(abs_top_builddir)/rust/gen/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit janky but I don't have a better way at this time.

Comment on lines -87 to 92
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
cd $(abs_top_srcdir)/rust && \
cbindgen --config $(abs_top_srcdir)/rust/cbindgen.toml \
--quiet --verify --output $(abs_top_builddir)/rust/gen/rust-bindings.h || true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not related, but needs to be done in master as part of the other PR that change the dist pattern for Rust.

Comment on lines +124 to +125
#[allow(unused_imports)]
pub use suricata_lua_sys;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we keep Lua library into the resulting binary without actually using it. Needs comment stating this.

@@ -67,6 +67,8 @@ time = "=0.3.20"

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

suricata-lua-sys = { git = "https://github.com/jasonish/suricata-lua-sys", version = "0.1.0-alpha.1" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo contains a copy of the Lua source. We could also use a git sub-module, but that does open us up to breakage by upstream still. So I opt to create a copy, so we're in full control.

Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 81.52%. Comparing base (784ce30) to head (b47197e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10843      +/-   ##
==========================================
- Coverage   82.83%   81.52%   -1.31%     
==========================================
  Files         913      928      +15     
  Lines      246847   254189    +7342     
==========================================
+ Hits       204474   207226    +2752     
- Misses      42373    46963    +4590     
Flag Coverage Δ
fuzzcorpus 61.56% <0.00%> (-2.74%) ⬇️
suricata-verify 60.37% <0.00%> (-1.73%) ⬇️
unittests 61.22% <33.33%> (-1.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 20062

@satta
Copy link
Contributor

satta commented Apr 15, 2024

Interesting. Are you planning to still support a way to optionally use an external Lua library?

@victorjulien
Copy link
Member

victorjulien commented Apr 15, 2024

My CI results are showing multiple failures:

FreeBSD 14:

gmake[2]: Leaving directory '/var/tmp/gitlab_runner/builds/Tys3Svbf/0/inliniac/suricata-ci/suricata/suricata-8.0.0-dev/_build/sub'
rm -f config.status config.cache config.log configure.lineno config.status.lineno
rm -f Makefile
ERROR: files left in build directory after distclean:
./rust/gen/lapi.h
./rust/gen/lauxlib.h
./rust/gen/lcode.h
./rust/gen/lctype.h
./rust/gen/ldebug.h
./rust/gen/ldo.h
./rust/gen/lfunc.h
./rust/gen/lgc.h
./rust/gen/ljumptab.h
./rust/gen/llex.h
./rust/gen/llimits.h
./rust/gen/lmem.h
./rust/gen/lobject.h
./rust/gen/lopcodes.h
./rust/gen/lopnames.h
./rust/gen/lparser.h
./rust/gen/lprefix.h
./rust/gen/lstate.h
./rust/gen/lstring.h
./rust/gen/ltable.h
./rust/gen/ltm.h
./rust/gen/lua.h
./rust/gen/luaconf.h
./rust/gen/lualib.h
./rust/gen/lundump.h
./rust/gen/lvm.h
./rust/gen/lzio.h
gmake[1]: *** [Makefile:789: distcleancheck] Error 1
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/Tys3Svbf/0/inliniac/suricata-ci/suricata/suricata-8.0.0-dev/_build/sub'
gmake: *** [Makefile:718: distcheck] Error 1

CentOS 7

error: failed to run custom build command for `suricata-lua-sys v0.1.0-alpha.1 (https://github.com/jasonish/suricata-lua-sys#fc4a2514)`
Caused by:
  process didn't exit successfully: `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-4974b882693dc352/build-script-build` (exit status: 101)
  --- stdout
  make[2]: Entering directory `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-045c6a5505d024b6/out/lua'
  Guessing Linux
  make[3]: Entering directory `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-045c6a5505d024b6/out/lua'
  make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl"
  make[4]: Entering directory `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-045c6a5505d024b6/out/lua'
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lapi.o lapi.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC  -c lcode.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lctype.o lctype.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ldebug.o ldebug.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ldo.o ldo.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ldump.o ldump.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lfunc.o lfunc.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lgc.o lgc.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC  -c llex.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lmem.o lmem.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lobject.o lobject.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lopcodes.o lopcodes.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC  -c lparser.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lstate.o lstate.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lstring.o lstring.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ltable.o ltable.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ltm.o ltm.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lundump.o lundump.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lvm.o lvm.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lzio.o lzio.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lauxlib.o lauxlib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lbaselib.o lbaselib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lcorolib.o lcorolib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ldblib.o ldblib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o liolib.o liolib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lmathlib.o lmathlib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o loadlib.o loadlib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o loslib.o loslib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o lstrlib.o lstrlib.c
  gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -fPIC   -c -o ltablib.o ltablib.c
  make[3]: Leaving directory `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-045c6a5505d024b6/out/lua'
  make[2]: Leaving directory `/builds/inliniac/suricata-ci/suricata/rust/target/release/build/suricata-lua-sys-045c6a5505d024b6/out/lua'
  --- stderr
  make[4]: *** write jobserver: Bad file descriptor.  Stop.
  make[4]: *** Waiting for unfinished jobs....
  make[4]: *** write jobserver: Bad file descriptor.  Stop.
  make[3]: *** [linux-noreadline] Error 2
  make[2]: *** [guess] Error 2
  thread 'main' panicked at 'build failed', /root/.cargo/git/checkouts/suricata-lua-sys-6aea8b1391be3cf8/fc4a251/build.rs:34:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
make[1]: *** [all-local] Error 101
make[1]: Leaving directory `/builds/inliniac/suricata-ci/suricata/rust'
make: *** [all-recursive] Error 1

Debian Buster Arm 32:

Test LuaMatchTest01                                               : STREAM MEMORY IN USE 33792
FAILED
Test LuaMatchTest01a                                              : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is 'O') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest02                                               : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '�D2���.�E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest02a                                              : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '��6��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '��9��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest03                                               : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '��=��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest03a                                              : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '0�A��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest04                                               : FAILED
Test LuaMatchTest04a                                              : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '��E��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest05                                               : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '8wI��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '�[M��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest05a                                              : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is 'h@Q��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest06                                               : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is '') [DetectLuaSetupPrime:detect-lua.c:720]
FAILED
Test LuaMatchTest06a                                              : FAILED
Test DetectIPRepTest01                                            : Error: detect-lua: couldn't load file: attempt to load a text chunk (mode is 'P	Y��-�]E') [DetectLuaSetupPrime:detect-lua.c:720]
pass

Debian 12 (arm64)

Test LuaMatchTest01                                               : /usr/bin/bash: line 175: 25690 Segmentation fault      (core dumped) ./src/suricata -u -l /tmp/

scan-build 16 (ubuntu 23.10)

reports 4 new bugs/warnings, but doesn't show them. Could they be hidden by cargo?

@suricata-qa
Copy link

Information:

ERROR: QA failed on SURI_TLPW2_autofp_suri_time.

ERROR: QA failed on SURI_TLPR1_alerts_cmp.

field baseline test %
SURI_TLPW2_autofp_stats_chk
.uptime 138 143 103.62%

Pipeline 20064

@jasonish
Copy link
Member Author

jasonish commented Apr 15, 2024

My CI results are showing multiple failures:

Yes. As expected. This is more about review of the bundling technique. I'll probably need access to each failing setup to fix that those. But first let's decide if this a method of bundling.

The other option is just copying the Lua source right into ours.

@jasonish
Copy link
Member Author

scan-build 16 (ubuntu 23.10)

reports 4 new bugs/warnings, but doesn't show them. Could they be hidden by cargo?

Probably in the Lua source.

Remove lua-dev(el) from all CI tests.
The vendored Lua code triggers some scan-build failures, so exclude
the rust/ directory for now. Might want to look at these separately
though.
@jasonish
Copy link
Member Author

Interesting. Are you planning to still support a way to optionally use an external Lua library?

Not really. It would be hard around what includes to use, etc. The other option for vendoring is to pull the Lua source right in, in which case it would be a little easier. But my question, is to what value? Is the effort worth it?

@satta
Copy link
Contributor

satta commented Apr 15, 2024

Interesting. Are you planning to still support a way to optionally use an external Lua library?

[...]

But my question, is to what value? Is the effort worth it?

Not sure. In Debian it is generally frowned upon to build using vendored code. Mainly because that means having to identify, patch and rebuild binary packages when security updates to vendored code are released. But given the fact that we already build a lot of vendored Rust code I don't think adding Lua would matter much (or is worth patching Suricata within Debian).

Remove maintainer-clean-local, this is not needed.

In distclean-local, remove "rust/dist" and "rust/vendor" as they are
created during "make dist".

In "clean-local", remove "rust/target" and "rust/gen" as they are
created during a normal "make".
Modify the CentOS 9 Stream build to not have cbdingen available, as
its already building from the dist.  But add a "make clean" followed
by a "make" to test that it still builds after a clean.
@jasonish
Copy link
Member Author

Continued at #10854.

@jasonish jasonish closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants