Many of the most important systems in the world are written in inherently unsafe languages such as C, the memory-related vulnerabilities of which expose a significant attack surface for hackers. It would be beneficial to rewrite these languages in safe-by-design languages, such as Rust, but migration of a real system by hand is enormously expensive and time consuming.
This is why, for more than a decade, Galois and Immunant have been developing C2Rust, our automatic migration tool that is able to translate most C modules into semantically equivalent Rust code.
Click the link below to try C2Rust for yourself!
Our original C2Rust transformed C code into unsafe, C-like Rust code. This is the first step of migration, but ultimately, we want Rust that is safe, performant, and idiomatic.
The current state of the art is to run C2Rust, and then for an expert team to migrate the rest of the way. Immunant have done exactly this on the migration of the dav1d codec library to Rust. The next step, currently in active development, is to create an automated migration tool that can fully transform C code to safe, performant Rust.
Even as the C2Rust continues to improve, it is already being widely used — for example, the popular serde_yaml crate is just a wrapper around c2rust-transpiled code. No matter your current tech stack, there are effective ways to integrate C2Rust into your workflow.
This project is available under the BSD-3 license.
Source code and instructions are available in our git repository.
To report issues with the translation or tool, please use our Issue Tracker →
For more information, email us at c2rust@galois.com →
The C2Rust manual is available online and is our comprehensive documentation for using and developing C2Rust.
More information about installing c2rust from crates.io is availble in this introductory blog post:
Per Larsen recently presented a talk on C2Rust at RustConf detailing both our approach to translation as well as our cross-checking approach to testing the resulting translations.
RustConf 2018 - C2Rust: Migrating Legacy Code to Rust
Eric Mertens wrote a blog post describing some of the challenges we encountered during translation of C to Rust and how C2Rust tackles them.
C2Rust Demonstration →
Types that aren't used to generate code are pruned away. Try using your type in a function declaration.
You'll need to include headers to use functions from external libraries.
When the translator can't handle a translating a function for some reason it omits the implementation and prints the reason. This is configurable and visible when you're running the tool locally. Currently this web interface doesn't show warning messages generated during translation.
We've captured many of the features we don't support on the wiki page.