{"id":15412428,"url":"https://github.com/robertknight/rust-cmacros","last_synced_at":"2026-02-03T04:04:04.554Z","repository":{"id":34027800,"uuid":"37786776","full_name":"robertknight/rust-cmacros","owner":"robertknight","description":"Rust lib for parsing macros from C header files and assisting with translation to Rust code","archived":false,"fork":false,"pushed_at":"2017-04-27T08:55:49.000Z","size":140,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T12:52:07.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/robertknight.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}},"created_at":"2015-06-20T21:35:10.000Z","updated_at":"2021-08-14T13:22:21.000Z","dependencies_parsed_at":"2022-07-14T02:30:38.320Z","dependency_job_id":null,"html_url":"https://github.com/robertknight/rust-cmacros","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Frust-cmacros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Frust-cmacros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Frust-cmacros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertknight%2Frust-cmacros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertknight","download_url":"https://codeload.github.com/robertknight/rust-cmacros/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247514854,"owners_count":20951365,"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-10-01T16:53:01.361Z","updated_at":"2026-02-03T04:04:04.513Z","avatar_url":"https://github.com/robertknight.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rust-cmacros\n[![Build Status](https://travis-ci.org/robertknight/rust-cmacros.png?branch=master)](https://travis-ci.org/robertknight/rust-cmacros)\n\nRust library to assist with parsing and translating #define\nmacro definitions from C header files\nto corresponding Rust code for use with bindings\nto external libraries.\n\n**Update: Vojtech Kral suggested a much better idea - Generate C++ code which leverages the compiler's type inference to determine the types of macros: http://vojtech.kral.hk/en/rust-importing-c-constants-proof-of-concept/**\n\n## Intro\n\nTo use libraries with a C interface from Rust,\n[rust-bindgen](https://github.com/crabtw/rust-bindgen) can be used\nto generate Rust bindings automatically. It does not translate\nconstants or functions defined as macros in C headers to Rust\ncode however.\n\nrust-cmacros is a simple and fairly dumb library which helps to\nfill this gap.\n\nIt has two basic functions:\n\n* `extract_macros()` parses the source of a C header file and extracts C macro definitions\n* `generate_rust_src()` takes as input a set of extracted macros and a translator function\n  and generates Rust code.\n\n## Examples\n\n```rust\ncargo run --example parse_all_headers /usr/include\n```\n\nParse all headers in `/usr/include` and print re-constructed #define statements\n\n```rust\ncargo run --example translate_macros /usr/include/sqlite3.h\n```\n\nParse `/usr/include/sqlite3.h` and output translations of the macros using the default translation function.\nIn real usage, you would supply a translation function to skip or modify the translations\nfor non-trivial or unnecessary macros.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertknight%2Frust-cmacros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertknight%2Frust-cmacros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertknight%2Frust-cmacros/lists"}