{"id":13995511,"url":"https://github.com/jupp0r/cpp-codegen-rs","last_synced_at":"2025-07-22T22:31:02.650Z","repository":{"id":62439038,"uuid":"63553467","full_name":"jupp0r/cpp-codegen-rs","owner":"jupp0r","description":"Generate code from C++ classes","archived":false,"fork":false,"pushed_at":"2017-03-04T21:39:30.000Z","size":52,"stargazers_count":10,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T11:41:08.872Z","etag":null,"topics":["code-generator","cpp","libclang","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jupp0r.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}},"created_at":"2016-07-17T21:34:14.000Z","updated_at":"2023-03-15T09:30:59.000Z","dependencies_parsed_at":"2022-11-01T22:01:38.802Z","dependency_job_id":null,"html_url":"https://github.com/jupp0r/cpp-codegen-rs","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jupp0r/cpp-codegen-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupp0r%2Fcpp-codegen-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupp0r%2Fcpp-codegen-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupp0r%2Fcpp-codegen-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupp0r%2Fcpp-codegen-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jupp0r","download_url":"https://codeload.github.com/jupp0r/cpp-codegen-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupp0r%2Fcpp-codegen-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266585663,"owners_count":23952163,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["code-generator","cpp","libclang","rust"],"created_at":"2024-08-09T14:03:27.289Z","updated_at":"2025-07-22T22:31:02.173Z","avatar_url":"https://github.com/jupp0r.png","language":"Rust","readme":"Generate Code from C++ Classes [![Build Status](https://travis-ci.org/jupp0r/cpp-codegen-rs.svg?branch=master)](https://travis-ci.org/jupp0r/cpp-codegen-rs)[![Build status](https://ci.appveyor.com/api/projects/status/nov0lxhgce7dwjvl/branch/master?svg=true)](https://ci.appveyor.com/project/jupp0r/cpp-codegen-rs/branch/master)[![Coverage Status](https://coveralls.io/repos/github/jupp0r/cpp-codegen-rs/badge.svg?branch=master)](https://coveralls.io/github/jupp0r/cpp-codegen-rs?branch=master)\n===================================\ncpp-codegen-rs uses libclang to read C++ class definitions and\ngenerate code. Example use cases include the generation of Google Mock\nClasses, Reflection Libraries, (De)Serialization, RPC Frameworks, and\nanything else that suffers from a lack of proper compile-time\nreflection in C++. The underlying concept is that it's sometimes\npreferrable to use actual code as the IDL to generate these things as\nsupposed to a dedicated IDL.\n\nProject Status\n--------------\nThis is currently alpha. Expect bugs and API changes.\n\nUsage\n-----\ncpp-codegen-rs is a source-to-source compiler. While the\ninput has to be very specific (C++ classes), the output can be\nanything ranging from more C++ code, bindings for other languages to\ndocumentation.\n\nThe following example creates\n[GoogleTest](https://github.com/google/googletest) mock objects for\nC++ classes. Usually code generation is run before the actual\ncompilation.\n\nGiven the following C++ header:\n\n``` c++\n#pragma once\n\nstruct Interface {\n    virtual ~Interface() = default;\n    virtual void method(int foo) = 0;\n    virtual int foo(double) = 0;\n};\n```\n\nThe corresponding [GoogleTest](https://github.com/google/googletest)\nmock object would look like this:\n\n``` c++\n#pragma once\n#include \u003cgmock/gmock.h\u003e\n\nclass MockInterface : public Interface {\n  MOCK_METHOD1(method, void(int));\n  MOCK_METHOD1(foo, void(double));\n};\n```\n\ncpp-codegen-rs parses the C++ header, and creates a `Model` object out of the abstract syntax tree defined by the header. The `Model` is then passed to a template file. To achieve the desired transformation, a suitable template looks like this:\n\n\n``` c++\n// THIS FILE IS GENERATED, CHANGING IT IS FUTILE\n#pragma once\n#include \u003cgmock/gmock.h\u003e\n\n{{#each interfaces ~}}\nclass Mock{{name}} : public {{name}} {\n{{#each methods ~}}\n    MOCK_METHOD{{len arguments}}({{name}}, {{return_type}}({{#each arguments}}{{argument_type}}{{#unless @last}}, {{/unless}}{{/each}}));\n{{/each ~}}\n};\n{{/each ~}}\n```\n\nThe templating language is based on the\n[HandleBars Rust](https://github.com/sunng87/handlebars-rust) library,\nwhich should be consulted for documentation on how to write\ntemplates. A complete template for\n[GoogleTest](https://github.com/google/googletest) mock objects, which\nalso deals with namespaces and class templates, can be found in\n[gmock.hbs](templates/gmock.hbs).\n\nIn order to perform the actual compilation, cpp-codegen-rs is invoked with the following parameters\n\n``` bash\ncpp_codegen interface.h -t templates/gmock.hbs\n```\n\nGenerated code is written to stdout.\n\nDistribution\n------------\nMy goal is to supply statically linked (against libclang) release\nbinaries for Linux, OS X and Windows to ease deployment.\n\nLicense\n-------\nMIT\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupp0r%2Fcpp-codegen-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupp0r%2Fcpp-codegen-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupp0r%2Fcpp-codegen-rs/lists"}