crustc: entirety of `rustc`, translated to C
A developer has translated the entire rustc compiler into 46 million lines of C, creating a functional Rust compiler (crustc) that can be built with GCC and Make. This monumental technical undertaking is a proof-of-concept for their cilly toolchain, which aims to bring Rust to obscure hardware and platforms by adapting to any C compiler. It represents a significant step towards broadening Rust's reach to environments traditionally considered inaccessible due to lack of modern toolchain support.
The Lowdown
This project, crustc, presents a remarkable achievement: a fully functional Rust compiler, specifically rustc 1.98.0-nightly, entirely translated into C code. Weighing in at 46 million lines, this C-based compiler can be built using standard tools like GCC and Make, showcasing the capabilities of its underlying cilly toolchain. The developer's primary motivation is to expand Rust's compatibility to older or more obscure hardware and operating systems that currently lack support for modern Rust toolchains like LLVM or GCC.
crustcis a direct C translation of a recentrustcnightly build, providing a functional Rust compiler in C. It supports compiling Rust's core libraries such ascore,alloc, andstd.- The project serves as a demonstration for
cilly, a new Rust library and compiler backend designed to translate Rust code into C for arbitrary targets. This is the 14th attempt by the author to achieve this goal over three years. - A key innovation of
cillyis its adaptability to various C compilers. It generates "witness" programs to probe a given compiler and platform for specific features, type layouts, sizes, alignments, and integer formats, ensuring compatibility with even highly specialized C environments. cillymakes minimal assumptions, striving to adhere to ANSI C standards and providing workarounds for modern C features like strict aliasing. However, the generated C code is compiler-specific and not directly portable between different architectures (e.g., Arm64 C code won't run on RISC-V).- The tool supports "network transparency," allowing
rustcto run on a powerful host machine whilecillycommunicates with a C compiler on a target machine (e.g., Plan 9 VM via TCP) to compile Rust code remotely. cillycan generate Makefiles from its intermediate representation, facilitating the build process for Rust projects using traditional C build systems.- While
cillyaims for ABI compatibility with standardrustcoutput, there are nuances, particularly on platforms like Arm64, whererustcuses ABIs not directly representable in C. - The
cillytoolchain is not yet publicly available, with the author citing ongoing development, employment, and academic commitments, along with some optimization-related bugs, as reasons.
This project significantly pushes the boundaries of Rust's portability, offering a path for the language to thrive in environments previously considered out of reach, potentially removing a long-standing barrier to Rust adoption in specialized embedded or legacy systems.