Use lvgl-codegen
This commit is contained in:
parent
f0ec94cbf9
commit
d970deaa9d
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-sys/target/
|
||||||
lvgl/target/
|
lvgl/target/
|
||||||
lvgl-sys/src/bindings.rs
|
lvgl-sys/src/bindings.rs
|
||||||
|
lvgl/src/widgets/generated.rs
|
||||||
|
|
|
@ -8,11 +8,6 @@ license = "MIT"
|
||||||
publish = false
|
publish = false
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "lvgl_codegen"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1.3.9"
|
regex = "1.3.9"
|
||||||
quote = "1.0.7"
|
quote = "1.0.7"
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
use lvgl_codegen::{CodeGen, Rusty};
|
use lvgl_codegen::{CodeGen, Rusty};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let rs = Path::new(concat!(
|
||||||
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
"/../lvgl/src/widgets/generated.rs"
|
||||||
|
));
|
||||||
|
|
||||||
let codegen = CodeGen::new().unwrap();
|
let codegen = CodeGen::new().unwrap();
|
||||||
|
|
||||||
let widgets_impl: Vec<TokenStream> = codegen
|
let widgets_impl: Vec<TokenStream> = codegen
|
||||||
|
@ -15,5 +23,11 @@ fn main() {
|
||||||
#(#widgets_impl)*
|
#(#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"
|
readme = "../README.md"
|
||||||
categories = ["api-bindings", "embedded", "gui", "no-std"]
|
categories = ["api-bindings", "embedded", "gui", "no-std"]
|
||||||
keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
|
keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
|
||||||
|
include = ["Cargo.toml", "src/**/*", "src/widgets/generated.rs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" }
|
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"
|
bitflags = "1.2.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
lvgl-codegen = { path = "../lvgl-codegen" }
|
|
||||||
quote = "1.0.7"
|
quote = "1.0.7"
|
||||||
proc-macro2 = "1.0.18"
|
proc-macro2 = "1.0.18"
|
||||||
|
|
|
@ -1,48 +1,26 @@
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{env, fs, path};
|
use std::{env, fs, path};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||||
.canonicalize()
|
let widgets_rs_path = manifest_dir.join("src/widgets/generated.rs");
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
if !widgets_rs_path.exists() {
|
||||||
let gen_code = out_path.join("bindings.rs");
|
println!("Generating `src/widgets/generated.rs`");
|
||||||
|
let status = Command::new(manifest_dir.join("../target/debug/lvgl-codegen"))
|
||||||
let code = invoke_command("../target/debug/lvgl-codegen", &[""], &project_dir);
|
.spawn()
|
||||||
fs::write(&gen_code, code).unwrap();
|
.unwrap_or_else(|_| {
|
||||||
|
|
||||||
// // 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 {
|
|
||||||
panic!(
|
panic!(
|
||||||
"{}",
|
"Code generation failed because no codegen executable was found. \
|
||||||
String::from_utf8_lossy(&output.stderr).trim().to_string()
|
Please run `cargo build --package lvgl-codegen` and then try again.",
|
||||||
);
|
)
|
||||||
}
|
})
|
||||||
})
|
.wait()
|
||||||
.unwrap()
|
.unwrap();
|
||||||
|
if !status.success() {
|
||||||
|
panic!("Code generation failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ mod bar;
|
||||||
mod gauge;
|
mod gauge;
|
||||||
mod label;
|
mod label;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
include!("generated.rs");
|
||||||
|
|
||||||
|
use crate::Widget;
|
||||||
pub use arc::*;
|
pub use arc::*;
|
||||||
pub use bar::*;
|
pub use bar::*;
|
||||||
pub use gauge::*;
|
pub use gauge::*;
|
||||||
|
|
Loading…
Reference in a new issue