Skip to content

Commit

Permalink
Add library and raw-bindings features to lvgl-sys.
Browse files Browse the repository at this point in the history
Correct CROSS_COMPILE target for bindgen
  • Loading branch information
madwizard-thomas committed Nov 13, 2023
1 parent aa88305 commit 4f3fdd8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lvgl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cc = "1.0.79"
bindgen = "0.65.1"

[features]
library = []
raw-bindings = []
use-vendored-config = []
drivers = []
rust_timer = []
10 changes: 9 additions & 1 deletion lvgl-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "library")]
use cc::Build;
#[cfg(feature = "drivers")]
use std::collections::HashSet;
Expand Down Expand Up @@ -41,7 +42,9 @@ fn main() {
font_extra_src: font_extra_src.as_ref().map(PathBuf::as_path),
};

#[cfg(feature = "library")]
compile_library(&conf);

generate_bindings(&conf);
}

Expand All @@ -67,6 +70,7 @@ struct BuildConf<'a> {
font_extra_src: Option<&'a Path>,
}

#[cfg(feature = "library")]
fn compile_library(conf: &BuildConf) {
let vendor = conf.vendor;

Expand Down Expand Up @@ -134,7 +138,10 @@ fn generate_bindings(conf: &BuildConf) {
];

// Set correct target triple for bindgen when cross-compiling
let target = env::var("TARGET").expect("Cargo build scripts always have TARGET");
let target = env::var("CROSS_COMPILE").map_or_else(
|_| env::var("TARGET").expect("Cargo build scripts always have TARGET"),
|c| c.trim_end_matches('-').to_owned(),
);
let host = env::var("HOST").expect("Cargo build scripts always have HOST");
if target != host {
cc_args.push("-target");
Expand Down Expand Up @@ -285,6 +292,7 @@ fn add_font_headers(bindings: bindgen::Builder, dir: Option<&Path>) -> bindgen::
}
}

#[cfg(feature = "library")]
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();
Expand Down
2 changes: 2 additions & 0 deletions lvgl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(feature = "raw-bindings")]
pub fn _bindgen_raw_src() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/bindings.rs"))
}

#[cfg(feature = "library")]
mod string_impl;

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions lvgl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
build = "build.rs"

[dependencies]
lvgl-sys = { version = "0.6.2", path = "../lvgl-sys" }
lvgl-sys = { version = "0.6.2", path = "../lvgl-sys", features = ["library"]}
cty = "0.2.2"
embedded-graphics = { version = "0.8.0", optional = true }
cstr_core = { version = "0.2.6", default-features = false, features = ["alloc"] }
Expand Down Expand Up @@ -77,7 +77,7 @@ unsafe_no_autoinit = []
quote = "1.0.23"
proc-macro2 = "1.0.51"
lvgl-codegen = { version = "0.6.2", path = "../lvgl-codegen" }
lvgl-sys = { version = "0.6.2", path = "../lvgl-sys" }
lvgl-sys = { version = "0.6.2", path = "../lvgl-sys", features = ["raw-bindings"]}

[dev-dependencies]
embedded-graphics-simulator = "0.5.0"
Expand Down

0 comments on commit 4f3fdd8

Please sign in to comment.