Adding drm-rs to a Rust project is straightforward: a single line inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Smithay/drm-rs/llms.txt
Use this file to discover all available pages before exploring further.
Cargo.toml pulls in the high-level API crate with all of its dependencies, including the low-level ioctl wrappers and pre-generated kernel bindings. No system library needs to be installed because drm-rs does not link against libdrm — it speaks directly to the kernel. The sections below cover the basic dependency declaration, the structure of the three-crate workspace, the optional use_bindgen feature flag, and the minimum environment requirements.
Basic Installation
Add the following to your project’sCargo.toml:
drm crate re-exports the full high-level API for both basic device access (drm::Device) and kernel mode setting (drm::control::Device). Run cargo build to fetch and compile the crate and its transitive dependencies from crates.io.
Full Dependency Block
The current release is drm 0.15.0. If you want to pin to the exact patch version, use:"0.15" range (without a patch component) accepts any 0.15.x release, which is the recommended form for most projects.
Workspace Crate Structure
The drm-rs repository is a Cargo workspace of three crates. Understanding this structure helps you decide whether you need to depend on any of the lower-level crates directly.drm v0.15.0 — High-Level Safe API
This is the crate almost every project should depend on. It provides:
- The
drm::Devicetrait for basic device operations (driver info, master lock, vblank waits, capability queries). - The
drm::control::Devicetrait for the full KMS/modesetting API (connectors, CRTCs, encoders, planes, framebuffers, atomic commits, page flips). - Safe Rust types for all DRM objects (
Mode,Handle,Infostructs, etc.). - The
drm::buffermodule andDumbBufferfor software-rendered scanout buffers. - The
drm::nodemodule for working with primary and render node paths.
drm-ffi v0.9.1 — Low-Level Safe ioctl Wrappers
drm-ffi sits between drm and the raw C bindings. It wraps every DRM ioctl in a safe Rust function that handles argument marshalling and error conversion, but does not add higher-level abstractions like typed handles or iterator adapters. You should depend on this crate directly only if you need to call an ioctl that the drm crate does not yet expose.
drm-sys v0.8.1 — Raw C Bindgen Bindings
drm-sys contains the auto-generated Rust bindings to the DRM kernel UAPI headers. It exposes raw C structs, constants, and type aliases exactly as they appear in the kernel headers. Direct use of this crate is rarely necessary; prefer drm-ffi or drm instead.
The use_bindgen Feature Flag
By default, drm-sys ships with pre-generated bindings that are bundled inside the crate source. These cover all stable DRM UAPI definitions up to the kernel version targeted at release time and require no additional build tooling.
If you need bindings generated from your system’s installed DRM headers — for example, because you are targeting a very recent kernel with new DRM features not covered by the bundled headers — you can enable the use_bindgen feature:
drm → drm-ffi → drm-sys), which causes drm-sys’s build script to invoke bindgen against the DRM headers found via pkg-config on the host system. The bindgen and pkg-config crates are pulled in automatically as build dependencies when the feature is active.
When to Use use_bindgen
| Situation | Recommendation |
|---|---|
| Standard desktop or embedded Linux project | Use the default (pre-generated) bindings |
| Targeting a kernel newer than the bundled headers | Enable use_bindgen |
| CI running on a minimal environment without DRM headers | Use the default; avoid use_bindgen |
| Contributing to drm-rs itself and updating headers | Use update_bindings feature in drm-sys directly |
Minimum Supported Rust Version (MSRV)
drm-rs requires Rust 1.70 or newer. This version is specified in therust-version field of each crate’s Cargo.toml. If your toolchain is older, update it with:
Platform Requirements
drm-rs is designed for operating systems that expose the DRM subsystem:- Linux — Primary and fully supported platform. Device nodes are located at
/dev/dri/card*(primary nodes) and/dev/dri/renderD*(render nodes). - FreeBSD — Supported. The DRM subsystem is available and exposes compatible device nodes.
- DragonFly BSD — Supported. Requires the
drm-kmodpackage to be installed.
/dev/dri/card0 is owned by root and the video group. Add your user to the video group, or use a seat manager such as logind or seatd that can hand you an already-opened file descriptor.