Generate code for most of the widgets #20

Merged
rafaelcaricio merged 11 commits from generate-code into master 2020-06-13 18:31:25 +00:00
rafaelcaricio commented 2020-06-12 18:46:18 +00:00 (Migrated from github.com)

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 the bindgen conflict on trying to instantiate Clang object in different threads.

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 the `bindgen` conflict on trying to instantiate `Clang` object in different threads.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:47:44 +00:00
@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:47:44 +00:00

Ok, I need to commit this to my own repo. The original clang-rs is not up to date with clang-sys that is used by rust-bindgen.

Ok, I need to commit this to my own repo. The original `clang-rs` is not up to date with `clang-sys` that is used by `rust-bindgen`.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:48:09 +00:00
@ -13,0 +19,4 @@
lang-c = "0.8.1"
syn = "1.0.31"
[build-dependencies]
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:48:08 +00:00

Remove this, not used.

Remove this, not used.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:49:11 +00:00
@ -13,0 +19,4 @@
lang-c = "0.8.1"
syn = "1.0.31"
[build-dependencies]
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:49:11 +00:00

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.

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.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:51:27 +00:00
@ -0,0 +59,4 @@
"-I",
lvgl_src_path.to_string_lossy().as_ref(),
"-I",
lv_config_dir.to_string_lossy().as_ref(),
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:51:27 +00:00

This code produces a full lvgl.c source code that is used by the lvgl-codegen to argument the code generation. One question I have is how to support use-supplied lvgl_config.h.

This code produces a full `lvgl.c` source code that is used by the `lvgl-codegen` to argument the code generation. One question I have is how to support use-supplied `lvgl_config.h`.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:52:13 +00:00
@ -0,0 +59,4 @@
"-I",
lvgl_src_path.to_string_lossy().as_ref(),
"-I",
lv_config_dir.to_string_lossy().as_ref(),
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:52:13 +00:00

I mean, how to support generic lvgl-config.h for the case of people downloading pre-built lvgl-rs from crates.io.

I mean, how to support generic `lvgl-config.h` for the case of people downloading pre-built `lvgl-rs` from `crates.io`.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:54:56 +00:00
@ -0,0 +406,4 @@
}
pub fn load_function_definitions() -> CGResult<Vec<LvFunc>> {
let clang = Clang::new()?;
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:54:56 +00:00

This line is where is clashes with rust-bindgen. It happens because clang has global state and so the Rust bindings to it prohibit to instantiate more than one per program. When cargo is building the lvgl-rs packages it uses the same process to build in different threads, so when building this package and bindgen we get errors.

This line is where is clashes with `rust-bindgen`. It happens because `clang` has global state and so the Rust bindings to it prohibit to instantiate more than one per program. When `cargo` is building the `lvgl-rs` packages it uses the same process to build in different threads, so when building this package and bindgen we get errors.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:56:15 +00:00
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:56:15 +00:00

We don't need either of those. I need to remove these lines.

We don't need either of those. I need to remove these lines.
rafaelcaricio (Migrated from github.com) reviewed 2020-06-12 18:56:51 +00:00
rafaelcaricio (Migrated from github.com) commented 2020-06-12 18:56:50 +00:00

This is cleaner and safer.

This is cleaner and safer.
jakubclark (Migrated from github.com) reviewed 2020-06-12 22:46:33 +00:00
@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
jakubclark (Migrated from github.com) commented 2020-06-12 22:46:33 +00:00

If a specific commit of the clang-rs repo is needed, it's possible to do something like:

clang = { git = "https://github.com/KyleMayes/clang-rs.git", rev = "<commit hash>" }
If a specific commit of the `clang-rs` repo is needed, it's possible to do something like: ```text clang = { git = "https://github.com/KyleMayes/clang-rs.git", rev = "<commit hash>" } ```
rafaelcaricio (Migrated from github.com) reviewed 2020-06-13 06:03:46 +00:00
@ -13,0 +15,4 @@
clang = { path = "../../clang-rs" }
itertools = "0.9.0"
proc-macro2 = "1.0.18"
Inflector = "0.11.4"
rafaelcaricio (Migrated from github.com) commented 2020-06-13 06:03:46 +00:00

I needed to actually write some tweaks to the code. 😕 Maybe a PR to upstream would be the way to go here.

I needed to actually write some tweaks to the code. 😕 Maybe a PR to upstream would be the way to go here.
Sign in to join this conversation.
No description provided.