Skip to main content

dpdk_sys/
lib.rs

1//! Raw FFI bindings to DPDK (Data Plane Development Kit)
2//!
3//! This crate provides low-level bindings to DPDK. It operates in two modes:
4//!
5//! ## With DPDK installed (bindgen feature)
6//!
7//! When compiled with the `bindgen` feature and DPDK is installed, this crate
8//! generates real FFI bindings using bindgen:
9//!
10//! ```toml
11//! [dependencies]
12//! dpdk-sys = { version = "0.1", features = ["bindgen"] }
13//! ```
14//!
15//! ## Without DPDK (default)
16//!
17//! By default, this crate provides stub implementations that allow development
18//! and testing without requiring DPDK to be installed. The stubs provide the
19//! same API but don't perform actual packet I/O.
20//!
21//! ## Environment Variables
22//!
23//! - `DPDK_PATH`: Path to DPDK installation (e.g., `/usr/local/dpdk`)
24//! - `PKG_CONFIG_PATH`: Can be set to help pkg-config find DPDK
25
26#![allow(non_upper_case_globals)]
27#![allow(non_camel_case_types)]
28#![allow(non_snake_case)]
29#![allow(dead_code)]
30#![allow(clippy::all)]
31
32// When bindgen generates real bindings, include them
33#[cfg(dpdk_bindgen)]
34include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
35
36// Shim: wrappers for static inline functions and macro constants that
37// bindgen cannot capture.  Only needed with real DPDK.
38#[cfg(dpdk_bindgen)]
39mod shim;
40
41#[cfg(dpdk_bindgen)]
42pub use shim::*;
43
44// When using stubs (default), use our manual definitions
45#[cfg(dpdk_stubs)]
46mod stubs;
47
48#[cfg(dpdk_stubs)]
49pub use stubs::*;
50
51// Re-export libc types commonly used with DPDK
52pub use libc::{c_char, c_int, c_uint, c_void, size_t, ssize_t};
53
54/// Check if real DPDK bindings are being used
55#[inline]
56pub const fn is_real_dpdk() -> bool {
57    cfg!(dpdk_bindgen)
58}
59
60/// Check if stub implementations are being used
61#[inline]
62pub const fn is_stub() -> bool {
63    cfg!(dpdk_stubs)
64}