A few years ago, the only way to compile Rust code was using the rustc compiler with LLVM as a backend. Since then, several projects, including Mutabah's Rust Compiler (mrustc), GCC's Rust support (gccrs), rust_codegen_gcc, and Cranelift have made enormous progress on diversifying Rust's compiler implementations. The most recent such project, Eurydice, has a more ambitious goal: converting Rust code to clean C code. This is especially useful in high-assurance software, where existing verification and compliance tools expect C. Until such tools can be updated to work with Rust, Eurydice could provide a smoother transition for these projects, as well as a stepping-stone for environments that have a C compiler but no working Rust compiler. Eurydice has been used to compile some post-quantum-cryptography routines from Rust to C, for example.
Compiling Rust to readable C with Eurydice
Key points
- It's part of the Aeneas project, which works to develop several different tools related to applying formal verification tools to Rust code.
- Of course, not all Rust programs can be faithfully represented in C. For example, for loops that use an iterator instead of a range need to be compiled to while loops that call into some of Eurydice's support code to manage the state of the iterator.
- More importantly, C has no concept of generics, so Rust code needs to be monomorphized during conversion.
Sentences selected automatically from the original article by Hacker News.
Story details
- Published
- By
- peter_d_sherman
- Format
- Article
- Original
- lwn.net ↗





