Skip to content

Commit 43d509f

Browse files
committed
Use custom generated bindings
1 parent 0a24a0b commit 43d509f

File tree

8 files changed

+2993
-26
lines changed

8 files changed

+2993
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
linux
3+
temp

Cargo.lock

Lines changed: 117 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ include = ["src/**/*.rs", "README.md", "LICENSE"]
1717
tracing = ["dep:tracing"]
1818

1919
[dependencies]
20-
drm-sys = "0.8.0"
2120
rustix = { version = "0.38.44", default-features = false, features = [
2221
"mm",
2322
"std",

gen/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
anyhow = "1.0.95"
8+
bindgen = "0.71.1"
9+
tempfile = "3.16.0"
10+
xshell = "0.2.7"

gen/src/bindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <drm/drm.h>
2+
#include <drm/drm_mode.h>

gen/src/main.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1-
fn main() {
2-
println!("Hello, world!");
1+
use std::fs;
2+
3+
use anyhow::Result;
4+
use tempfile::TempDir;
5+
use xshell::{cmd, Shell};
6+
7+
const VERSION: &str = "v6.13";
8+
9+
fn main() -> Result<()> {
10+
let sh = Shell::new()?;
11+
12+
if !fs::exists("linux/.git")? {
13+
cmd!(
14+
sh,
15+
"git clone --filter=tree:0 --no-checkout https://github.com/torvalds/linux.git"
16+
)
17+
.run()?;
18+
}
19+
20+
sh.change_dir("linux");
21+
22+
cmd!(sh, "git fetch origin tag {VERSION}").run()?;
23+
cmd!(sh, "git checkout {VERSION}").run()?;
24+
25+
let temp_dir = TempDir::with_prefix("diretto-linux-bindings-")?;
26+
let work_dir = temp_dir.path();
27+
28+
cmd!(sh, "make headers_install INSTALL_HDR_PATH={work_dir}").run()?;
29+
30+
let bindings = bindgen::builder()
31+
.clang_arg(format!("-I{}", work_dir.join("include").display()))
32+
.header("src/bindings.h")
33+
.use_core()
34+
.generate()?;
35+
36+
bindings.write_to_file("../src/sys.rs")?;
37+
38+
Ok(())
339
}

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use std::{
88
slice,
99
};
1010

11-
use drm_sys::{
11+
#[allow(nonstandard_style)]
12+
pub mod sys;
13+
14+
use sys::{
1215
drm_mode_card_res, drm_mode_create_dumb, drm_mode_crtc, drm_mode_fb_cmd,
1316
drm_mode_get_connector, drm_mode_get_encoder, drm_mode_get_plane_res, drm_mode_map_dumb,
1417
drm_mode_modeinfo, drm_version, DRM_IOCTL_BASE,

0 commit comments

Comments
 (0)