Skip to main content

Documentation 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.rs links against the system-provided 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.
1

Install system prerequisites

gbm.rs builds a native C extension (gbm-sys) that links against libgbm. You must install the GBM development package for your distribution before cargo build will succeed.Debian / Ubuntu
sudo apt-get install libgbm-dev
Fedora / RHEL
sudo dnf install mesa-libgbm-devel
Arch Linux
sudo pacman -S mesa
Verify the library is discoverable by pkg-config:
pkg-config --modversion gbm
A version string such as 23.3.5 confirms that libgbm is correctly installed.
2

Add gbm.rs to Cargo.toml

Open your project’s Cargo.toml and add gbm.rs under [dependencies]:
[dependencies]
gbm = "0.18.0"
This pulls in gbm.rs with its default feature set (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:
[dependencies]
gbm = "0.18.0"
drm = "0.14.0"
3

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:
[dependencies.gbm]
version = "0.18.0"
default-features = false
features = ["drm-support", "import-egl"]

Feature reference

FeatureDefaultDescription
import-waylandEnables Device::import_buffer_object_from_wayland. Requires the wayland-server 0.31 crate. Pulls in wayland-backend with the server_system feature.
import-eglEnables Device::import_buffer_object_from_egl and the EGLImage type alias (*mut libc::c_void). No extra crate dependencies.
drm-supportImplements 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_bindgenRegenerates 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.
serdeDerives 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:
[dependencies.gbm]
version = "0.18.0"
default-features = false
features = ["drm-support"]

Enabling serde support

To serialize BufferObjectFlags (for example, to store display configuration in a JSON or TOML file), enable the serde feature:
[dependencies.gbm]
version = "0.18.0"
features = ["serde"]   # adds to the default set
[dependencies]
serde = { version = "1", features = ["derive"] }
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.

Build docs developers (and LLMs) love