C to Rust translation keeps macros to preserve original code structure
Lifting the Preprocessor with Oxidize: Structure-Preserving C-to-Rust Translation (Technical Report)
Programming Languages
Summary
Translating C code to Rust usually loses some parts like macros, which are shortcuts that programmers use to simplify their code. The authors created Oxidize, a tool that translates C to Rust while keeping these macros intact as Rust macros, so the original code’s structure and intent are preserved. This makes it easier for developers to maintain and understand the translated code. The report includes technical details, evaluations on real C projects, and performance studies to back up this approach.
What this means in practice
- •For software migration teams: Translate large C codebases into Rust while preserving original macro abstractions to maintain code clarity and developer intent.
- •For legacy systems maintainers: Update legacy C code to safer Rust code without losing key abstraction mechanisms embedded in macros, improving maintainability.
Authors
Robbe De Greef, Théo Engels, Felix Van den Broucke, Ken Hasselmann, Antonio Paolillo
Abstract
This technical report accompanies our EuroSys 2027 paper "Lifting the Preprocessor with Oxidize: Structure-Preserving C-to-Rust Translation" (DOI 10.1145/3842654.3848533). Oxidize is a C-to-Rust translator that retains C macros as Rust macros instead of expanding them away, so that the translated code keeps the abstractions its developers wrote. The report collects material the paper cites but has no room for: the translator's intermediate representation, pass structure and back-end emission; the details of macro typing through helper traits and the generic cast macro; the sources and pinned revisions of the nine evaluated C codebases; the per-codebase macro population and how macros are attributed to classes; a roadmap from structure-preserving translation toward safe Rust; the performance overhead study and its methodology; and the configuration and prompt used for the LLM-based baselines.