news.volyx.in

crustc: entirety of `rustc`, translated to C (github.com)

386 points by Philpax · 56 days ago · 92 comments on HN

Article summary

The article presents a project called crustc, which is a translation of the Rust compiler into C code, allowing it to be compiled with a C compiler like GCC. This project aims to support old or obscure hardware that does not have LLVM or GCC support but can run C code. The author has been working on this project for three years and has made 14 attempts at compiling Rust to C. The resulting C code is mostly ABI compatible with normal Rust-compiled code.

Main themes

  • Rust compiler
  • C code translation
  • Old hardware support
  • Bootstrapping
  • Compiler compatibility

What commenters say

  • The project's goal of supporting old hardware is more efficiently achieved by making the target an LLVM target, which would also enable support for other languages.
  • A Rust-to-C transpiler can be useful for compiling Rust programs for platforms not supported by LLVM, and this project has broader applications than existing solutions.
  • The project's approach can be used to test for backdoors in the official Rust compiler by comparing the output of the translated compiler with the original one.
  • The use of a C intermediate representation does not provide diversity in testing for backdoors, as the translation was done using a Rustc backend that could be compromised.
  • This project could make bootstrapping a Rust compiler easier, but the generated C code is not suitable as a source code for bootstrapping purposes.
  • Compiling Rust to C can be an underappreciated technique with more potential, as seen in projects that compile languages to WebAssembly and then translate to C.