Discussion summary
A project called `crustc` translates Rust to C, sparking varied opinions on its purpose and implications. Some see it as a way to improve portability and debugging, while others question its direction.
What the discussion says
- Some believe it broadens debugging help for portability issues.
- Others think it might lead to feature creep or trust issues with Microsoft/ISO.
- Critics warn about AI-generated content and its impact on discussions.
- Enthusiasts appreciate the project's name and concept.
- There is excitement about Rust and C competition.
“Rust is finally memory safe enough to become C”
“Let Rust vs C battle commence with renewed haste!”
Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- 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.by SpecialistK
- > The primary goal of this is support for old/obscure hardware with no LLVM/GCC support
Wouldn't it be easier to add old hardware support to LLVM/GCC instead? I adore the project scale and determination, but for this goal extending existing projects seems more logical than building a language translator.
by ivanjermakov - Some architecture lacks documentation, if you have a working C compiler, it's easier to use it than working on a compiler to target it.by claudex
- rust to c supports infinite platforms that already have a c compiler by implementing a single rust to c program
on the other hand, porting llvm to an infinite number of platforms requires an infinite amount of work
so, it is less work this way
by jitl - > Wouldn't it be easier to add old hardware support to LLVM/GCC instead?
No, in fact it's much, much harded. You have no idea of the scope. I have no idea of the scope. Nobody does. There are obscure machines we've never heard about and there are C compilers for them. Targeting and supporting them from modern toolchains is a fool's errand.
by Perz1val - As an ex C++ compiler developer, I heartily approve of this project. Kudos.by groos
- Rewrite in C is the new Rewrite in Rust.by npalli
- GTA VI out in Rust before C++?by keyle
- Finally we can rewrite all the Rust in C. ;)by layer8
- As long as we rewrite all the C++ in Rust first.by avadodin
- > 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.
by Cadwhisker - 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.
- Not really. This C code is more like a binary and compiler artifact than a source code. So it won't match the standards of bootstrap.by hkalbasi
- mrustc (a handwritten Rust compiler in C++) is already used for that in Guix and likely other distros: https://guix.gnu.org/blog/2018/bootstrapping-rust/ This would have other benefits though, as it's both a second bootstrapping path and could potentially compile Rust programs for platforms not supported by LLVMby lispwitch
- 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...by ahartmetz
- This approach is harder than you might imagine. LLVM can do a lot of things that don't map to C language constructs. You cannot generally roundtrip arbitrary LLVM IR through some C representation. You can emulate most things, but you won't necessarily get the same LLVM IR in the other end.by simonask
- > 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.
by ronsor - I desperately want to know more.
- But did it Blender open the source?by luke-stanley
- I mean I get confused every time I use blender too but not to the point of losing fingers...by cozzyd
- Nobody who would code this up would be entirely sane. But I can't help thinking "these are my people" when I read this...by RustyRussell
- 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.
by levkk - 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.
by taris2 - Awesome idea!by amir734jj
- This reminds me of https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...by swalberg
- It's not diverse in that case - it's the same compiler source compiled to binaries twice - it's just that with one compiler you've gone via a C intermediate representation. For the purposes of diversity it's the same as compiling rustc with the cranelift/gcc backend.by wmanley
- Better than that, you can get a bootstrapped rust from the Guix project, which has bootstrapped its entire system from source code from only a tiny verifiable binary.by rcxdude
- This was done with mrustc, which produced byte identical output.by steveklabnik
- > 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.
by lioeters - > The primary goal of this is support for old/obscure hardware with no LLVM/GCC support.
If you're going to go to all this effort for an old target though, wouldn't the effort be better spent on making it an LLVM target? Then you'd get Rust and a bunch of other languages for free.
But maybe there are required parts of the LLVM IR that make this undesirable for certain targets, maybe requiring specific hardware features, I don't know. I guess also WASM-as-IR is a possible way to go. (Is that a thing?)
Edit: sorry I see that this point was already raised in this thread by ivanjermakov. Ignore.
by radarsat1