TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

C2rust: Transpile C to Rust

140 pointsby juancampaover 3 years ago

13 comments

WalterBrightover 3 years ago
We kinda gave up on translating C into D, as many C constructs were unduly awkward to represent in D. What's working much better is to incorporate a C compiler directly into the D compiler. No need to translate, and the C semantics can be adhered to exactly. (The D compiler is extended to understand the C semantics coming from the C code, although that isn't part of the D specification.)
评论 #30173612 未加载
评论 #30172448 未加载
评论 #30173927 未加载
评论 #30173949 未加载
评论 #30177693 未加载
acomjeanover 3 years ago
We used to call fortran transpired into ada: adatran.<p>Adatran was terrible. Hard to impossible to edit if something needed fixing. Used none of the features that made Ada a decent language. The very limited code they did this to did work however. This was a huge project and included C and ada code.<p>What do we call C code transpiled to Rust. Crust?
评论 #30174583 未加载
评论 #30170348 未加载
评论 #30170672 未加载
评论 #30171065 未加载
评论 #30173365 未加载
评论 #30171057 未加载
mastaxover 3 years ago
Not mentioned on this page is the associated refactoring tool (<a href="https:&#x2F;&#x2F;c2rust.com&#x2F;manual&#x2F;c2rust-refactor&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;c2rust.com&#x2F;manual&#x2F;c2rust-refactor&#x2F;index.html</a>) which IME is too complicated to learn in 15 minutes, but would likely be a very useful investment when translating a large code base.
JoelJacobsonover 3 years ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;immunant&#x2F;c2rust" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;immunant&#x2F;c2rust</a>:<p>&gt; We rely on Emscripten&#x27;s Relooper algorithm to translate arbitrary C control flows.<p>Article on why Relooper isn&#x27;t good enough and the superior Stackifier algorithm, which they probably should be using instead:<p><a href="https:&#x2F;&#x2F;medium.com&#x2F;leaningtech&#x2F;solving-the-structured-control-flow-problem-once-and-for-all-5123117b1ee2" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;leaningtech&#x2F;solving-the-structured-contro...</a>
foxfluffover 3 years ago
It seems to &quot;optimize out&quot; volatile reads if the result is not used.
评论 #30180975 未加载
评论 #30174658 未加载
techdragonover 3 years ago
This looks more useful than some other C to Rust tools, as this will work on code directly instead of the finally linked product, allowing you to use it to port larger library collections or SDKs ahead of time for use in a subsequent Rust project. This can also be used on any old random snippet of valid C, (known limitations aside)<p>This will be fantastic for helping encourage Rust on microcontrollers. The microcontroller world is very C heavy, so libraries for daughter board and other chips, and other example code, is often only published in C, despite the growing ecosystem of microcontroller chips and boards that have good support for Rust, you end up constantly pushed towards C due to the ecosystem basically only using C. Having a good tool to take that C code and give at least a mechanical, non-idiomatic Rust port is just fantastic and I&#x27;m looking forward to giving this a shot with a particular add on board SDK that I wanted to use on a Rust supported microcontroller.
detaroover 3 years ago
Have their been any large projects that used this as a starting point for a port? I would be curious how it works out in practice.
评论 #30170243 未加载
评论 #30170198 未加载
评论 #30172225 未加载
评论 #30169899 未加载
评论 #30172626 未加载
评论 #30205445 未加载
评论 #30169492 未加载
andrew_mason1over 3 years ago
Shame it&#x27;s not called `crust`. Very cool though!
rgovostesover 3 years ago
Back in the day there was also Corrode: <a href="https:&#x2F;&#x2F;github.com&#x2F;jameysharp&#x2F;corrode" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jameysharp&#x2F;corrode</a><p>Discussed here: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12056230" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12056230</a>
the-alt-oneover 3 years ago
Why is this a transpiler and not a compiler?
评论 #30175249 未加载
kitdover 3 years ago
Hmm. Transpile C to &quot;Rust&quot;<p>edit: I see it is part of a broader toolchain, which makes a bit more sense
jokoonover 3 years ago
I&#x27;m curious how it manages to work with the borrow checker.
评论 #30176668 未加载
ronloboover 3 years ago
Promising!<p>Has anybody incorporated an AI into c2rust to do the heavy lifting and learning from the compiler errors to self fix the transpiled code?
评论 #30172695 未加载