Use lvgl-codegen
This commit is contained in:
parent
9b68e734eb
commit
43f2a2d4c4
6 changed files with 37 additions and 48 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ examples/demo/target/
|
|||
lvgl-sys/target/
|
||||
lvgl/target/
|
||||
lvgl-sys/src/bindings.rs
|
||||
lvgl/src/widgets/generated.rs
|
||||
|
|
|
@ -8,11 +8,6 @@ license = "MIT"
|
|||
publish = false
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
name = "lvgl_codegen"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
regex = "1.3.9"
|
||||
quote = "1.0.7"
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
use lvgl_codegen::{CodeGen, Rusty};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let rs = Path::new(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../lvgl/src/widgets/generated.rs"
|
||||
));
|
||||
|
||||
let codegen = CodeGen::new().unwrap();
|
||||
|
||||
let widgets_impl: Vec<TokenStream> = codegen
|
||||
|
@ -15,5 +23,11 @@ fn main() {
|
|||
#(#widgets_impl)*
|
||||
};
|
||||
|
||||
println!("{}", code.to_string());
|
||||
let mut file = File::create(rs).unwrap();
|
||||
writeln!(
|
||||
file,
|
||||
"/* automatically generated by lvgl-codegen */\n{}",
|
||||
code
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ license = "MIT"
|
|||
readme = "../README.md"
|
||||
categories = ["api-bindings", "embedded", "gui", "no-std"]
|
||||
keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
|
||||
include = ["Cargo.toml", "src/**/*", "src/widgets/generated.rs"]
|
||||
|
||||
[dependencies]
|
||||
lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" }
|
||||
|
@ -18,6 +19,5 @@ cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"]
|
|||
bitflags = "1.2.1"
|
||||
|
||||
[build-dependencies]
|
||||
lvgl-codegen = { path = "../lvgl-codegen" }
|
||||
quote = "1.0.7"
|
||||
proc-macro2 = "1.0.18"
|
||||
|
|
|
@ -1,48 +1,26 @@
|
|||
use std::ffi::OsStr;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::{env, fs, path};
|
||||
|
||||
fn main() {
|
||||
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||
.canonicalize()
|
||||
.unwrap();
|
||||
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let widgets_rs_path = manifest_dir.join("src/widgets/generated.rs");
|
||||
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
let gen_code = out_path.join("bindings.rs");
|
||||
|
||||
let code = invoke_command("../target/debug/lvgl-codegen", &[""], &project_dir);
|
||||
fs::write(&gen_code, code).unwrap();
|
||||
|
||||
// // Format generated code
|
||||
// let _ = invoke_command(
|
||||
// "cargo",
|
||||
// &["fmt", "-p", gen_code.to_str().unwrap()],
|
||||
// &project_dir,
|
||||
// );
|
||||
}
|
||||
|
||||
fn invoke_command<C, I, S, D>(command: C, args: I, cur_dir: D) -> String
|
||||
where
|
||||
C: AsRef<OsStr>,
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
D: AsRef<path::Path>,
|
||||
{
|
||||
Command::new(command)
|
||||
.current_dir(cur_dir)
|
||||
.args(args)
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|output| {
|
||||
if output.status.success() {
|
||||
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
if !widgets_rs_path.exists() {
|
||||
println!("Generating `src/widgets/generated.rs`");
|
||||
let status = Command::new(manifest_dir.join("../target/debug/lvgl-codegen"))
|
||||
.spawn()
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr).trim().to_string()
|
||||
);
|
||||
}
|
||||
})
|
||||
.unwrap()
|
||||
"Code generation failed because no codegen executable was found. \
|
||||
Please run `cargo build --package lvgl-codegen` and then try again.",
|
||||
)
|
||||
})
|
||||
.wait()
|
||||
.unwrap();
|
||||
if !status.success() {
|
||||
panic!("Code generation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ mod bar;
|
|||
mod gauge;
|
||||
mod label;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
include!("generated.rs");
|
||||
|
||||
use crate::Widget;
|
||||
pub use arc::*;
|
||||
pub use bar::*;
|
||||
pub use gauge::*;
|
||||
|
|
Loading…
Reference in a new issue