-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
bindgen: use bindgen to provide Rust bindings to C - v8 #12466
base: master
Are you sure you want to change the base?
Changes from 4 commits
db06234
31aaee8
af17e4a
770cd3c
66e4d98
9844b39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
SUBDIRS = sys | ||
|
||
EXTRA_DIST = src derive \ | ||
.cargo/config.toml.in \ | ||
cbindgen.toml \ | ||
dist/rust-bindings.h \ | ||
vendor \ | ||
Cargo.toml Cargo.lock \ | ||
derive/Cargo.toml | ||
derive/Cargo.toml \ | ||
sys \ | ||
sys/Cargo.toml | ||
|
||
if !DEBUG | ||
RELEASE = --release | ||
|
@@ -75,14 +79,49 @@ clean-local: | |
distclean-local: | ||
rm -rf vendor dist | ||
|
||
check-bindgen-bindings: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a CI test with bindgen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I didn't pull over this test from the previous PR: https://github.com/OISF/suricata/pull/12461/files#diff-73e17259d77e5fbef83b2bdbbe4dc40a912f807472287f7f45b77e0cbf78792d It just rebuilds the bindings to make sure they are up to date. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the CI test I am expecting :-) |
||
if HAVE_BINDGEN | ||
if test "$(top_srcdir)" = "$(top_builddir)"; then \ | ||
cp sys/src/sys.rs sys/src/sys.rs.orig; \ | ||
$(MAKE) update-bindings; \ | ||
if diff sys/src/sys.rs sys/src/sys.rs.orig > /dev/null 2>&1; then \ | ||
rm -f sys/src/sys.rs.orig; \ | ||
else \ | ||
echo "WARNING: bindgen bindings may be out of date"; \ | ||
fi \ | ||
else \ | ||
echo "Not checking bindings for out of tree build"; \ | ||
fi | ||
else | ||
@echo "Unable to check bindgen bindings: bindgen not found" | ||
endif | ||
|
||
check: | ||
cd $(abs_top_srcdir)/rust && \ | ||
$(CARGO_ENV) \ | ||
$(CARGO) test --all $(RELEASE) --features "$(RUST_FEATURES)" | ||
$(MAKE) check-bindgen-bindings | ||
|
||
vendor: | ||
$(CARGO_ENV) $(CARGO) vendor | ||
|
||
update-bindings: | ||
if HAVE_BINDGEN | ||
$(BINDGEN) \ | ||
-o sys/src/sys.rs \ | ||
--rust-target 1.71 \ | ||
--disable-header-comment \ | ||
--default-enum-style rust \ | ||
--allowlist-type 'AppProto.*' \ | ||
--allowlist-function 'AppProto.*' \ | ||
$(abs_top_srcdir)/src/bindgen.h \ | ||
-- \ | ||
-DHAVE_CONFIG_H -I../src -I../rust/gen $(CPPFLAGS) | ||
else | ||
@echo "error: bindgen not installed, can't update bindings" | ||
exit 1 | ||
endif | ||
|
||
if HAVE_CBINDGEN | ||
gen/rust-bindings.h: $(RUST_SURICATA_LIB) | ||
cd $(abs_top_srcdir)/rust && \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
//! This module exposes items from the core "C" code to Rust. | ||
use std; | ||
use suricata_sys::sys::{AppProto, AppProtoEnum}; | ||
|
||
use crate::filecontainer::*; | ||
use crate::flow::Flow; | ||
|
||
|
@@ -41,11 +43,8 @@ pub const STREAM_GAP: u8 = 0x10; | |
pub const STREAM_DEPTH: u8 = 0x20; | ||
pub const STREAM_MIDSTREAM:u8 = 0x40; | ||
|
||
// Application layer protocol identifiers (app-layer-protos.h) | ||
pub type AppProto = u16; | ||
|
||
pub const ALPROTO_UNKNOWN : AppProto = 0; | ||
pub const ALPROTO_FAILED : AppProto = 1; | ||
pub const ALPROTO_UNKNOWN : AppProto = AppProtoEnum::ALPROTO_UNKNOWN as AppProto; | ||
pub const ALPROTO_FAILED : AppProto = AppProtoEnum::ALPROTO_FAILED as AppProto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh |
||
|
||
pub const IPPROTO_TCP : u8 = 6; | ||
pub const IPPROTO_UDP : u8 = 17; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check bindgen version ?