forked from linebender/glazier
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
68 lines (61 loc) · 2.1 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#[cfg(not(all(
any(feature = "x11", feature = "wayland"),
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
)))]
fn main() {}
#[cfg(all(
any(feature = "x11", feature = "wayland"),
any(target_os = "freebsd", target_os = "linux", target_os = "openbsd")
))]
fn main() {
use pkg_config::probe_library;
use std::env;
use std::path::PathBuf;
let xkbcommon = probe_library("xkbcommon").unwrap();
#[cfg(feature = "x11")]
probe_library("xkbcommon-x11").unwrap();
let mut header = "\
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon-names.h>
#include <xkbcommon/xkbcommon.h>"
.to_string();
if cfg!(feature = "x11") {
header += "
#include <xkbcommon/xkbcommon-x11.h>";
}
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header_contents("wrapper.h", &header)
.clang_args(
xkbcommon
.include_paths
.iter()
.filter_map(|path| path.to_str().map(|s| format!("-I{s}"))),
)
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.prepend_enum_name(false)
.size_t_is_usize(true)
.allowlist_function("xkb_.*")
.allowlist_type("xkb_.*")
.allowlist_var("XKB_.*")
.allowlist_type("xcb_connection_t")
// this needs var args
.blocklist_function("xkb_context_set_log_fn")
// we use FILE from libc
.blocklist_type("FILE")
.blocklist_type("va_list")
.default_enum_style(bindgen::EnumVariation::NewType {
is_bitfield: true,
is_global: false,
})
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/xkbcommon.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("xkbcommon_sys.rs"))
.expect("Couldn't write bindings!");
}