2020-04-10 18:34:07 +00:00
|
|
|
use std::{env, path::PathBuf, path::Path};
|
2020-04-10 17:12:10 +00:00
|
|
|
use cc::Build;
|
2020-04-10 17:38:07 +00:00
|
|
|
use bindgen;
|
2020-04-10 17:12:10 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
|
|
|
.canonicalize()
|
|
|
|
.unwrap();
|
|
|
|
let root_dir = project_dir.parent().unwrap();
|
|
|
|
let vendor = root_dir.join("vendor");
|
2020-04-11 11:06:16 +00:00
|
|
|
let lvgl_sys_src = root_dir.join("lvgl-sys").join("src");
|
2020-04-10 17:12:10 +00:00
|
|
|
let src = vendor.join("lvgl").join("src");
|
|
|
|
|
2020-04-10 17:38:07 +00:00
|
|
|
// 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");
|
|
|
|
|
2020-04-10 17:12:10 +00:00
|
|
|
let mut cfg = Build::new();
|
|
|
|
|
2020-04-10 18:34:07 +00:00
|
|
|
add_c_files(&mut cfg, src.join("lv_core"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_draw"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_font"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_hal"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_misc"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_objx"));
|
|
|
|
add_c_files(&mut cfg, src.join("lv_themes"));
|
|
|
|
|
|
|
|
cfg.define("LV_CONF_INCLUDE_SIMPLE", Some("1"))
|
2020-04-10 17:12:10 +00:00
|
|
|
.include(&src)
|
2020-04-10 17:48:21 +00:00
|
|
|
.warnings(false)
|
|
|
|
.include(&lvgl_config_path)
|
|
|
|
.compile("lvgl");
|
2020-04-10 17:38:07 +00:00
|
|
|
|
|
|
|
let cc_args = ["-DLV_CONF_INCLUDE_SIMPLE=1", "-I", lvgl_config_path.to_str().unwrap()];
|
2020-04-10 17:48:21 +00:00
|
|
|
bindgen::Builder::default()
|
2020-04-10 17:38:07 +00:00
|
|
|
.header(src.parent().unwrap().join("lvgl.h").to_str().unwrap())
|
|
|
|
.clang_args(&cc_args)
|
2020-04-10 17:48:21 +00:00
|
|
|
.generate()
|
|
|
|
.expect("Unable to generate bindings")
|
2020-04-11 11:06:16 +00:00
|
|
|
.write_to_file(lvgl_sys_src.join("bindings.rs"))
|
2020-04-10 17:48:21 +00:00
|
|
|
.expect("Can't write bindings!");
|
2020-04-10 17:12:10 +00:00
|
|
|
}
|
2020-04-10 18:34:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
fn add_c_files(build: &mut cc::Build, path: impl AsRef<Path>) {
|
|
|
|
for e in path.as_ref().read_dir().unwrap() {
|
|
|
|
let e = e.unwrap();
|
|
|
|
let path = e.path();
|
|
|
|
if e.file_type().unwrap().is_dir() {
|
|
|
|
// skip dirs for now
|
|
|
|
} else if path.extension().and_then(|s| s.to_str()) == Some("c") {
|
|
|
|
build.file(&path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|