logoalt Hacker News

crustc: entirety of `rustc`, translated to C

164 pointsby Philpaxyesterday at 10:57 PM31 commentsview on HN

Comments

lioetersyesterday at 11:48 PM

> For the past 3 years, I have been working on compiling Rust to C. .. This is, by my count, the 14th attempt: cilly

Gotta respect the dedication to a niche interest.

> The primary goal of this is support for old/obscure hardware with no LLVM/GCC support.

I remember reading about the bootstrapping question, how it typically requires a Rust compiler to build the Rust compiler from source. https://bootstrapping.miraheze.org/wiki/Bootstrapping_Specif...

Oh, but I see there's a C++ implementation of the Rust compiler. https://github.com/thepowersgang/mrustc

Anyway, this part sounds useful too, that crustc can compile across network and devices.

> You build a small C server on your Blorbo OS, run rustc on some normal platform like Linux, and let cilly talk over the wire.

show 2 replies
taris2yesterday at 11:48 PM

Have you tried Diverse Double-Compiling (DDC) to test if the official rust compiler has a backdoor?

Use crustc to compile the rust source code, producing a new compiler. Then use this new compiler and the official rustc binary, both with deterministic flags, to compile the rust source code again. The two outputs should match bit for bit.

show 4 replies
levkkyesterday at 11:48 PM

Very cool. At first, I thought it was yet another LLM-generated demo, but no: original work of art. Super cool. Transpiling into C does seem easier than LLVM IR, and letting GCC optimize seems like this might actually work.

Excited to see the compiler implementation when it's out -- a lot to learn from.

ronsoryesterday at 11:37 PM

> I put my left hand in a blender. The blender won. (Still have all my fingers, just some stitches). I will not elaborate further.

What a shame. I would've read an article about this.

show 2 replies
ahartmetzyesterday at 11:56 PM

Wait, I thought LLVM had a C backend which could be used for the purpose of transpiling Rust to C? Turns out not for a long time, but now maybe again: https://discourse.llvm.org/t/re-ann-llvm-c-backend-still-abl...

npallitoday at 12:55 AM

Rewrite in C is the new Rewrite in Rust.

layer8today at 12:15 AM

Finally we can rewrite all the Rust in C. ;)

Cadwhiskeryesterday at 11:38 PM

> The primary goal of this is support for old/obscure hardware with no LLVM/GCC support. There are still some systems out there that don't support Rust but support C.

The landing page mentions Plan 9 as one of the systems.

SpecialistKtoday at 12:14 AM

I wonder if this could be used in PPC Mac OS X, where LLVM isn't supported and most graphical applications need to use GCC 4 with Apple's SDK.

nxtfaritoday at 12:35 AM

this is really cool but it seems very unlikely that someone targeting an exotic system not supported by rust (mostly embedded and ancient mainframe targets) would be willing to trust a beta transpiler to not inject any bugs or leaks in the process of turning rust to c. nevertheless, very cool.

groostoday at 12:29 AM

As an ex C++ compiler developer, I heartily approve of this project. Kudos.

Tiberiumyesterday at 11:22 PM

I wonder how the performance looks like, because this can be interesting even for non-porting reasons ;)

show 1 reply
Imustaskforhelpyesterday at 11:48 PM

This could be used within https://bootstrappable.org/projects.html to make bootstrappability of rust incredibly much easier other than the previous route of OCaml and other things.

I know some folks within the bootstrappable OS projects community are on Hackernews and I hope that they could take a look at this. I feel as if this project could drastically shrink down the efforts needed to get a working rust compiler in a bootstrappable manner.

show 2 replies
linzhangruntoday at 1:24 AM

Quite an interesting project, lol. I like the name `crustc` :)

CurbStompertoday at 1:21 AM

[dead]

dangoodmanUTtoday at 12:25 AM

i believe the author is confused

this is the wrong direction

(jk i read the readme)