- > 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.
- 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.
- 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.
- > 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 ahartmetz
1 subcomments
- 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 Cadwhisker
0 subcomment
- > 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.
- Finally we can rewrite all the Rust in C. ;)
by ivanjermakov
3 subcomments
- > 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.
- Rewrite in C is the new Rewrite in Rust.
- As an ex C++ compiler developer, I heartily approve of this project. Kudos.
by SpecialistK
0 subcomment
- 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 adithyassekhar
0 subcomment
- I'll wait for rustcrustc
by Archit3ch
1 subcomments
- If I understand this correctly, you could run this compiler on iPadOS (since it's plain C). But you cannot mark it's output executable, since that would require JIT entitlement.
- We should port it to Rust.
by kube-system
0 subcomment
- What sort of hardware would this be useful for?
by Imustaskforhelp
2 subcomments
- 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.
- I wonder how the performance looks like, because this can be interesting even for non-porting reasons ;)
- 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.
by micheleeet
1 subcomments
- Rust is finally memory safe enough to become C
- There are discussions of round-trip between Rust and C;
Would this be useful for this too?
From https://news.ycombinator.com/item?id=46265855 :
> To better port C to Rust: 3C (Checked C), c2rust, Crown ownership analysis, RustMap, c2saferrust (LLM), Laertes
C -> Checked C -> Rust
Because Checked C will annotate the raw and other C pointers first.
- Let Rust vs C battle commence with renewed haste!
- Kudos.
by linzhangrun
0 subcomment
- Quite an interesting project, lol. I like the name `crustc` :)
- Not to be confused with crust [1] the dialect of rust B [2][3] is written in.
[1] https://github.com/tsoding/crust
[2] https://github.com/bext-lang/b
[3] https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman...
by valentynkit
0 subcomment
- [dead]
by CurbStomper
0 subcomment
- [dead]
- [dead]
- [flagged]
- The most interesting part of this to me is not “Rust to C” by itself, but the fact that it widens the pool of people who can help debug portability problems.
There are relatively few people who understand Rust’s compiler internals, LLVM backends, and obscure target support deeply. But there are many engineers who understand C compilers, ABIs, linkers, makefiles, cross-compilation, old operating systems, and weird platform-specific compiler behavior.
If Rust can be lowered into target-specific C, then some problems stop being exclusively “Rust compiler problems” and also become C toolchain problems. That means more people can inspect the generated C, build failures, linker errors, ABI mismatches, and compiler-specific behavior.
C is obviously not a magic portability layer. ABI details, integer widths, alignment, TLS, aliasing, and undefined behavior still matter. But as an ecosystem boundary, C gives many more engineers a way to participate in debugging and porting work.
I think that social/maintenance aspect may be more important than the language translation itself.
by dangoodmanUT
1 subcomments
- i believe the author is confused
this is the wrong direction
(jk i read the readme)