An automated framework for converting complete C projects to equivalent Rust ones.
.
├── data/ # Main data folder
│ ├── default/ # Default data directory for script execution
│ │ ├── project/ # Place projects to be translated here
│ │ ├── cache/ # Caches for generated results
│ │ ├── c-metadata/ # Stores parsed C metadata
│ │ └── rust-metadata/ # Stores parsed Rust metadata
│ ├── increment/ # data directory for incremental compilation
│ ├── fill/ # data directory for fill-in-the-blank tests
│ └── project_template/ # Sample project templates
│ ├── safelevel-0/ # General project framework
│ └── safelevel-test/ # Framework with unit tests
├── scripts/ # Scripts for running the translation pipeline
├── experiment_scripts/ # Scripts for reproducing experiments
├── src/ # Main source code directory
│ ├── config/ # Global settings and prompt configurations
│ ├── cache/ # Code cache management module
│ ├── code_optim/ # Error repair and optimization module
│ ├── entity/ # Core data structures and project management
│ ├── llm/ # LLM API interaction module
│ └── metadata_extraction/ # C/Rust metadata extraction using tree-sitter
EvoC2Rust is an automated framework designed to convert complete C projects to equivalent Rust ones. It employs a skeleton-guided translation strategy for project-level translation. The pipeline consists of three stages:
- It first decomposes the C project into functional modules, employs a feature-mapping-enhanced LLM to transform definitions and macros, and generates type-checked function stubs, which form a compilable Rust skeleton.
- It then incrementally translates functions, replacing the corresponding stub placeholders.
- Finally, it repairs compilation errors by integrating LLM and static analysis.
- Clone the repository:
git clone https://github.com/your-username/evo-c2rust-v2.git cd evo-c2rust-v2 - Install system dependencies:
- Recommended: Using Nix
Use the
nixpackage manager to create the required shell environment.# Create the required shell environment nix-shell # Install the Rust toolchain rustup toolchain install stable-gnu
- Alternative: Manual Installation
Install the following dependencies using your system's package manager:
python 3.11,clang-tools,gcc,cargo,rustc.
- Recommended: Using Nix
Use the
-
Install the required Python packages:
- Recommended: Using PDM
# Create a temporary python environment and install EvoC2Rust pdm install - Alternative: Using Pip
# Install EvoC2Rust into the system python environment pip install -e .
- Recommended: Using PDM
-
Configure your LLM API key: You need to modify the configuration in the
config/llm_config.ini.- Client Selection:
- If using the official DeepSeek model, ensure your import statement is
from llm.client import GenerationClient. - If using the official qwen model, change it to
from llm.client_qwen import GenerationClient.
- If using the official DeepSeek model, ensure your import statement is
- Client Selection:
The default project directory is ./data/default/project. Place the project you want to convert into this folder, then run the following scripts from the scripts directory.
Run the script to extract metadata from your C project. This information will be stored for later stages.
python scripts/extract_metadata.py --project_name {name}This will extract metadata from ./data/default/project/{name} and save it to ./data/default/c_metadata/{name} and ./data/default/rust_metadata/{name}.
Translate the C code using the generation script.
python scripts/generate.py --project_name {name}The script will translate the C code in the project and store the results in the cache directory specified within the script.
This multi-stage process fixes errors in the translated code.
- Bracket Mismatch Repair:
python scripts/delim_fix.py --project_name {name} - Rule-Based Repair:
python scripts/rule_fix.py --project_name {name} - LLM-Based Repair:
python scripts/rule_fix.py --project_name {name}
Note: For repair scripts, pay attention to the
old_cacheandnew_cachesettings. The scripts read from the old cache, perform repairs, and save the updated results to the new cache.
Verify the correctness of the translated code through compilation and testing.
- Incremental Compilation:
python scripts/verify.py --project_name {name} - Fill-in-the-Blank Compilation:
python scripts/fill_compile.py --project_name {name} - Fill-in-the-Blank Testing:
python scripts/fill_test.py --project_name {name}
Note: Fill-in-the-blank compilation and testing can only be performed on datasets with manually created ground truth. Fill-in-the-blank testing also requires manually created test cases.
Finally, generate the complete Rust project.
python scripts/gen_project.py --project_name {name}The final, translated Rust project will be created in ./final_project/{name}.
The case directory contains detailed examples of how EvoC2Rust handles specific translation challenges:
- Red-Black Tree Rotation: We present a case study on the
rb_tree_rotatefunction, a core operation in a red-black tree implementation, to illustrate the effectiveness of EvoC2Rust. - Post-Generation Repair: We list an example of the full repair pipeline, showing how bracket repair, rule-based repair, and LLM refinement work together to fix a series of compilation errors.





