Deterministic C++ to Rust Transpiler with Industrial-Grade Static Analysis
Project description
c2r: The Industrial C++ to Rust Transpiler
c2r (formerly Ferrum) is a deterministic, static-analysis driven tool designed to migrate legacy C++ codebases to idiomatic, safe Rust. Unlike LLM-based solutions that hallucinate, c2r uses rigorous mathematical models to prove ownership and lifetimes.
🚀 Features
- Deterministic Translation: No AI guessing. Uses Steensgaard's and Andersen's analysis for aliasing.
- Ownership Reconstruction: Infers
Box<T>,Arc<T>,Rc<T>based on usage patterns. - Thread Safety Analysis: Automatically detects data races and injects
Arc<Mutex<T>>. - Cycle Detection: Identifies reference cycles (SCCs) and suggests
Weak<T>orRefCell<T>. - Smart Pointers: Maps
std::unique_ptrandstd::shared_ptrto Rust equivalents. - Safety Audit: Reports a "Safety Score" indicating the ratio of safe/unsafe code generated.
📦 Installation
c2r is available as a Python package with a high-performance Rust backend.
pip install c2r
🛠 Usage
c2r provides a CLI to migrate projects.
Migrate a Project
c2r migrate ./legacy_cpp_project -o ./new_rust_project
This command will:
- Analyze all
.cppand.hfiles in the input directory. - Generate a valid Cargo project structure (
src/models,src/utils). - Create a
Cargo.tomlwith necessary production dependencies (tokio,serde,parking_lot). - Transpile the code, resolving include dependencies and type definitions.
🚀 Publishing to PyPI
To publish a new version of c2r, ensure you have maturin installed.
-
Build Release Artifacts:
maturin build --release
-
Publish to PyPI:
maturin publish
🏗 Architecture
c2r operates on a multi-pass architecture:
- Ingestion (Industrial Frontend): Simulates Clang AST parsing to generate a Property-Oriented Intermediate Representation (PIIR).
- Points-To Analysis:
- Steensgaard ($O(N \alpha(N))$): Fast partitioning of memory regions.
- Andersen ($O(N^3)$): Precise subset-based constraint solving for aliasing.
- Region Inference (Tofte-Talpin): Infers lifetimes (
'a) and scopes. - Cycle Detection: Detects Strongly Connected Components using Tarjan's algorithm concepts.
- Thread Safety Pass: Simulates execution flow to detect concurrent mutations.
- Code Generation: Uses
synandquoteto construct a valid Rust AST.
📊 Benchmarks
c2r includes a built-in benchmarking harness to verify the scalability of its analysis algorithms.
- 100 Pointers: ~0.2ms
- 1,000 Pointers: ~2.2ms
- 5,000 Pointers: ~11.4ms
📄 License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file c2r-1.0.2.tar.gz.
File metadata
- Download URL: c2r-1.0.2.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f7cc76923d7219bab7e676329611febc061b6a58bb4cff321c08888ec699b93
|
|
| MD5 |
2bc74ab0ecd6ae78de425084bad44595
|
|
| BLAKE2b-256 |
c2ed53d1a1ee2a69cfeaccf2511b6881e883494064cb11fef1862b461fddc973
|
File details
Details for the file c2r-1.0.2-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: c2r-1.0.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 968.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
095581323b849f38eb8fdce39b3f9222c1f46555bc75da9545500b895f07fc86
|
|
| MD5 |
ba0e8cf8da9d50b568dcc8a2ff8abbcf
|
|
| BLAKE2b-256 |
d480939dbc97781bd58d06a323aa869d8bf82ebfeb6e4941e5d9966301343416
|