Live data from Hacker News

Rust to C compiler – 95.9% test pass rate, odd platforms

fractalfir.github.io

81–90 of 264 posts

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#82
post #68

Why would I use a tool that doesn't pass all tests?

The post is an update on the status of an ongoing project.

> This is an update on the progress I have made on my Rust to C compiler.

> There still are about 65 tests that need fixing, but they all seem to have pretty similar causes. So, fixing them should not be too difficult.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#83
post #34

At first I read it as C to rust compiler. What is the point of compiling rust to C?

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

#84
post #54

Earlier quoted context omitted.

Borrow checker, and more generally any type checkers, are essentially terminating programs ran during compilation process, thus safety guarantees given by them are ensured before the code is transformed into some target language.

Thats assuming lossless transpilation though

If you mean 'no bugs in compiler' then yes. The safety of the target language doesn't matter: the output C is has an equivalent role to output machine code, those languages themselves are as unsafe as they can get, it's just that compilers output is a safer subsection of 'all programs which can be expressed in them'.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#85
post #76

Earlier quoted context omitted.

Not GP, but what is the point of touching Rust at all then?

To generate safer C?

Compiling Rust to C doesn’t simplify interoperability. Either way you’ll be calling C functions. I assume compiling Rust to C is useful if you’re targeting some esoteric platform that Rust compiler doesn’t support.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#86
post #80
post #36

Earlier quoted context omitted.

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.

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…

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

#87
post #42
post #33

Earlier quoted context omitted.

What does this gain you that you can't already do with `extern "c"` functions from rust?

’Extern c’ still uses Rust. You want to skip Rust and call C from other languages directly.

Rust doesn't have a runtime so it looks just like C in compiled form. c-bindgen even spits out a c header. I’m not sure what skipping C practically means even if you can argue there’s a philosophical skip happening.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#89
post #6

Very cool. C to Rust would be fantastic.

What benefit would you envision from this?

1. It means you don't need C code & a C compiler in your project any more, which simplifies infrastructure. E.g. cross compiling is easier without any C.

2. You can do LTO between Rust and the C->Rust code so in theory you could get a smaller & faster executable.

3. In most cases it is the first step to a gradual rewrite in idiomatic Rust.

Re: Rust to C compiler – 95.9% test pass rate, odd platforms

#90
post #42

Earlier quoted context omitted.

’Extern c’ still uses Rust. You want to skip Rust and call C from other languages directly.

Not GP, but what is the point of touching Rust at all then?

I'd like to write Rust, receive its safety benefits (esp borrow checker), compiler to equivalent C, and then use C's tooling on the result. Why use C's tooling?

In verification, C has piles of static analyzers, dynamic analyzers, test generators (eg KLEE), code generators (eg for parsing), a prover (Frama-C), and a certified compiler. If using a subset of these, C code can be made more secure than Rust code with more effort.

There's also many tools for debugging and maintenance made for C. I can also obfuscate by swapping out processor ISA's because C supports all of them. On the business end, they may be cheaper with lower watts.

I also have more skilled people I can hire or contract to do any of the above. One source estimated 7 million C/C++ developers worldwide. There's also a ton of books, online articles, and example code for anything we need. Rust is very strong in that last area for a new language but C/C++ will maintain an advantage, esp for low-level programming.

These are the reasons I'd use Rust if I wanted C or C++ for deployment. Likewise, I wish there was still a top-notch C++ to C compiler to get the same benefits I described with C's tooling.

Post reply on HN