mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.27k stars 294 forks source link

Convert config fields header, trailer, after_includes to text fields. #977

Open flaviojs opened 2 weeks ago

flaviojs commented 2 weeks ago

Motivation:

Some cbindgen tests have a toml config file. That config file must work with multiple languages. Hard to understand tricks are used, making it harder for cbindgen contributors to make tests for their code. A better solution is to allow language-specific text in text fields that allow "code".

Changes:

This PR attempts to do that, while maintaining backwards compatibility. I chose a serde-compatible way to represent the data (untagged enums) but can change to whatever you want.

Only header, trailer, after_includes were changed. Other fields that output raw "code" can be changed too. No idea how docs.md should be changed so I left it alone.

Fields:

Text field can be a line field or a sequence of lines or structs:

field = [
   "sequence of lines",
   { language = "C", line = "or structs" },
]

Line field can be a single line or a struct:

field = "line"
field = { language = "C", line = "struct" }