# immunant/c2rust

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/immunant-c2rust).**

4,642 stars · 293 forks · Rust · other

## Links

- GitHub: https://github.com/immunant/c2rust
- Homepage: https://c2rust.com/
- awesome-repositories: https://awesome-repositories.com/repository/immunant-c2rust.md

## Topics

`memory-safety` `migration` `rust` `security-hardening` `translation` `transpiler`

## Description

c2rust is a source-to-source translation suite and C-to-Rust transpiler designed to convert C source code and libraries into functionally equivalent unsafe Rust code. It operates as a pipeline that preserves original behavior and data structures, producing translated code that compiles as compatible shared libraries or Rust crates.

The system includes an automated Rust refactoring framework that uses pattern-based AST rewriting to transform unsafe Rust into safe, idiomatic constructs. It utilizes an ownership inference engine to determine when raw pointers can be converted into safe references or owned values, and it generates byte-compatible bitfield structs with typed accessors.

To ensure correctness, the project provides cross-execution verification tools that instrument binaries to detect state discrepancies and verify execution parity at the function-call level. The suite also covers structural refactoring, automated type error correction, and the generation of build files and crate directories for the translated output.

## Tags

### Programming Languages & Runtimes

- [C Library Migration Tools](https://awesome-repositories.com/f/programming-languages-runtimes/c-library-migration-tools.md) — Translates complete C library source trees into compatible Rust crates with build configurations and external binding management.
- [Semantic-Preserving Transpilers](https://awesome-repositories.com/f/programming-languages-runtimes/semantic-preserving-transpilers.md) — Converts C constructs into functionally equivalent unsafe Rust code to ensure initial behavioral parity.
- [Source-To-Source Transpilers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/source-to-c-transpilers/source-to-source-transpilers.md) — Provides a comprehensive pipeline for transpiling C libraries into Rust crates.
- [C-to-Rust Transpilers](https://awesome-repositories.com/f/programming-languages-runtimes/c-to-rust-transpilers.md) — Translates C source code into functionally equivalent unsafe Rust code while preserving original behavior and data structures.
- [Crate Generators](https://awesome-repositories.com/f/programming-languages-runtimes/crate-generators.md) — Produces a full project directory including build scripts and metadata from original source code. ([source](https://c2rust.com/manual/examples/grabc/index.html))
- [Unsafe Block Elimination](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/language-extensions/unsafe-code/unsafe-block-elimination.md) — Eliminates unsafe blocks from source code while preserving original functionality to ensure full safety. ([source](https://c2rust.com/manual/c2rust-refactor/index.html))
- [Safe Pointer Type Conversions](https://awesome-repositories.com/f/programming-languages-runtimes/safe-pointer-type-conversions.md) — Transforms unsafe raw pointer types into safe array or reference types that include bounds checking. ([source](https://c2rust.com/manual/examples/robotfindskitten/index.html))
- [Structural Pattern Matching](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching.md) — Parses pattern strings into syntax fragments and matches them against source code to extract transformation bindings. ([source](https://c2rust.com/manual/c2rust-refactor/doc/scripting_api.html))
- [Byte-Compatible Bitfield Generators](https://awesome-repositories.com/f/programming-languages-runtimes/byte-compatible-bitfield-generators.md) — Generates Rust structs with typed accessors that maintain identical memory layouts to C bit-fields.
- [Type and Data Restructuring](https://awesome-repositories.com/f/programming-languages-runtimes/program-entry-points/type-and-data-restructuring.md) — Converts functions to methods and unions to enums while adjusting binary interfaces for compatibility. ([source](https://c2rust.com/manual/c2rust-refactor/commands.html))
- [Struct Property Accessors](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structures/struct-generators/struct-property-accessors.md) — Generates typed getter and setter methods for bit-level fields in Rust structures. ([source](https://c2rust.com/manual/c2rust-bitfields/index.html))
- [Type Conversion and Casting](https://awesome-repositories.com/f/programming-languages-runtimes/type-conversion-and-casting.md) — Changes types for variables and arguments and propagates these adjustments using casts or conversion functions. ([source](https://c2rust.com/manual/c2rust-refactor/commands.html))
- [Type-Safe Formatting Conversions](https://awesome-repositories.com/f/programming-languages-runtimes/type-safe-formatting-conversions.md) — Replaces variadic formatting calls with type-safe macros to eliminate unsafe string operations. ([source](https://c2rust.com/manual/examples/robotfindskitten/index.html))

### Development Tools & Productivity

- [AST-Based Source Transformations](https://awesome-repositories.com/f/development-tools-productivity/ast-transformation-tools/ast-to-source-conversion/ast-based-source-transformations.md) — Matches syntax tree nodes against templates to perform targeted automated transformations and structural code changes.
- [Automated Rust Refactoring Frameworks](https://awesome-repositories.com/f/development-tools-productivity/automated-rust-refactoring-frameworks.md) — Provides a pattern-based AST rewriting engine that transforms unsafe Rust code into safe and idiomatic constructs.
- [Refactoring Tools](https://awesome-repositories.com/f/development-tools-productivity/refactoring-tools.md) — Rewrites translated unsafe code into idiomatic patterns using specialized refactoring tools to improve safety. ([source](https://c2rust.com/manual/docs/source_walkthrough.html))
- [Build System Templates](https://awesome-repositories.com/f/development-tools-productivity/build-tooling/template-compilation-tools/build-time-template-validation/build-system-templates.md) — Creates project configuration files for libraries or binaries to support the compilation of transpiled source files. ([source](https://cdn.jsdelivr.net/gh/immunant/c2rust@master/README.md))
- [Build Configuration File Generators](https://awesome-repositories.com/f/development-tools-productivity/project-file-generators/build-configuration-file-generators.md) — Creates project configuration files for translated code to compile as a library or binary. ([source](https://c2rust.com/manual/c2rust-transpile/index.html))

### Operating Systems & Systems Programming

- [Library Transpilation](https://awesome-repositories.com/f/operating-systems-systems-programming/c-libraries/library-transpilation.md) — Converts complete C library source trees into equivalent Rust code that compiles as shared libraries. ([source](https://c2rust.com/manual/examples/json-c/index.html))
- [Semantic-Preserving Unsafe Conversions](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/memory-safety-and-semantics/unsafe-blocks/semantic-preserving-unsafe-conversions.md) — Translates C constructs into functionally equivalent unsafe Rust code that maintains original test suite results.

### Software Engineering & Architecture

- [AST-Based Refactorers](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-tools/internal-tree-representations/ast-based-refactorers.md) — Uses pattern-based syntax tree matching and rewriting to perform bulk transformations on source code. ([source](https://c2rust.com/manual/c2rust-refactor/doc/scripting_api.html))
- [Safe FFI Substitutions](https://awesome-repositories.com/f/software-engineering-architecture/binary-linking-interfaces/ffi-interfaces/safe-ffi-bridge-definitions/safe-ffi-substitutions.md) — Replaces calls to external functions and macros with safe library wrappers or standard equivalents. ([source](https://c2rust.com/manual/examples/robotfindskitten/index.html))
- [Pattern-Based Replacements](https://awesome-repositories.com/f/software-engineering-architecture/code-transformation-tools/pattern-based-replacements.md) — Replaces matched statements or expressions with new syntax produced by a callback or a pattern template. ([source](https://c2rust.com/manual/c2rust-refactor/doc/scripting_api.html))
- [Ownership Inference Engines](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling/type-inference-engines/ownership-inference-engines.md) — Analyzes raw pointer usage to determine which should become safe references or owned values in the translated code.
- [Unsafe to Safe Rust Refactoring](https://awesome-repositories.com/f/software-engineering-architecture/unsafe-to-safe-rust-refactoring.md) — Rewrites automatically translated unsafe Rust into safer, more idiomatic constructs using pattern-based transformations and ownership inference.
- [Ownership Inference Engines](https://awesome-repositories.com/f/software-engineering-architecture/unsafe-to-safe-rust-refactoring/ownership-inference-engines.md) — Deno Bitfield analyzes raw pointers in translated code to determine which should become safe references or owned values. ([source](https://c2rust.com/manual/c2rust-refactor/src/analysis/ownership/index.html))
- [Global State Migration Tools](https://awesome-repositories.com/f/software-engineering-architecture/global-state-migration-tools.md) — Gathers global mutable statics into a single structure and passes it by reference to enable safety checks. ([source](https://c2rust.com/manual/examples/robotfindskitten/index.html))

### Testing & Quality Assurance

- [Behavioral Equivalence Checkers](https://awesome-repositories.com/f/testing-quality-assurance/behavioral-equivalence-checkers.md) — Compares the execution of C and Rust code versions at the function-call level. ([source](https://c2rust.com/manual/intro.html))
- [Cross-Execution Instrumentations](https://awesome-repositories.com/f/testing-quality-assurance/cross-execution-instrumentations.md) — Inserts runtime checks into both source and translated binaries to compare function-level execution behavior and state.
- [Parity Test Suites](https://awesome-repositories.com/f/testing-quality-assurance/implementation-parity-testing/parity-test-suites.md) — Verifies identical behavior across different language implementations by comparing compiled binaries. ([source](https://c2rust.com/manual/))
- [Translation Parity Validations](https://awesome-repositories.com/f/testing-quality-assurance/translation-parity-validations.md) — Runs original test suites against compiled Rust output to confirm behavioral equivalence with the original C code. ([source](https://c2rust.com/manual/examples/json-c/index.html))
- [Type-Aware Memory Hashing](https://awesome-repositories.com/f/testing-quality-assurance/type-aware-memory-hashing.md) — Processes memory values using algorithms that ignore padding and dereference pointers to ensure consistent behavioral comparison.

### Part of an Awesome List

- [Foreign Declaration Management](https://awesome-repositories.com/f/awesome-lists/devtools/external-bindings/foreign-declaration-management.md) — Replaces foreign declarations with internal definitions and standardizes external references by merging duplicates. ([source](https://c2rust.com/manual/c2rust-refactor/commands.html))
- [Developer Tools](https://awesome-repositories.com/f/awesome-lists/devtools/developer-tools.md) — Translates C code to Rust using Clang/LLVM.

### Data & Databases

- [Byte-Compatible Struct Generators](https://awesome-repositories.com/f/data-databases/bitfield-operations/byte-compatible-struct-generators.md) — Generates byte-compatible Rust structs with typed getters and setters to match C bit-fields.
- [Cross-Check Hashing Algorithms](https://awesome-repositories.com/f/data-databases/hash-tables/custom-hashing-implementations/deterministic-hashing/cross-check-hashing-algorithms.md) — Uses type-aware hashing that ignores padding and dereferences pointers for consistent state comparison. ([source](https://c2rust.com/manual/docs/cross-check-hash.html))
- [Automated Type Fixes](https://awesome-repositories.com/f/data-databases/type-mapping-utilities/type-mapping-converters/automatic-type-converters/automated-type-fixes.md) — Applies type patterns to automatically resolve and fix type errors found within the code. ([source](https://c2rust.com/manual/c2rust-refactor/rewrite.html))
