{"id":15047419,"url":"https://github.com/dynamium/lv_cxx_bindgen","last_synced_at":"2025-08-22T16:11:20.754Z","repository":{"id":214737825,"uuid":"736416780","full_name":"dynamium/lv_cxx_bindgen","owner":"dynamium","description":"A C++ binding generator for LVGL. Written in Rust (oh the irony)","archived":false,"fork":false,"pushed_at":"2024-04-02T13:12:38.000Z","size":45896,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T00:51:00.115Z","etag":null,"topics":["binding","cpp","cpp11","cpp14","cpp17","cpp20","cpp23","lvgl","rust"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dynamium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-27T21:09:31.000Z","updated_at":"2025-01-24T16:49:21.000Z","dependencies_parsed_at":"2024-02-28T18:28:59.035Z","dependency_job_id":"14c18b88-956d-4260-8809-e1db6ce022a3","html_url":"https://github.com/dynamium/lv_cxx_bindgen","commit_stats":null,"previous_names":["dynamium/lv_cxx_binding","dynamium/lv_cxx_bindgen"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dynamium/lv_cxx_bindgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dynamium%2Flv_cxx_bindgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dynamium%2Flv_cxx_bindgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dynamium%2Flv_cxx_bindgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dynamium%2Flv_cxx_bindgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dynamium","download_url":"https://codeload.github.com/dynamium/lv_cxx_bindgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dynamium%2Flv_cxx_bindgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271665312,"owners_count":24799304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binding","cpp","cpp11","cpp14","cpp17","cpp20","cpp23","lvgl","rust"],"created_at":"2024-09-24T20:58:05.547Z","updated_at":"2025-08-22T16:11:20.726Z","avatar_url":"https://github.com/dynamium.png","language":"C++","readme":"# lv_cxx_bindgen\nA C++ binding generator for LVGL. Written in Rust (oh the irony)\n\n\u003e This is still work-in-progress, it doesn't even generate any sources for\n\u003e now, but it's in the works.\n\nThis generator uses the LVGL JSON API map, that will later be analyzed, and used as\na basis for all autogenerated C++ code. Also, it supports different C++ target\nversions, ranging from C++11 to C++23. \n\n## Usage\n\n`lv_cxx_bindgen` requires a config file, by default named `lv_cxx_bindgen.toml` and\nlooked for in CWD, but can be specified in the `-c` argument.\n\n\u003e TODO: Finish writing this section after CLI API is finished\n\n## Configuration\n\nAll configuration is done in the `lv_cxx_bindgen.toml` file. An example file\nlooks like this:\n\n```toml\n[classes]\nexclude = {\n    groups = [\"anim\"],\n    functions = [\"obj_get_disp\", \"font_set_kerning\"]\n},\nrenames = [\n    [\"obj\", \"Object\"]\n],\ninheritances = [\n    [\"img\", \"obj\"],\n    [\"menu\", \"obj\"]\n]\nnamespaces = {\n    exclude = [\"obj\"],\n    renames = [\n        [\"anim\", \"animation\"]\n    ]\n}\nfunctions = {}\n```\n\n### Input\n\n- `cwd` - current working directory.\n\n### Generation\n\n- `target` - target C++ version, by default C++23. All the differences between different\ntargets and generated output:\n\n\u003e Note: read the list from the start to your desired C++ target to fully understand what\n\u003e code will be generated\n\n- C++11\n    - Functions that accept arrays in arguments have those arguments converted from pointers\n    to `std::vector` or `std::array`, depending on configuration\n    - Functions that accept function pointers in arguments have those arguments converted\n    to `std::function`, but as an overload, so there are options for `std::function`, and\n    normal function pointers\n    - Functions that can error out have `lvgl::expected` as their result type.\n    - Functions that can have `null` values use `lvgl::optional`.\n- C++14 doesn't have any changes, but it's still a good idea to set the target to your\nC++ version, so that in future updates it will not break\n- C++17\n    - Instead of `lvgl::optional`, `std::optional` is used as an option type.\n- C++20\n    - Now there is no header file in the output, only a `.cppm` file, which is a C++\n    module, that can be imported with `import lvgl;`. And yes, when you use import,\n    you lose access to the C API, but it still can be included via its header file\n    (that is not recommended tho, see FAQ).\n- C++23\n    - Instead of `lvgl::expected`, `std::expected` is used as a result type.\n\n\u003e TODO: document `classes` and `namespaces` when those will be implemented\n\n- `class.exclude` - function groups that are excluded from assigning to a class.\nFor example, if you specify `\"obj\"` in the list, any function that starts with\n`lv_obj_` will not get assigned to any class\n- `class.renames` - \n\n## Process\n\nIn short, the whole process can be simplified to 3 main steps:\n\n- Parsing\n- Conversion \n- Generation\n\nThe first step is the simplest one, it just parses a JSON API map file and extracts\nall relevant data.\n\nThe second step converts that map file to High-level Abstract Syntax Tree (HL-AST),\nwhich represents the entire C++ binding in a high-level format. That step is the\nmost interesting one, because this one does the fun stuff - converting\nthe C API into idiomatic C++ code.\n\nAnd the (not-so) best for last, the third step consists of actually converting allat\ninto actual C++ code. That shit is done manually (without any codegen library), for\nplain efficiency and also ease of understanding what is actually going on. Also, an\nadditional `clang-format` run can be named a \"three and a half\" step, because it's\npart of codegen, but not part of the actual generator.\n\nSo, a full process can be described like this:\n\n- Extraction\n    - Parsing of `lvgl.json` (a.k.a. LVGL API Map)\n    - Function list extraction\n    - Typedef/struct/enum/etc extraction and combination (combining anonymous struct\n    with its associated typedef for example)\n- Conversion to C++ a.k.a. HL-AST (High-level Abstract Syntax Tree) generation\n    - Function processing/generation\n        - Argument conversion for more idiomatic C++\n        - Argument filtering (removal of singular void args, like `lv_init(void)`)\n    - Struct processing/generation\n        - Replace *char with std::string, function pointers with std::function,\n        and other stuff when applicable (configurable via CLI)\n    - Enum processing/generation\n        - Generate as enum classes\n    - Namespace generation\n        - Group by function/struct/enum namespace (lv_\u003cnamespace\u003e)\n    - Class generation\n        - Group by function/struct/enum namespace (lv_\u003cnamespace\u003e)\n        - Create constructors from lv_\u003cnamespace\u003e_create functions\n- Generation\n    - Conversion of HL-AST to LL-AST (Low-level Abstract Syntax Tree)\n    - LL-AST to source code conversion \n    - `clang-format` run over generated code (optional)\n\n## FAQ\n\n### Q: Are exceptions used in any shape or form?\n\nA: No, never. That's the worst idea known to man, especially knowing that\nLVGL is supposed to run on embedded systems. Exceptions introduce a lot of\noverhead, and are generally a pain in the ass. As a replacement, `std::optional`,\n`std::expected`, and similar types are used, depending on context. \n\n### Q: Can I use the normal C API together with C++?\n\nA: **TL;DR: Don't. Please.**\n\nFull answer: Technically, yes, no one is stripping that right from you, but that is\nfar from recommended, use the C API only when you REALLY know what you are doing.\nThis is basically black\u0026white, you should only use one API, no mixing of C and C++\nAPIs, no \"grays. You're only making it harder for yourself by using both at the\nsame time.\n\n## Technical\n\n### Templating\n\nIf you have looked at this repository longer that 99% of people that go here, you've\nprobably noticed that `res/src/lvgl.hpp` has comments that look something like\n`// MARKER: OBJ_CLASS_MEMBERS` all over it. And that is just for simple\ntemplating built-in to `lv_cxx_binding` itself. All the templating engine does\nis it looks for `// MARKER:` inside the source code, and if found, gets the\nID after the statement, and replaces the comment with what should be in that spot.\nNo dark magic or anything, simple search-and-replace :)\n\n## Thanks\n\nThe implementation of `lvgl::optional` is basically\n[martinmoene/optional-lite](https://github.com/martinmoene/optional-lite). Thanks\nfor this great piece of software @martinmoene!\n\nSame goes for `lvgl::expected`, it is from\n[martinmoene/expected-lite](https://github.com/martinmoene/expected-lite). Fabulous\npiece of software.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdynamium%2Flv_cxx_bindgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdynamium%2Flv_cxx_bindgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdynamium%2Flv_cxx_bindgen/lists"}