{"id":13711099,"url":"https://github.com/lassade/c2z","last_synced_at":"2025-12-17T12:07:55.490Z","repository":{"id":173537067,"uuid":"650853810","full_name":"lassade/c2z","owner":"lassade","description":"C++ to Zig bindings and transpiler","archived":false,"fork":false,"pushed_at":"2024-10-17T11:49:19.000Z","size":3710,"stargazers_count":100,"open_issues_count":9,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-19T15:40:08.103Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lassade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2023-06-08T00:40:02.000Z","updated_at":"2024-10-17T11:49:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"8380ce9f-3e42-4b4c-bc61-9e96738ce219","html_url":"https://github.com/lassade/c2z","commit_stats":null,"previous_names":["lassade/zbg","lassade/c2z"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lassade%2Fc2z","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lassade%2Fc2z/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lassade%2Fc2z/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lassade%2Fc2z/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lassade","download_url":"https://codeload.github.com/lassade/c2z/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528339,"owners_count":17326345,"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","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":[],"created_at":"2024-08-02T23:01:04.472Z","updated_at":"2025-12-17T12:07:55.416Z","avatar_url":"https://github.com/lassade.png","language":"C++","readme":"inspeired by this [article](https://floooh.github.io/2020/08/23/sokol-bindgen.html) uses zig to create zig bindgens for c++\n\n`zig cc -x c++ -std=c++11 -Xclang -ast-dump=json {input_file}`\n\n\n## Notes\n\n- Glue is invitable ... snap ... and needed to make the bindings cross platform\n- Transpiled code can leak memory (implicit destructors aren't called)\n- Manual adjustments are required, specially to make bindings idiomatic and easer to read\n- Meant to work with libraries that follow the *C with classes* coding style\n- No Zig side inheritance, instead create bindings of a C++ implementation\n\n## Usage\n\n### Setup\n\n1. make sure `zig` in your PATH, you will need the version `0.13` and up\n2. build the project and copy the `c2z` executable from `zig-out` to your desired location\n3. or just run the project using `zig build run -- ARGS`\n\n### Running it\n\n1. `zig build run -- lib.h` or `c2z lib.h`\n2. pass any clang argument like include and defines e.g. `zig build run -- -DNDEBUG -I.\\include -target x86-linux -- .\\include\\lib.h`\n4. modify the generated bindings until it works ;) you might need to import `cpp.zig` it is located in the src folder\n\n### Misc\n\n- `msvc` has a second tier support, just pass it as target tuple like as: `-no-glue -target x86_64-windows-msvc` to generate a target specifc binding for it. Debug builds aren't fully supported, use `ReleaseFast` or at least `-O1`, you might also wan't to find a way of define `_ITERATOR_DEBUG_LEVEL` to something different than `2`.\n\n## Todo\n\n- transpile inline or constexpr constructors when the class isn't polymorphic\n- use function pointers to handle varidact functions\n- (hard) `#include` -\u003e `@import`\n- (easy) walk a directory tree\n\n- transpile vector of vectors\n- (easy) better input file not found error\n- (easy) verbose option\n- (easy) handle `BlockCommandComment` and `ParamCommandComment` in `FullComment`\n- (easy) resolve return of function with a aliased return type\n- (easy) fail when clang ast-bump has failed, because missing headers or wrong code\n- (hard) `if (*data++ == v) { ... }` should generate `{ const __tmp0 = data; data += 1; if (__tmp0.* == v) { ... }  }`\n- (hard) solve `UnresolvedMemberExpr`, maybe when integrating clang ast directly\n- (hard) solve implicit destructors calls\n- (easy) handle private members, class is default private, struct default public, in code is referenced as `self.public`\n- (hard) handle varidact functions `myFunction(va_args) -\u003e myFunction(args: [*c]u8) and myFunction__VA(...)`\n- (hard) apply `keywordFix`\n- use `@compileError` for objects that couldn't be transpiled\n- write layout tests\n\n## Test cases\n\n### C++ libs\n\n- [ ] fpng (99.99 %)\n- [ ] xatlas (86.40 %)\n- [ ] imgui (67.21 %)\n- [ ] msdfgen (~80% ish)\n- [ ] box2d\n- [ ] basis_universal\n- [ ] JoltPhysics\n- [ ] astc-encoder\n\n### C libs (or with builtin C bindings)\n\n- [ ] SDL2\n- [ ] stbi\n- [ ] raylib\n- [ ] meshoptimizer\n- [ ] tinyexr\n- [ ] minimp3\n","funding_links":[],"categories":["C++","Interoperability"],"sub_categories":["FFI Bindings"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassade%2Fc2z","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flassade%2Fc2z","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flassade%2Fc2z/lists"}