gbm.rs links against the system-providedDocumentation 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.
libgbm shared library, so before adding it to your Cargo.toml you need a Linux system with a DRM-capable GPU, the GBM development headers installed, and a working Rust toolchain. The crate targets stable Rust (edition 2021) and is only useful on Linux, where the DRM/KMS kernel subsystem and a compatible Mesa or vendor driver are present.
Install system prerequisites
gbm.rs builds a native C extension (Fedora / RHELArch LinuxVerify the library is discoverable by A version string such as
gbm-sys) that links against libgbm. You must install the GBM development package for your distribution before cargo build will succeed.Debian / Ubuntupkg-config:23.3.5 confirms that libgbm is correctly installed.Add gbm.rs to Cargo.toml
Open your project’s This pulls in gbm.rs with its default feature set (
Cargo.toml and add gbm.rs under [dependencies]:import-wayland, import-egl, and drm-support), which is suitable for most compositor and display-server projects.If you also need to call DRM mode-setting APIs directly from your code, add drm-rs as well:Configure optional feature flags
gbm.rs exposes several Cargo feature flags that control which parts of the API are compiled in. You can opt out of the defaults and selectively re-enable only what you need:
Feature reference
| Feature | Default | Description |
|---|---|---|
import-wayland | ✅ | Enables Device::import_buffer_object_from_wayland. Requires the wayland-server 0.31 crate. Pulls in wayland-backend with the server_system feature. |
import-egl | ✅ | Enables Device::import_buffer_object_from_egl and the EGLImage type alias (*mut libc::c_void). No extra crate dependencies. |
drm-support | ✅ | Implements drm::Device, drm::control::Device, drm::buffer::Buffer, and drm::buffer::PlanarBuffer for Device<T> and BufferObject<T> respectively. Requires drm-rs 0.14. |
use_bindgen | ❌ | Regenerates the low-level FFI bindings from the system gbm.h header at build time using bindgen. Use this when building against a libgbm version that has additions not covered by the pre-generated bindings. |
serde | ❌ | Derives serde::Serialize and serde::Deserialize for BufferObjectFlags. Requires serde 1.0.103 or later. |
Minimal build (no Wayland, no EGL)
If you are building a headless tool, a testing harness, or an application that only needs DRM/KMS with CPU-mapped buffers, you can strip the build down to its essentials:Enabling serde support
To serializeBufferObjectFlags (for example, to store display configuration in a JSON or TOML file), enable the serde feature:gbm.rs links against
-lgbm at compile time via gbm-sys, its internal -sys sub-crate. If libgbm is not found as a system library, the build will fail with a linker error. There is no pure-Rust fallback — a working Mesa installation (or vendor equivalent) is required on the build host as well as the deployment target.