Skip to main content

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> or RefCell<T>.
  • Smart Pointers: Maps std::unique_ptr and std::shared_ptr to 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:

  1. Analyze all .cpp and .h files in the input directory.
  2. Generate a valid Cargo project structure (src/models, src/utils).
  3. Create a Cargo.toml with necessary production dependencies (tokio, serde, parking_lot).
  4. Transpile the code, resolving include dependencies and type definitions.

🚀 Publishing to PyPI

To publish a new version of c2r, ensure you have maturin installed.

  1. Build Release Artifacts:

    maturin build --release
    
  2. Publish to PyPI:

    maturin publish
    

🏗 Architecture

c2r operates on a multi-pass architecture:

  1. Ingestion (Industrial Frontend): Simulates Clang AST parsing to generate a Property-Oriented Intermediate Representation (PIIR).
  2. Points-To Analysis:
    • Steensgaard ($O(N \alpha(N))$): Fast partitioning of memory regions.
    • Andersen ($O(N^3)$): Precise subset-based constraint solving for aliasing.
  3. Region Inference (Tofte-Talpin): Infers lifetimes ('a) and scopes.
  4. Cycle Detection: Detects Strongly Connected Components using Tarjan's algorithm concepts.
  5. Thread Safety Pass: Simulates execution flow to detect concurrent mutations.
  6. Code Generation: Uses syn and quote to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2r-1.0.2.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

c2r-1.0.2-cp311-cp311-win_amd64.whl (968.9 kB view details)

Uploaded CPython 3.11Windows x86-64

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

Hashes for c2r-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0f7cc76923d7219bab7e676329611febc061b6a58bb4cff321c08888ec699b93
MD5 2bc74ab0ecd6ae78de425084bad44595
BLAKE2b-256 c2ed53d1a1ee2a69cfeaccf2511b6881e883494064cb11fef1862b461fddc973

See more details on using hashes here.

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

Hashes for c2r-1.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 095581323b849f38eb8fdce39b3f9222c1f46555bc75da9545500b895f07fc86
MD5 ba0e8cf8da9d50b568dcc8a2ff8abbcf
BLAKE2b-256 d480939dbc97781bd58d06a323aa869d8bf82ebfeb6e4941e5d9966301343416

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page