Skip to content

Commit

Permalink
Include kernel header files
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Feb 17, 2024
1 parent 4c6f3c7 commit a2e9135
Show file tree
Hide file tree
Showing 6 changed files with 2,800 additions and 3 deletions.
3 changes: 2 additions & 1 deletion drm-ffi/drm-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ edition = "2021"
[features]
default = []
use_bindgen = ["bindgen", "pkg-config"]
update_bindings = ["use_bindgen"]
use_kernel_sources_for_bindgen = ["use_bindgen"]
update_bindings = ["use_kernel_sources_for_bindgen"]

[build-dependencies]
bindgen = { version = "0.69.1", optional = true }
Expand Down
18 changes: 16 additions & 2 deletions drm-ffi/drm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ mod use_bindgen {

// Create a C include directive
fn include(header: &str) -> String {
format!("#include <{}>", header)
if cfg!(feature = "use_kernel_sources_for_bindgen") {
format!("#include \"./include/{}\"", header)
} else {
format!("#include <{}>", header)
}
}

fn kernel_macros() -> String {
if cfg!(feature = "use_kernel_sources_for_bindgen") {
("#define __user\n").to_string()
} else {
String::new()
}
}

// Create a C constant
Expand Down Expand Up @@ -120,7 +132,9 @@ mod use_bindgen {

// Fully create the header
fn create_header() -> String {
apply_formatting(INCLUDES.iter(), include) + &apply_formatting(MACROS.iter(), rebind_macro)
kernel_macros()
+ &apply_formatting(INCLUDES.iter(), include)
+ &apply_formatting(MACROS.iter(), rebind_macro)
}

pub fn generate_bindings() {
Expand Down
Loading

0 comments on commit a2e9135

Please sign in to comment.