HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
immunant
c2rust
Rust2018–2026
immunant / c2rust

c2rust

Migrate C code to Rust

32Distinct people
56Mentions
0Explicit recommenders
4.8KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Migrate C code to Rust

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year56 dated mentions

Observed mentions: 2018-07-02 07:57:04 UTC to 2026-07-05 04:29:23 UTC.

0510152018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments20182019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 14 mentions; 1 submissions, 13 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 11 mentions; 0 submissions, 11 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 4 mentions; 2 submissions, 2 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 7 mentions; 1 submissions, 6 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 7 mentions; 1 submissions, 6 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC606
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC14113
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC11011
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC422
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC716
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC101
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC404
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC716
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC202

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
C2Rust 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 ./manual/ for more up-to-date instructions. Installation Prerequisites C2Rust requires LLVM 15 or later with its corresponding clang compiler and libraries. Python (through uv), CMake 3.5 or later and openssl (1.0) are also required. These prerequisites may be installed with the following commands, depending on your platform: Python: curl -LsSf https://astral.sh/uv/install.sh | sh uv venv uv pip install -r scripts/requirements.txt Ubuntu 22.04, Debian 12, and later: apt install build-essential llvm clang libclang-dev cmake libssl-dev pkg-config git Depending on the LLVM distribution, the llvm-dev package may also be required. For example, the official LLVM packages from apt.llvm.org require llvm-dev to be installed. Arch Linux: pacman -S base-devel llvm clang cmake openssl NixOS / nix: nix-shell macOS: Xcode command-line tools and recent LLVM (we recommend the Homebrew version) are required. xcode-select --install brew install llvm cmake openssl The C2Rust transpiler now builds using a stable Rust compiler. If you are developing other features, you may need to install the correct nightly compiler version. Installing from crates.io cargo install --locked c2rust You can also set the LLVM version explicitly if you have multiple installed, like this, for example: LLVM_CONFIG_PATH=llvm-config-15 cargo install --locked c2rust If you're using LLVM from Homebrew (either on Apple Silicon, Intel Macs, or Linuxbrew), you can run: LLVM_CONFIG_PATH="$(brew --prefix)/opt/llvm/bin/llvm-config" cargo install --locked c2rust or for a specific LLVM version, LLVM_CONFIG_PATH="$(brew --prefix)/opt/llvm@22/bin/llvm-config" cargo install --locked c2rust On Gentoo, you need to point the build system to the location of libclang.so and llvm-config as follows: LLVM_CONFIG_PATH=/path/to/llvm-config LIBCLANG_PATH=/path/to/libclang.so cargo install --locked c2rust If you have trouble with building and installing, or want to build from the latest master, the developer docs provide more details on the build system. Installing from Git If you'd like to check our recently developed features or you urgently require a bugfixed version of c2rust, you can install it directly from Git: cargo install --locked --git https://github.com/immunant/c2rust.git c2rust Please note that the master branch is under constant development and you may experience issues or crashes. You should also set LLVM_CONFIG_PATH accordingly if required as described above. Nightly Tools c2rust and c2rust-transpile are installed by default and can be built on stable rustc. The other tools, such as c2rust-refactor, use rustc internal APIs, however, and are thus pinned to a specific rustc nightly version: nightly-2023-04-15. These are also not published to crates.io. To install these, these can be installed with cargo with the pinned nightly. For example, cargo +nightly-2023-04-15 install --locked --git https://github.com/immunant/c2rust.git c2rust-refactor However, we recommend installing them from a full checkout, as this will resolve the pinned nightly automatically: git clone https://github.com/immunant/c2rust.git cd c2rust cargo build --release These tools, like c2rust-refactor, can then also be invoked through c2rust as c2rust refactor, assuming they are installed in the same directory. Translating C to Rust To translate C files specified in compile_commands.json (see below), run the c2rust tool with the transpile subcommand: c2rust transpile compile_commands.json c2rust also supports a trivial transpile of source files, e.g.: c2rust transpile project/*.c project/*.h For non-trivial projects, the translator requires the exact compiler commands used to build the C code. This information is provided via a compilation database file named compile_commands.json (note that it must be named exactly compile_commands.json; otherwise libclangTooling can have (silent) trouble resolving it correctly). (Read more about compil
Read the full README on GitHub

What Hacker News says

56 sources
> I've heard the meme that AI written rust code is absurdly full and safe blocks but... that's pretty funny. If I understand what happened here correctly this isn't really a case of any such meme, but the result of the porters (heh) telling the LLM to directly convert zig code using unsafe to match the previous code "exactly". I.e. more like using the LLM as a fancy version of c2rust [1] (which would result in just as much unsafe) than a result of LLMs reaching for escape hatches too liberally. [1] https://github.com/immunant/c2rust
In Command and Conquer Generals natively ported to macOS, iPhone, iPad using Fable
c2rust can generate UB in Rust even when there is no UB in the original C. It isn't bug-free, and C and Rust's undefined behavior semantics overlap but aren't identical. One example: https://github.com/immunant/c2rust/issues/1678 I firmly believe the right way to port C and C++ (and Zig) programs to Rust is to do it module by module ("Ship of Theseus"). It needs scrutiny by folks who know both languages deeply, and you can port test cases too so you can detect UB at runtime (using tools like Miri). That's what fish did, and their port has been quite successful. Blindly trusting the results of a machine translation is never a good idea. Especially when the translator has a temperature parameter.
In Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"
I did take a look at the projects which attempt to address conversion of C to Rust and even if article talk about about uplifting C to idiomatic Rust, or to utilize decompilation techniques, I do not see anything of that in any existing project. - C2Rust: https://github.com/immunant/c2rust From what I see, very limited testing of what C can be uplifted. - Citrus: https://gitlab.com/citrus-rs/citrus Overall almost no tests. I would not even mention this project, since it seems to be working on hope. https://gitlab.com/citrus-rs/citrus/-/tree/master/tests?ref_... - Corrode: https://github.com/jameysharp/corrode Written in Haskel, not in Rust as others, have potential, since they utilize csmith for testing.But still lack of testing. https://github.com/jameysharp/corrode/tree/master/scripts I really don't see any project which attempt to reve
Read the rest
rse engineer Rust idioms from C, even if in limited contexts. Maybe the goal of the article to inspire all of us. Or Maybe I miss some other existings projects?
In Automatically Translating C to Rust
There's non-LLM research towards doing this which has a few success stories: https://github.com/immunant/c2rust LLMs seem generally unsuited for the task, because they're fundamentally approximators that won't always get things right, and as a result will introduce subtle bugs. Perhaps if you paired them with some sort of formal methods... I'm not aware of anyone doing that. Tests aren't sufficient - lots of subtle bugs will not be caught by existing test suites. Your idea of "smaller" projects is not... smaller enough. See the actual success stories for example: https://github.com/immunant/c2rust?tab=readme-ov-file#uses-o...
In Upcoming Rust language features for kernel development
I don't think anyone is suggesting that the generated Rust is nicer than the original C. It is auto-generated with the purpose of maintaining the exact same semantics as the C code, with no regard to safety, best practices, etc.—of course it is messier than actual, handwritten Rust. As c2rust says in its documentation [1], it's meant to be the first step in an otherwise manual and incremental port of a codebase from C to Rust, and the author recognizes this in their closing remarks: > The next goal is to convert the codebase to safe Rust. [1] https://github.com/immunant/c2rust/raw/master/docs/c2rust-ov...
In Introducing tmux-rs
Converting C to legal (unsafe) Rust is quite possible; there is indeed already a tool that does this (https://github.com/immunant/c2rust). The problem you run into is that the conversion is so pedantically correct that the resulting code is useless. The result retains all of the problems that the C code has, and is so far from idiomatic Rust that it's easier to toss the code and start from scratch. Progressive lifting on unsafe Rust to safe Rust is a very difficult order, and the tool I mentioned had a tool to do that... which is now abandoned and unmaintained. At the end of the day, the chief issue with converting to safe Rust is not just that you have to copy semantics over, but you also have to recover a lot of high-level preconditions. Turning pointers into slices is perhaps the easiest task of the lot; given the very strict mutabilit
Read the rest
y rules in Rust, you also have to work out when and where to insert things like Cell or Rc or Mutex or what have you, as well as building out lifetime analysis. And chances are the original code doesn't get all these rules right, which is why there are bugs in the first place. Solving that problem is the goal of this DARPA proposal, or perhaps more accurately, determining how feasible it is to solve that problem automatically. Personally, I think the better answer is to have a semi-automated approach, where users provide as input the final Rust struct layouts (and possibly parts of the API, to fix lifetime issues), and the tool automates the drudgery of getting the same logic ported to that mapping.
In Translating All C to Rust (TRACTOR)
I have to imagine that in the general case it will be a translation to unsafe Rust, with occasional isolated leaf nodes being translated to safe Rust. If you think it's hard wrestling with the borrow checker, just imagine how much harder it is to write automatic translation to borrow-checker-approved code that accounts for all the possible program space of C and all it's celebrated undefined behavior. A classic problem of writing compilers is that the space of valid programs is much larger than the space of programs which will compile. A quick web search reveals some other efforts, such as c2rust [1]. I wonder how TRACTOR differs. [1] https://github.com/immunant/c2rust
In Translating All C to Rust (TRACTOR)
A recent practical example of the former: the fish shell re-wrote incrementally from C++ to Rust, and is almost finished https://github.com/fish-shell/fish-shell/discussions/10123 An example of the latter: c2rust, which is a work in progress but is very impressive https://github.com/immunant/c2rust It currently translates into unsafe Rust, but the strategy is to separate the "compile C to unsafe Rust" steps and the "compile unsafe Rust to safe Rust" steps. As I see it, as it makes the overall task simpler, allows for more user freedom, and makes the latter potentially useful even for non-transpiled code. https://immunant.com/blog/2023/03/lifting/
In Converting the Kernel to C++

Showing the 15 most recent of 56 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.