Is there an existing way to compile rust to C99?

Hi, I just discovered the rust langage and I really like the approach,
I'm learning about it, and so I have a question :

Is there an existing way to compile rust to standard C99 ?

Why ? Originally, because I'm using the dynamic compiler TCC for a project, it's small and generate fast (but not SIMD) assembly. And I don't want to use LLVM in this case because it's too big. Note that I'm using LLVM for other projects, this one need to be light.

Other reason is that it could give access to C compilers and (potentially) additional targets.

Any clue about that ?
Thanks a lot,

For example llvm-cbe (llvm c backend) : GitHub - draperlaboratory/llvm-cbe: resurrected LLVM "C Backend", with improvements
But it still depends on llvm code.

We do not currently support compiling to C.

For the record, some months ago I tried llvm-cbe with Rust and got it to sort of work, but ran into serious bugs in it (wrong C code being generated for perfectly reasonable IR). This doesn't help your main use case, of course.

Maybe there is a better way to use rust as a light JIT compiler.
My main problem here is about size, it's not so important in general.
TCC weights barely 64k which makes it good for small embedded (and standalone) JIT.
Thank you for your feedback,

1 Like

Unfortunately, rustc by itself (sans LLVM) is already something like 20MB, plus the Rust standard libraries it needs to run. It's also not very fast. Not the best solution for a lightweight JIT, for now...

1 Like