Compiling Rust To Readable C With Eurydice
AIThis post was created with the assistance of artificial intelligence (AI).

TL;DR

Buying for a business?Offer from Amazon

Get business pricing on networking and server gear

  • Business-only prices and quantity discounts
  • Tax-exempt purchasing
  • Multiple users, one account, clear invoices
As an affiliate, we earn on qualifying purchases.

Eurydice is a project that translates Rust code into C while aiming to preserve the source program’s structure and behavior. The approach could help projects use C-based verification and compliance tools, but Rust features such as generics and dynamically sized types create translation challenges.

Eurydice, a project in the Aeneas family of tools, translates Rust programs into C while attempting to preserve the structure and evaluation order of the original code. The approach could help teams working on high-assurance software use established C-based verification and compliance tools, and could support systems that lack a working Rust compiler.

Eurydice follows a compiler pipeline: it converts Rust into an intermediate representation, applies a series of transformations, then emits C. Its goal differs from producing optimized machine code: it seeks to retain recognizable source-level structure while removing or translating features that C does not have. A report by LWN.net says Eurydice has been used to translate some post-quantum cryptography routines from Rust to C.

A simple example in the report translates Rust functions for calculating the greatest common divisor and least common multiple. The generated C keeps the conditional and recursive call recognizable, and introduces temporary variables where needed to preserve the source’s evaluation order. The report contrasts this with ordinary rustc output, which is optimized for machine code and can be less readable as source.

The project was started in 2023 and is part of Aeneas, which develops tools related to formal verification of Rust. Aeneas projects are maintained by people employed by France’s Inria research institute and Microsoft, and the report says they accept outside contributions. Eurydice includes code licensed under both MIT and Apache-2.0.

At a glance
reportWhen: Eurydice began in 2023; the report desc…
The developmentA report on Eurydice describes how the Aeneas project translates Rust programs into structurally similar C code for uses including high-assurance software.

Rust Code for C-Based Assurance

Many established verification and compliance workflows are built around C programs. Translating Rust into C may let developers retain Rust as a source language while making the resulting program available to tools and environments that do not support Rust directly. This is particularly relevant in high-assurance work, where teams need to inspect, analyze, or validate code using existing processes.

The translation is not simply a change of syntax. The output needs to preserve relevant Rust behavior if it is to serve as a trustworthy basis for further analysis. Eurydice’s emphasis on structure may make the generated code easier for people to review than compiler output designed chiefly for machine execution. That is a potential benefit, not a guarantee that every program or verification workflow will be supported without additional work.

Products Worth Considering

Amazon Kindle Scribe (3rd Generation), 64GB, 11-inch Display, Graphite, with Premium Pen

Amazon Kindle Scribe (3rd Generation), 64GB, 11-inch Display, Graphite, with Premium Pen

Amazon Kindle Paperwhite Signature Edition (12th Generation, 2024), 32 GB, Metallic Raspberry

Amazon Kindle Paperwhite Signature Edition (12th Generation, 2024), 32 GB, Metallic Raspberry

As an affiliate, we earn on qualifying purchases.

How Eurydice Fits Rust Tooling

Rust compilation has become less tied to a single implementation. The LWN report notes progress in projects including mrustc, GCC’s Rust support, rust_codegen_gcc and Cranelift. Eurydice has a different aim: rather than provide another route to machine code, it converts Rust into a lower-level language that already has a broad tool ecosystem.

Eurydice is based on KaRaMeL, a project that translates the F* programming language into C. F* is used in developing cryptographic libraries, and the approach of compiling a higher-level language to structurally similar C is therefore not new. Eurydice applies a related model to Rust, but must account for Rust-specific semantics and type features.

Some Rust constructs require substantial adaptation. Iterators, for example, may become while loops that use Eurydice support code to track iterator state. Rust generics also have no direct C equivalent, so generic code must be monomorphized: the translation can produce separate implementations for different types, where an idiomatic C implementation might instead use macros or void pointers.

“Eurydice has a more ambitious goal: converting Rust code to clean C code.”

— LWN.net report

Limits of Rust-to-C Translation

The report does not establish that Eurydice can translate every Rust program or that its output is suitable for every C verification tool. Generics, iterators and dynamically sized types require special handling, and the material does not provide a complete account of supported language features, performance, or production deployments.

Dynamically sized types illustrate a deeper issue. Rust may know a field’s exact size in one use of a generic type even when the type is not known to have a fixed size everywhere. Eurydice emits separate C representations for the flexible-size and known-size cases to preserve the relevant bounds-checking behavior. Converting between those representations is a runtime no-op, but the report says it technically violates C’s strict-aliasing rule; Protzenko recommends disabling strict aliasing for generated code. The broader implications for particular toolchains and assurance processes are not detailed in the source.

Further Tooling and Adoption

The report does not announce a release date, roadmap milestone or adoption target. Near-term development will depend on how the Aeneas maintainers and outside contributors address Rust language features, improve the generated C, and document how projects should build and analyze it. Teams considering Eurydice will need to check whether their code is supported and follow the project’s guidance on compiler settings.

The next practical measure of progress is whether more projects can use the translation in their own verification or deployment workflows. The reported use with some post-quantum cryptography routines shows an application, but it does not by itself establish broad adoption or independent assurance results. Further details about supported Rust constructs, testing and integration would help clarify how widely the approach can be applied.

Key Questions

What does Eurydice do?

Eurydice translates Rust into C through an intermediate representation and a sequence of compiler passes, aiming to retain much of the original program’s structure.

Why translate Rust code into C?

Some high-assurance projects rely on verification and compliance tools built for C. C output can also be useful in environments that have a C compiler but no working Rust compiler.

Does Eurydice support every Rust feature?

The report does not claim universal support. Features including generics, iterators and dynamically sized types require transformations or additional support code.

Is the generated C guaranteed to be safe or formally verified?

No such guarantee is established in the report. Eurydice is part of a project focused on tools related to formal verification, but translating code to C does not by itself prove that the output is correct or verified.

What build setting does Eurydice’s contributor recommend?

Jonathan Protzenko recommends compiling generated code with -fno-strict-aliasing, because one representation conversion for dynamically sized types technically conflicts with C’s strict-aliasing rule.

Source: hn

You May Also Like

The Fastest Way to Document a Cloud Environment Without Starting Over

Automate your cloud documentation process to quickly capture resources and identify gaps—discover how to streamline your environment today.

Robert Wille (Munich Quantum Software Company): Quantum Software Needs Design Automation, Not Just Algorithms

Computer scientist Robert Wille says practical quantum computing will need automated software design, compatible tools and links to HPC systems.

CodePen 2.0

CodePen has announced Version 2.0, introducing new features and a redesigned interface aimed at enhancing user experience and collaboration.

Monitor Size Myths That Hurt Productivity More Than They Help

Many believe bigger monitors boost productivity, but misconceptions about size may actually hinder your workflow—discover the truth to optimize your setup.