c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Translate with one Rust module file per C header

Open Rua opened this issue 4 months ago • 1 comments

At the moment, the definitions in every header are listed at the top of each Rust source file. This leads to a lot of duplication of definitions. I propose using Rust modules for this, with each in its own file, so that the definitions are centralised. This would lead to a more natural project structure for Rust and make it easier to start off refactoring it.

Because of how C headers work, there is no guarantee that the output will be exactly identical from one inclusion to the next. This can be a problem for translating it to Rust. However, I think that this is relatively rare compared to the majority of cases where the output is the same. So I think c2rust should primarily output that format, and do something else as fallback only in the case of conflicts.

Rua avatar Aug 10 '25 08:08 Rua

This is already supported, but turned off by default because c2rust-refactor has bitrotted a bit (see https://github.com/immunant/c2rust/issues/215). We are working on reviving that tool.

ahomescu avatar Aug 11 '25 22:08 ahomescu