C source code
void insertion_sort(int const n, int * const p) { for (int i = 1; i < n; i++) { int const tmp = p[i]; int j = i; while (j > 0 && p[j-1] > tmp) { p[j] = p[j-1]; j--; } p[j] = tmp; } }
Output

About C2Rust

The C2Rust project is being developed by Galois and Immunant. This tool is able to translate most C modules into semantically equivalent Rust code. These modules are intended to be compiled in isolation in order to produce compatible object files. We are developing several tools that help transform the initial Rust sources into idiomatic Rust.

The translator focuses on supporting the C99 standard. C source code is parsed and typechecked using clang before being translated by our tool.

This project is available under the BSD-3 license.

Downloads

Source code and instructions are available in our git repository.

Learn More

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 Challenges

Environment

Host environment
The translator is running on Ubuntu 16.04.4 LTS with x86_64 architecture. With this approach to translation details of the host system's libraries can be embedded in the translation. The generated C code might not link correctly on other platforms.
Rust environment
The generated code is currently targeting:
nightly-2018-06-20
Translator flags
The transpile.py script is being invoked with the following flags enabled in the ast-importer:
--reloop-cfgs --translate-entry --debug-labels

FAQ

Why isn't my type definition translated?
Types that aren't used to generate code are pruned away. Try using your type in a function declaration.
Why isn't printf available?
You'll need to include headers to use functions from external libraries.
Why was my function omitted?
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.
What are the known limitations?
We've captured many of the features we don't support on the Known Limitations of Translation wiki page.

Contact

To report issues with the translation, please use our Issue Tracker.

The development team can be reached by email at c2rust@immunant.com.