• Stars4.8k+4 tuần này
  • Forks326
  • Watchers52
  • Issues317
  • Ngày tạo20/04/2018
  • Cập nhật gần nhất26/10/2026
  • Ngôn ngữRust
  • Giấy phép—
README.md28.0 KBRaw

C2Rust

ci GitHub Actions Status c2rust-testsuite GitHub Actions Status Latest Version Rustc Version

Intro

C2Rust helps you migrate C99-compliant code to Rust. The transpiler, c2rust transpile, produces unsafe Rust code that closely mirrors the input C code. The primary goal of the transpiler is to preserve functionality; test suites should continue to pass after translation.

The output of c2rust transpile is unsafe and unidiomatic; it is merely the first step in a longer migration process. Generating safe and idiomatic Rust code from C ultimately requires additional work. This work can be done by a human, a large language model, a deterministic tool, or some combination thereof.

flowchart LR
    A[C sources] --> B
    subgraph "C2Rust toolchain"
        B["`c2rust transpile`"] --> C["`c2rust refactor`"]
        C --> D["`c2rust postprocess`"]
    end
    D --> E[Human and/or agentic workflow]
    E --> F[Safe, idiomatic Rust]

    click B "https://github.com/immunant/c2rust/tree/master/c2rust-transpile" "c2rust transpile"
    click C "https://github.com/immunant/c2rust/tree/master/c2rust-refactor" "c2rust refactor"
    click D "https://github.com/immunant/c2rust/tree/master/c2rust-postprocess" "c2rust postprocess"
Loading

For instance, we provide a deterministic refactoring tool to automate cleanup across the files produced by c2rust transpile. We also provide an LLM-powered postprocessing tool for additional types of cleanup that are hard to do deterministically. Even though the postprocessor validates the output of LLMs, it can introduce errors; we recommend using it in combination with a robust test suite.

You can also cross-check the translated code against the original (tutorial).

You can try c2rust transpile directly in the Compiler Explorer. This uses the current master branch, updated every night.

Documentation

To learn more about using and developing C2Rust, check out the manual. The manual is still a work-in-progress, so if you can't find something please let us know. c2rust.com/manual/ also has not been updated since ~2019, so refer to the in-tree

Nội dung README thuộc về immunant và cộng đồng đóng góp, giấy phép Không có giấy phép. Nguồn: github.com/immunant/c2rust