gbm.rs ships pre-generated FFI bindings inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Smithay/gbm.rs/llms.txt
Use this file to discover all available pages before exploring further.
gbm-sys/src/bindings.rs, produced by rust-bindgen 0.69 from the bundled gbm-sys/include/gbm.h header. For most projects these pre-generated bindings are the right choice — they build instantly with no additional system tooling required. When you need to target a custom or newer version of libgbm, however, the use_bindgen feature lets you regenerate the bindings at build time directly from your system’s gbm.h.
Sub-Features
Thegbm-sys crate exposes two related feature flags that the top-level gbm crate surface through its own use_bindgen feature.
use_bindgen
Compiles
bindgen 0.69 as a build-dependency and runs it during cargo build to regenerate bindings.rs from gbm-sys/include/gbm.h. The result is written to Cargo’s OUT_DIR and compiled from there — your source tree is untouched.update_bindings
A superset of
use_bindgen. After regenerating, the build script also copies the freshly generated bindings.rs back into gbm-sys/src/bindings.rs, permanently updating the file that is committed to source control. Activate this on gbm-sys directly when you want to refresh the shipped pre-generated bindings.Enabling Bindgen
Enable the feature from your project’sCargo.toml by activating use_bindgen on the top-level gbm crate. This propagates automatically to gbm-sys.
src/bindings.rs inside gbm-sys itself (e.g. when preparing a new release of the crate), enable the feature on gbm-sys directly:
Prerequisites
Before building withuse_bindgen, ensure that Clang and libclang are installed on your system. Bindgen requires them to parse C headers.
On macOS you may also need to export
LIBCLANG_PATH pointing to the LLVM lib directory so that bindgen can locate libclang.dylib.Build Script Logic
Whenuse_bindgen is active, gbm-sys/build.rs performs the following steps at compile time:
Include the GBM header
The build script instructs bindgen to search the
include/ directory (via -Iinclude) and opens gbm.h as the root header.Rebind GBM_BO_IMPORT_* macros as constants
Several GBM import-type identifiers are defined as C preprocessor macros. Bindgen cannot emit typed constants for macros directly, so the build script redefines each one as a proper The
unsigned int constant before unbinding and re-exposing it.rebind_macro helper captures the macro value into a temporary constant, undefines the macro, then redeclares it as a named constant — making it visible to bindgen’s allowlist.Configure and run bindgen
The builder is configured with an allowlist that restricts output to only the GBM-related items, then generates bindings into Cargo’s
OUT_DIR.Generated Items
The bindgen configuration produces the following categories of Rust items:| Allowlist Pattern | What Is Generated |
|---|---|
^gbm_.*$ (types) | Structs, unions, and typedefs for GBM objects (gbm_device, gbm_bo, gbm_surface, etc.) |
^gbm_.*$ (functions) | All public GBM API functions (gbm_create_device, gbm_bo_create, gbm_surface_lock_front_buffer, …) |
GBM_.*|gbm_.* (vars) | Top-level constants and the rebound GBM_BO_IMPORT_* values |
^gbm_.*$ (enums) | GBM enumerations emitted as constified_enum_module — each variant becomes an associated constant inside a module, giving namespaced integer constants |
Layout tests are explicitly disabled with
.layout_tests(false). Bindgen’s generated layout assertions are architecture-specific and would produce incorrect results — or fail to compile — when the bindings are used on an architecture different from the one where they were generated.