HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
jameysharp
corrode
Haskell2016–2025
jameysharp / corrode

corrode

C to Rust translator

27Distinct people
32Mentions
0Explicit recommenders
2.2KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

C to Rust translator

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 8–Nov 15 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/15/2026, 6:01:32 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 year32 dated mentions

Observed mentions: 2016-07-04 23:31:17 UTC to 2025-11-03 17:32:56 UTC.

0510152016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 10 mentions; 2 submissions, 8 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 15 mentions; 1 submissions, 14 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-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): 0 mentions; 0 submissions, 0 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025

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
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC1028
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC15114
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC202
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC101
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC101
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC101
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 UTC000
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC101

From the project README

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

Read the project’s introduction
Corrode: Automatic semantics-preserving translation from C to Rust This program reads a C source file and prints an equivalent module in Rust syntax. It's intended for partial automation of migrating legacy code that was implemented in C. This tool does not fully automate the job because its output is only as safe as the input was; you should clean up the output afterward to use Rust features and idioms where appropriate. Quick Start As of now, there are no pre-built binaries available, so you need to build the project yourself, but don't let that scare you away; clone the project, cd into it and follow along :) Windows If you're using Windows, start by running fixGitSymlinksForWindows.bat as admin (this is necessary for Git to create symlinks). Cabal Ensure that you have GHC and the cabal-install tool installed by following the directions on haskell.org. You'll also need to have the happy and alex tools available in order to build corrode: you can install them with the cabal-install tool, as well. Once you have installed the cabal-install tool, you can build corrode by navigating to the corrode directory, installing the happy and alex tools, and then building and installing the corrode package: cabal install happy cabal install alex cabal install This puts the corrode executable in ~/.cabal/bin, so ensure that that location is in your $PATH. Alternate instructions: Stack Alternately, you can use the Haskell Stack tool for Haskell development. If you don't have it, head over to their website and follow the instructions for installing it on your machine. Install the Glasgow Haskell Compiler using stack setup. You can skip this step if you already have a version of GHC installed on your system. You can then build and install corrode by navigating to the corrode directory and running: stack install Stack will build and install corrode to ~/.local/bin. For ease of use, make sure that directory is in your $PATH. To experiment with the project itself, you can build it using stack build then run the executable: stack exec -- corrode -Wall filename.c -I/usr/local/include -lm Usage There are two ways to use Corrode. You can simply generate a .rs file from the C source, or you can do this and compile in one step. Generating Rust source You can now run corrode, giving it any options that gcc would accept. corrode -Wall filename.c -I/usr/local/include -lm It will only use the options that are relevant to the C pre-processor, like -I or -D, but since it accepts and ignores any other options, you can usually get going just by changing gcc to corrode in the gcc invocation you've been using. Unlike a real C compiler, Corrode does not produce an object file or executable! Instead, if you ask it to process filename.c, it generates equivalent Rust source code in filename.rs. If you do want object code, there is a script to help with that. Codegen with compilation You can either invoke rustc on Corrode's output yourself (or import it into a Rust project), or use the scripts/corrode-cc tool in place of gcc to compile and link. In many build systems, such as make, you can simply set CC=corrode-cc without modification. Design principles The overarching goal of Corrode is to preserve the original properties of the source program as much as possible: behavior, ABI compatibility, and maintainability. We expect the output of Corrode to be used to replace the original C, not just as an intermediate step in a compiler toolchain. Corrode aims to produce Rust source code which behaves exactly the same way that the original C source behaved, if the input is free of undefined and implementation-defined behavior. In the presence of undefined behavior, we've tried to pick a behavior that isn't too surprising. For example, if a signed addition might overflow (which is undefined behavior in C), Corrode just translates it to Rust's + operator, which panics on overflow in debug builds. The compiled Rust source in turn will be ABI-compatible with the original C. If you compile Corrode-generated Rust to a .o file, you can link to it exactly as if it were generated from the original C. Every function that Corrode generates with be annotated with the extern "C" modifier. At the same time, Corrode should produce code which is recognizably structured like the original, so that the output is as maintainable as the original. Every statement and every expression should be represented in the output—in the same order, where possible. If a programmer went to the trouble to put something in, we usually want it in the translated output; if it's not necessary, we can let the Rust compiler warn about it. If either behavior or ABI is not preserved, we consider that a bug in Corrode. However, it is not always possible to preserve the structure of the original code, so we do the best that we can. Testing So far, Corrode has primarily been tested by generating random C programs using csmith, fixing Corrode until it can handle all syntax used in that particular program, and verifying that the resulting Rust module compiles without errors. Verifying that the translated output is equivalent to the input is not trivial. One approach I think is worth trying is to use the Galois Software Analysis Workbench to prove that the LLVM bitcode generated from clang on a C source file is equivalent to the LLVM bitcode generated from rustc on a Rust source file from Corrode. SAW uses a symbolic simulator over LLVM bitcode to extract logical formulas representing the behavior of each function, and then uses an SMT solver to prove equivalence between pairs of formulas. Generating large numbers of random C programs using csmith and then proving the translation results equivalent for each one should give pretty good confidence in the implementation. Because the project is still in its early phases, it is not yet possible to translate most real C programs or libraries. But if you have one you particularly want to try out, I'd love to get pull requests implement
Read the full README on GitHub

What Hacker News says

10 sources
> Hence the comment "With all the usual disclaimers about the inaccuracy of benchmarks". But it still gives a good, practical starting point for discussions. You're welcome to provide a counter data set to further the discussion. There is nothing you can do in C++ that you can't do in Rust as far as memory is concerned. The compiler backends are even identical! You can drop libstd if you want in Rust, which you probably would in the microcontroller use case. You can even translate C to Rust [1], which should result in virtually identical LLVM IR! That's what's so frustrating about throwing out benchmarks game numbers: the languages are isomorphic, so you end up ultimately comparing things like jemalloc implementations. > Like ATMega? If an architecture is supported in modern versions of GCC, there's a good chance that it's needed by someb
Read the rest
ody. And that doesn't count the dozens of specialized C compilers for other non-standard architectures. Modern banks are still running Cobol on mainframes, after all, and microcontrollers are everywhere. Why is COBOL on mainframes relevant? We're talking about C++ here. (Anyway, if you want to bring up mainframes, IBM has a working SystemZ backend for LLVM.) Talking about "microcontrollers" is too broad of a brush. A lot of microcontrollers are ARM (or MIPS, etc.). Rust runs just fine on those. > Ultimately, with enough time and money, Rust is capable of competing with C for the embedded space, making a lot of embedded developers happy. But not in the forseeable future. This is again way too strong of a statement, because we have people using Rust right now for embedded IoT use cases (including some at Mozilla!) It all depends on what you need. If LLVM supports your architecture (which is probably does) then great! If it doesn't, then let's talk about the specific architecture you need and what you need it for, rather than making blanket "Rust is a non-starter for embedded use" statements. We're never going to get support for every architecture anyone can come up with that C has ever run on. But who cares? What matters is whether Rust runs on a platform you were seriously considering using Rust for. If it doesn't, then we can get that fixed; chances are if you want that architecture, someone else using LLVM does too. [1]: https://github.com/jameysharp/corrode
In BearSSL – Smaller SSL/TLS
I hate that way of looking at it because I think it's totally wrong. C (this view is usually presented as only about c) isn't fundamental or bedrock in any way. Most of our current stacks just happen to be written in it. The original Mac OS for instance was written in Pascal and C. The most popular open source compilers are written in c++. Most browsers are written in c++ not in c. And there's no reason these days you couldn't rewrite llvm (a set of compiler libraries and compilers mostly written in c++, not that rust compiler uses llvm for code generation but the frontend is in rust) in haskell or java or javascript(they'd be slower but they would work). Haskell has useful features for writing compilers and a lot of language analysis libraries already. If you re-wrote in in rust it'd be just as fast. Hell this guy (https://github.com/jam
Read the rest
eysharp/corrode) wrote a rust-c source-to-source compiler in literate haskell. Also in a few years servo will be a full browser in rust and Firefox is already adding components written in rust. Other then os interface & c binary api linking there is nothing special about c or c++.
In Memory management in C programs (2014)
Not to look a gift horse in the mouth, but it seems like Corrode misses some other chances to use idiomatic Rust: 1. Rust fn:main doesn't need to return something. 2. The arguments to main aren't mutated, so Rust doesn't need to declare them as mutable. 3. Ditto for the argument to printf. Anyone know how easy it is to recognize and code for such cases in the transpiler? Edit: It looks like they might have opposite design goals [1]: "Corrode aims to produce Rust source code which behaves exactly the same way that the original C source behaved, if the input is free of undefined and implementation-defined behavior. ... If a programmer went to the trouble to put something in, I want it in the translated output; if it's not necessary, we can let the Rust compiler warn about it." (Edit2: cleaned up and numbered) [1] https://github.com/jameysh
Read the rest
In Corrode: C to Rust translator written in Haskell
Absolutely blown away by the detail of the documentation. The main logic of this project is in a literate haskell file you can easily read on GitHub. https://github.com/jameysharp/corrode/blob/master/src/Langua... I wonder how readable is to someone who isn't experienced in Haskell. To me reads like a breeze, but I have a project using the exact same parsing library so maybe that puts me at an advantage. The language-c library he uses is an excellent one, it's a fully spec compliant C parser that's well maintained. I've based my C compiler on it and I haven't encountered any C code it couldn't parse yet. One time I upgraded to a new OSX and Apple added some stupid thing to their headers that broke the parser and a fix was merged within days. This means it takes away the entire headache of parsing C leaving just the actual compiling.
In Corrode: C to Rust translator written in Haskell

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.