Discover and explore top open-source AI tools and projects—updated daily.
immunantC to Rust transpiler for code migration
Top 10.3% on SourcePulse
C2Rust is a transpiler designed to migrate C99-compliant codebases to Rust, preserving functional equivalence. It targets developers undertaking complex C-to-Rust rewrites, providing an initial unsafe Rust representation that serves as a foundation for subsequent manual or automated refinement into safe, idiomatic Rust code.
How It Works
The C2Rust toolchain employs a multi-stage process: c2rust transpile converts C sources into unsafe Rust, closely mirroring the original C structure. This is followed by c2rust refactor for deterministic code cleanup and deduplication, and optionally c2rust postprocess, which can leverage LLMs for more advanced idiomatic transformations. This approach prioritizes functional fidelity in the initial translation, deferring safety and idiomatic concerns to later, more manageable stages.
Quick Start & Requirements
cargo install --locked c2rust. Development versions can be installed from Git.c2rust-refactor require specific nightly Rust compiler versions (e.g., nightly-2022-11-03) and are typically installed from Git.c2rust transpile compile_commands.json, which requires a compilation database generated by build systems like CMake, Meson, or tools like bear../manual/ directory of the repository. A live Compiler Explorer integration is also available.Highlighted Details
rav1d (AV1 decoder) and rexpat (XML parser), with some migrations achieving fully safe Rust.Cargo.toml templates for Rust libraries or binaries, simplifying project setup.--reorganize-definitions flag integrates c2rust-refactor to deduplicate code and improve module imports.Maintenance & Community
c2rust@immunant.com.Licensing & Compatibility
Limitations & Caveats
The transpiled output is explicitly unsafe and unidiomatic, necessitating significant post-translation effort by developers. The LLM-powered postprocessing tool carries a risk of introducing errors, making a robust test suite essential. The translator may skip function definitions it cannot translate, emitting warnings. Cross-OS transpilation is noted as more challenging than cross-architecture.
1 day ago
Inactive
Ataraxy-Labs