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

Commits on Nov 21, 2024

  1. rust: integrate bindgen to generate rust bindings to C

    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.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    51b972a View commit details
    Browse the repository at this point in the history
  2. app-layer: rename AppLayerEventType to SCAppLayerEventType

    Follow the naming scheme for public exports.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    4adaef3 View commit details
    Browse the repository at this point in the history
  3. app-layer: remove prototypes from decode.h

    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.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    d810bed View commit details
    Browse the repository at this point in the history
  4. bindgen: export SCAppLayerStateGetEventInfoByIdFn from C to Rust

    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.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    2c05b35 View commit details
    Browse the repository at this point in the history
  5. bindgen: export AppProto and AppProtoEnum to Rust

    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 committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    3ff6063 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    ec9ab02 View commit details
    Browse the repository at this point in the history
  7. bindgen: use bindgen-cli instead of library

    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.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    748fb24 View commit details
    Browse the repository at this point in the history
  8. bindgen: use --allowlist-type instead of --allowlist-item

    The bindgen found in Ubuntu 24.04 and older is not new enough for
    --allowlist-item.
    jasonish committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    199db46 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    154e6b3 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    4e75afe View commit details
    Browse the repository at this point in the history