Abstract
Translating legacy C codebases to Rust is increasingly demanded for building safety-critical systems. While various approaches have emerged for this task, they face inherent trade-offs: rule-based methods often struggle to satisfy code safety and idiomaticity requirements, while LLM-based methods frequently fail to generate semantically equivalent Rust code due to heavy dependencies across the codebase. We propose EvoC2Rust, an automated framework for converting complete C projects to equivalent Rust ones. EvoC2Rust employs a skeleton-guided translation strategy consisting of three stages: skeleton construction, incremental module translation with feature mappings, and post-generation repair. Our evaluation demonstrates that EvoC2Rust outperforms the strongest LLM-based baseline by 17.24% in syntax accuracy and 14.32% in semantic accuracy, while achieving a 43.59% higher code safety rate than the best rule-based tool.
Introduction
The software industry is undergoing a significant migration toward memory-safe languages like Rust to eliminate vulnerabilities such as buffer overflows common in legacy C codebases. However, project-level translation remains challenging due to the linguistic gap between C and Rust and complex project-level dependencies. Existing rule-based tools like C2Rust often produce "C-in-Rust" code that relies heavily on unsafe blocks, while pure LLM-based methods struggle with cross-module references and context window limitations.
Methodology: The EvoC2Rust Pipeline
EvoC2Rust introduces a three-stage, skeleton-guided pipeline to bridge these gaps by combining structural integrity with semantic reasoning.
1. Skeleton Construction
The framework first analyzes the entire C project to extract metadata, including macros, type definitions, and function signatures. It constructs a compilable Rust skeleton where function bodies are initially replaced with unimplemented!() stubs. This ensures that project-wide dependencies are resolved before logic translation begins.
2. Module Translation with Feature Mapping
Function stubs are incrementally filled using an LLM (e.g., DeepSeek-V3 or Qwen3-32B). To ensure safety and idiomaticity, the LLM is guided by expert-defined Safety-Preserving Mappings. These mappings provide safe Rust abstractions for complex C features like pointer arithmetic and variadic arguments, effectively lowering the complexity of the translation task for the LLM.
3. Post-Generation Repair
EvoC2Rust employs a cascading repair loop to handle compilation errors. This includes bracket repair for syntax errors, rule-based regex fixes for common translation quirks, and iterative LLM refinement based on compiler feedback to resolve deep semantic or type-consistency issues.
Evaluation and Results
The framework was evaluated on Vivo-Bench (19 algorithmic projects) and C2R-Bench, a new benchmark featuring six industrial projects from Huawei with complex multi-file architectures and extensive cross-file dependencies.
As shown in the results table, EvoC2Rust significantly outperforms existing methods. It achieves near-perfect safety rates (98% on Vivo-Bench) and maintains high compilation rates even as project size increases. Specifically, it improves syntax accuracy by 17.24% and semantic accuracy by 14.32% over the strongest LLM baseline. Furthermore, it achieves a 43.59% higher safety rate (measured by the absence of unsafe blocks) compared to rule-based tools.
Conclusion
EvoC2Rust demonstrates that a hybrid approach—combining the structural integrity of rule-based skeletons with the semantic reasoning of LLMs—is highly effective for project-level C-to-Rust translation. Future work will focus on extending the framework to handle multi-threaded concurrency and a broader range of third-party library dependencies.
Summary updated