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

bindgen-cli: alternate use of bindgen - v1 #12139

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jasonish
Copy link
Member

Like #12062, but uses the bindgen-cli tool.

Currently requires it to exist, but the idea is that a distribution archive would provide the bindings, meaning users of the release would not require bindgen to be install (and the clang tooling it requires).

Draft as I'm figuring out some Windows issue, also an issue on the other PR.

@jasonish jasonish force-pushed the bindgen-cli/v1 branch 3 times, most recently from b64eeb7 to 4869aff Compare November 20, 2024 23:18
Comment on lines +2273 to +2276
AC_PATH_PROG([BINDGEN], [bindgen], [no])
if test "x$BINDGEN" = "xno"; then
AC_MSG_ERROR([bindgen required])
fi
Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is that when building from a distribution archive this wouldn't be required. Just like cbindgen.

@jasonish jasonish force-pushed the bindgen-cli/v1 branch 2 times, most recently from eac1b70 to e4ccf11 Compare November 20, 2024 23:34
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.05%. Comparing base (13841c0) to head (4e75afe).

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #12139       +/-   ##
===========================================
+ Coverage   49.77%   75.05%   +25.27%     
===========================================
  Files         909      848       -61     
  Lines      257884   155587   -102297     
===========================================
- Hits       128367   116775    -11592     
+ Misses     129517    38812    -90705     
Flag Coverage Δ
fuzzcorpus 60.93% <87.50%> (-0.01%) ⬇️
livemode 19.43% <12.50%> (-0.01%) ⬇️
pcap 44.39% <56.25%> (-0.02%) ⬇️
suricata-verify 62.70% <87.50%> (+0.01%) ⬆️
unittests ?

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

---- 🚨 Try these New Features:

@suricata-qa
Copy link

ERROR:

ERROR: QA failed on build_asan.

Pipeline 23468

@suricata-qa
Copy link

ERROR:

ERROR: QA failed on build_asan.

Pipeline 23469

@ct0br0 ct0br0 added the skip qa label Nov 21, 2024
Add a minimal integration of bindgen to the build.

Bindgen is integrated at compile time with a "build.rs" file that for
now only generates AppLayerEventType Rust bindings.

This required some refactoring of the C so app-layer-events.h did not
also include "rust.h", which causes issues for bindgen, probably
related to circular references.

AppLayerEventType was chosen as the first step as its an argument type
some app-layer functions that we may want to use bindgen to export
Rust, and one of the requirements of bindgen might be that C functions
should only use datatypes defined in C, and not Rust. Following such a
rule also prevents circular dependencies between Rust and C code.

Bindgen generates the bindings in a file named "bindings.rs" in the
target/ direction, which "sys.rs" will statically "include" at
compiling name, making these bindings available under package
"crate::sys".

"build.rs" had to be placed in the non-standard location of
"src/build.rs" (its usually alongside Cargo.toml) to satisfy the
out-of-tree build requirements of distcheck.

Note that bindgen is also available as a command line tool which could
be used instead of integrating this at compile time, however the tool
requires a newer version of Rust than our MSRV, and may present
additional issues with respect to autoconf and distcheck.
Follow the naming scheme for public exports.
This lets us remove decode.h from app-layer-events.h as pulling in
app-layer-events.h shouldn't result in pulling in dpdk, and other
includes not related to app-layer-events.

decode.h also doesn't need those forward declarations anymore due to
previous changes.
Instead of defining this function pointer in type in Rust, and having
it in C signatures, create a type and export it to Rust.

To facilitate this, and new header has been creates,
"app-layer-types.h", this is to avoid the circular reference of C
headers pulling in "rust.h" which are required to generate Rust
bindings.
This exposes the C define ALPROTO values to Rust without having to
perform some runtime initialization with init_ffi.

As app-layer-protos.h was clean of a circular reference to rust.h we
could use it directly, it just needed the addition of
suricata-common.h.
@jasonish jasonish force-pushed the bindgen-cli/v1 branch 4 times, most recently from 587acd0 to 3f1f490 Compare November 21, 2024 18:13
Replace bindgen usage from build.rs with the bindgen-cli program much
like we use cbindgen.

As bindgen can only accept one header file, we construct a
pseudo-header file of all the headers that need to be
consumed. Makefile dependency checking is done to make sure the
pseudo-header is only generated as needed to avoid rebuilding every
time.

Special handling is required for Windows to use the Windows path.
The bindgen found in Ubuntu 24.04 and older is not new enough for
--allowlist-item.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants