Make bindings be dynamically generated at compile time

This commit is contained in:
Rafael Caricio 2020-04-10 19:38:07 +02:00
parent d71b8097a4
commit 6da7ca0c19
4 changed files with 13 additions and 9 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
.idea/
lvgl-sys/src/lib.rs

View file

@ -15,3 +15,4 @@ name = "lvgl_sys"
[build-dependencies]
cc = "1.0.50"
bindgen = "0.53.2"

View file

@ -1,5 +1,6 @@
use std::{env, path::PathBuf};
use cc::Build;
use bindgen;
fn main() {
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
@ -9,6 +10,9 @@ fn main() {
let vendor = root_dir.join("vendor");
let src = vendor.join("lvgl").join("src");
// TODO: Make it configurable! Needs to be linked to final proj defs, define as an env var.
let lvgl_config_path = vendor.join("lv_sim_eclipse_sdl");
let mut cfg = Build::new();
cfg.file(src.parent().unwrap().join("lvgl.h"))
@ -16,8 +20,13 @@ fn main() {
.include(&src)
.warnings(false);
// TODO: Make it configurable! Needs to be linked to final proj defs, define as an env var.
cfg.include(vendor.join("lv_sim_eclipse_sdl"));
cfg.include(&lvgl_config_path);
cfg.compile("lvgl");
let cc_args = ["-DLV_CONF_INCLUDE_SIMPLE=1", "-I", lvgl_config_path.to_str().unwrap()];
let _bindings = bindgen::Builder::default()
.header(src.parent().unwrap().join("lvgl.h").to_str().unwrap())
.clang_args(&cc_args)
.generate().expect("Unable to generate bindings");
}

View file

@ -1,7 +0,0 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}