crustc: rustc compiled to C to bring Rust to platforms LLVM forgot
FractalFir has published crustc, a fully functional Rust compiler emitted as C source that builds with nothing more than GCC and make. The generated compiler is a real rustc 1.98.0-nightly that can compile core, alloc, std, and arbitrary Rust code — it just happens to have been produced entirely as C by translating rustc through a new backend rather than through LLVM. The self-compiling stunt is a teaser for the author’s actual project, cilly, a Rust library and rustc backend plugin that transpiles Rust to C.
The interesting engineering is in how cilly stays portable. Instead of hardcoding assumptions about a target, it generates small ‘witness’ programs that probe what a given C compiler and platform actually support — type sizes and alignments, _Thread_local, two’s-complement integers, ASCII, strict-aliasing behavior — and adapts its output accordingly, falling back to documented, asserted assumptions only when unavoidable. It aims to stay within ANSI C. The tradeoff is that emitted C is compiler- and target-specific: code generated for ARM64 won’t run on RISC-V. cilly can also drive C compilers over TCP (potentially even UART), which sidesteps the bootstrap problem on exotic systems — the author used it to build Rust programs for x86 Plan 9 from an ARM64 Linux host, with a small on-target C server doing the compilation.
The motivation is reach: some hardware still has a C toolchain but no LLVM or GCC-Rust support, and ‘Rust doesn’t run there’ is a recurring argument against adopting it. Output is mostly ABI-compatible with normal rustc, breaking only where a platform’s ABI (like ARM64’s sret convention) can’t be expressed in C. This is the author’s 14th attempt at Rust-to-C over three years, following the earlier public rustc_codegen_clr. cilly itself isn’t released yet — the demo is rough, path-canonicalization quirks can crash it in its own build directory, and the author cites a new job, a thesis, and a blender-related hand injury as reasons the full toolchain is still pending.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.