Generate code for most of the widgets #20
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: rafaelcaricio/lvgl-rs#20
Loading…
Reference in a new issue
No description provided.
Delete branch "generate-code"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR sets a foundation on how we can generate most of the safe Rust code from the C99 API. After discovering code patterns by manually implementing some parts of the API bindings in Rust, we can generalise the pattern and generate code for all the other places where the pattern is identified.
Initially, I'm focusing on generating code for the widgets. I use the
lvgl-codegen
package as a tool to generate code at compile time. Maybe a good option to move to procedural macros, but we need to work around thebindgen
conflict on trying to instantiateClang
object in different threads.@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
Ok, I need to commit this to my own repo. The original
clang-rs
is not up to date withclang-sys
that is used byrust-bindgen
.@ -13,0 +19,4 @@
lang-c = "0.8.1"
syn = "1.0.31"
[build-dependencies]
Remove this, not used.
@ -13,0 +19,4 @@
lang-c = "0.8.1"
syn = "1.0.31"
[build-dependencies]
For context, I tried to use this library. But it cannot parse C99 standard. So I went back to
clang-rs
. If we can find a good C99 parser we could simplify a lot all this code generation work.@ -0,0 +59,4 @@
"-I",
lvgl_src_path.to_string_lossy().as_ref(),
"-I",
lv_config_dir.to_string_lossy().as_ref(),
This code produces a full
lvgl.c
source code that is used by thelvgl-codegen
to argument the code generation. One question I have is how to support use-suppliedlvgl_config.h
.@ -0,0 +59,4 @@
"-I",
lvgl_src_path.to_string_lossy().as_ref(),
"-I",
lv_config_dir.to_string_lossy().as_ref(),
I mean, how to support generic
lvgl-config.h
for the case of people downloading pre-builtlvgl-rs
fromcrates.io
.@ -0,0 +406,4 @@
}
pub fn load_function_definitions() -> CGResult<Vec<LvFunc>> {
let clang = Clang::new()?;
This line is where is clashes with
rust-bindgen
. It happens becauseclang
has global state and so the Rust bindings to it prohibit to instantiate more than one per program. Whencargo
is building thelvgl-rs
packages it uses the same process to build in different threads, so when building this package and bindgen we get errors.We don't need either of those. I need to remove these lines.
This is cleaner and safer.
@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
If a specific commit of the
clang-rs
repo is needed, it's possible to do something like:@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
I needed to actually write some tweaks to the code. 😕 Maybe a PR to upstream would be the way to go here.