Skip to content
GitHub·

💻Cpp2Rust Translates C++ to Safe Rust Automatically

Automatically convert C++ to safe Rust with a single command

TL;DR

Cpp2Rust is an automatic translator that converts C++ code into fully safe Rust. It uses clang's AST and libcc2rs runtime library, making it easier for developers to switch from C++ to Rust.

Cpp2Rust translates C++ code into fully safe Rust automatically using clang's Abstract Syntax Tree (AST). This tool is a game-changer for teams looking to migrate existing C++ projects to Rust without rewriting everything. It simplifies the translation process and ensures safety by default, with an option to generate unsafe Rust for performance comparisons. The paper detailing this algorithm was published at PLDI 2026. To use it, install dependencies on Ubuntu and run `./build/cpp2rust/cpp2rust --file=<file>.cpp -o=<file>.rs`.

Cpp2Rust Translates C++ to Safe Rust Automatically — GitHub

Key Points

1

Cpp2Rust translates C++ files into fully safe Rust using clang's AST (Abstract Syntax Tree).

2

The algorithm is described in the paper 'Cpp2Rust: Automatic Translation of C++ to Safe Rust' published at PLDI 2026.

3

To build and install, run `sudo apt install libclang-22-dev clang++-22 ninja-build cmake curl -LsSf https://astral.sh/ruff/install.sh | sh` on Ubuntu.

4

By default, Cpp2Rust uses reference counting to produce fully safe Rust code. Unsafe Rust generation is available with the --model=unsafe argument.

5

The generated Rust code relies on libcc2rs runtime library for simplifying translation and ensuring safety.

Why It Matters

Cpp2Rust makes it easier for teams using C++ to migrate their projects to Rust by automatically translating code. If you're developing a large-scale application in C++, consider Cpp2Rust as an option to simplify the transition process while maintaining safety and performance.

Cpp2RustC++Rusttranslation-toolPLDI

Frequently Asked Questions

Why does this matter?

Cpp2Rust makes it easier for teams using C++ to migrate their projects to Rust by automatically translating code. If you're developing a large-scale application in C++, consider Cpp2Rust as an option to simplify the transition process while maintaining safety and performance.

What happened?

Cpp2Rust is an automatic translator that converts C++ code into fully safe Rust. It uses clang's AST and libcc2rs runtime library, making it easier for developers to switch from C++ to Rust.

Comments

Subscribe to join the conversation...

Be the first to comment

Enjoyed this article?

Get it daily. 7am. Free. Reads in 5 minutes.

Join 2,067 builders reading daily.