News for hackers. Stuff that matters.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by jokoon on Saturday April 12, 2025 @05:12AM (#43662733)
At first I read it as C to rust compiler.

What is the point of compiling rust to C?

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by drdeca on Saturday April 12, 2025 @05:16AM (#43662757)
I think there are probably C compilers for more platforms than there are rust compilers. So, if you want to compile your rust project on some obscure platform that doesn’t have a rust compiler for it yet, you could compile to C and then compile the resulting C code for that platform?

Just a guess.

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by Someone on Saturday April 12, 2025 @08:01AM (#43663662)
This project doesn’t have that as a goal. In fact, it doesn’t even have “Rust to C compiler” as a goal. https://github.com/FractalFir/rustc_codegen_clr:

“ The project aims to provide a way to easily use Rust libraries in .NET. It comes with a Rust/.NET interop layer, which allows you to easily interact with .NET code from Rust

[…]

While .NET is the main focus of my work, this project can also be used to compile Rust to C, by setting the C_MODE enviroment flag to 1.

This may seem like a strange and unrelated feature, but the project was written in such a way that this is not only possible, but relatively easy.”

It also doesn’t mention for which version of C it produces code. That may or may not hinder attempts to use this to run rust on obscure platforms.

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by arka2147483647 on Saturday April 12, 2025 @08:47AM (#43663899)
The article mentions ANSI-C at places. So seems like the old c standard is targeted.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by FractalFir on Saturday April 12, 2025 @01:15PM (#43666248)
The README is slightly out of date, sorry. Supporting old platforms is one of the goals.

Truth be told, the support for C was at first added as a proff-of-concept that a Rust to C compiler is possible. But it worked surprisingly well, so I just decided to roll with it, and see where it takes me.

My policy in regards to C version is: I want to be as close to ANSI C as possible. So, I avoid modern C features as much as I can. I don't know if full compatibility is achievable, but I certainly hope so. Only time will tell.

Some simpler pieces of Rust work just fine with ANSI C compilers, but more complex code breaks(eg. due to unsupported intrinsics). If I will be able to solve that(+ some potential soundness issues) then I'll be able to use ANSI C.

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by tetha on Saturday April 12, 2025 @06:46AM (#43663245)
This is a fairly common technique in compiler construction and programming language research: Don't try to emit some machine code, instead emit C or an IR for clang or GCC. And suddenly your little research language (not that rust is one) is executable on many, many platforms, can rely on optimizations the compilers can do, has potential access to debug handling, ..
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by kvemkon on Saturday April 12, 2025 @12:38PM (#43665922)
Vala [1] is, perhaps, the most prominent example of practically used programming language with such compiler.

[1] https://en.wikipedia.org/wiki/Vala_(programming_language)

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by widforss on Saturday April 12, 2025 @06:50AM (#43663268)
Regarding the other way, I guess a lot of (practically) legal C wouldn't compile to Rust at all due to the language's restrictions and C's laxness, while I think all Rust could be translated to C.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by p0w3n3d on Saturday April 12, 2025 @05:51AM (#43662948)
Exactly. Btw rust toolchain is quite complicated while a code that was tanspiled to C might be as well compiled to e.g. 6052
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by vblanco on Saturday April 12, 2025 @08:05AM (#43663686)
Game consoles generally only offer clang as a possibility for compiler. If you can compile rust to C, then you can finally use rust for videogames that need to run everywhere.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by dcow on Saturday April 12, 2025 @09:27AM (#43664179)
I don’t think I’ve ever heard those two terms “video game” and “run everywhere” in the same sentence. Bravo.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by koakuma-chan on Saturday April 12, 2025 @09:43AM (#43664306)
Is Steam Deck a monopoly yet? I feel like if your game compiles to Linux, you can target pretty much every market out there.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by arghwhat on Saturday April 12, 2025 @05:18AM (#43662771)
Using C compiler infrastructure, taking Rust where rustc/llvm does not go. Proprietary platforms with proprietary compilers for example.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by teo_zero on Saturday April 12, 2025 @05:18AM (#43662768)
> What is the point of compiling rust to C?

To address platforms that don't support Rust. TFA mentions NonStop, whatever it is.

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by vbitz on Saturday April 12, 2025 @05:35AM (#43662865)
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by steveklabnik on Saturday April 12, 2025 @09:14AM (#43664092)
Not only does NonStop not support Rust, but apparently they failed to port gcc to it, even. So compiling Rust straight to C itself is pretty much the only option there.
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by nickpsecurity on Saturday April 12, 2025 @09:16AM (#43664106)
They are amazing machines designed for fault tolerance (99.999% reliability). The Wikipedia article below has design details for how many generations were made. HP bought them.

https://en.m.wikipedia.org/wiki/Tandem_Computers

I think it would be useful in open-source, fault tolerance to copy one of their designs with SiFive's RISC-V cores. They could use a 20 year old approach to dodge patent issues. Despite its age, the design would probably be competitive, maybe better, than FOSS clusters on modern hardware in fault tolerance.

One might also combine the architecture with one of the strong-consistency DR'S, like FoundationDB or CochroachDB, with modifications to take advantage of its custom hardware. At the local site, the result would be easy scaling of a system whose nodes appeared to never fail. The administrator still has to do regular maintenance, though, as the system reports component failures which it works around.

Re:Rust to C compiler – 95.9% test pass rate, odd platforms by oulipo on Saturday April 12, 2025 @06:15AM (#43663057)
I guess it's to target platforms (like some microcontrollers) which don't yet have a native Rust compiler, but often do have a C compiler?
Re:Rust to C compiler – 95.9% test pass rate, odd platforms by jeroenhd on Saturday April 12, 2025 @10:12AM (#43664556)
To use rust in places where you can only use C. I imagine there are quite a few obscure microcontrollers that would benefit greatly from this pipeline.

Hell, you might finally be able to get Rust into the Linux kernel. Just don't tell them the code was originally written in Rust to calm their nerves.