Rust to C compiler – 95.9% test pass rate, odd platforms
C↔Rust Translation and Safety
- Several commenters wish for C→Rust tools (e.g. DARPA’s TRACTOR, c2rust) mainly to:
- Remove C toolchains from builds.
- Enable LTO across translated C and Rust.
- Use translation as a first step toward idiomatic Rust rewrites.
- Others argue automatic C→Rust must be largely
unsafeand non‑idiomatic because C omits key semantic information Rust requires. - A WASM→Rust example shows a path to fully “safe” Rust that is still semantically sandboxed C.
Does a Rust→C Backend Preserve Rust’s Guarantees?
- One side: if the Rust frontend has already proven safety, the backend (LLVM, C, machine code) is just another compilation step; safety is a property of the Rust source, not the target.
- Concerns:
- C UB mismatches (e.g. signed overflow, alias rules) can break Rust’s semantics if not handled carefully.
- Transitivity of guarantees depends on “lossless” translation and bug‑free compilers, which is unproven.
- Author notes workarounds for “simple” UB, uses
-fsanitize=undefined, and C escape hatches likememcpyto avoid strict aliasing.
Why Compile Rust to C?
- Primary motivation: reach platforms where Rust/LLVM don’t exist but C compilers do (NonStop, obscure microcontrollers, some consoles, proprietary OSes).
- Also:
- Leverage mature C tooling (static/dynamic analyzers, Frama‑C, KLEE, CompCert).
- Possibly integrate into ecosystems that only accept C sources.
- Skeptics say this doesn’t improve FFI interop per se; you still call C functions either way.
Platform Coverage and Alternate Backends
- This project is a
rustcbackend using its own IR, initially for .NET; C support was added because the IR mapped cleanly. - Interest from people maintaining alpha, hppa, m68k, sh4, etc., frustrated that other backends (e.g. gcc‑based) haven’t fully bootstrapped Rust on these.
- Debate over Rust’s target tiers: explicit but conservative guarantees vs. C compilers’ de‑facto, less‑documented support on obscure architectures.
Language Ecosystem, Learning, and Stability
- Extended side‑discussion:
- Rust praised for free, unified documentation, safety model, and package manager; C/C++ defended for decades of teaching material and huge ecosystems.
- Arguments over dependency bloat vs. the cost and correctness of rolling your own libs.
- Rust criticized by some for complexity, build times, lack of a formal standard and multiple implementations, and weaker dynamic linking story; others counter that C/C++ also evolve and require similar care.
Project Status and Quality
- Earlier README numbers (~80% C test pass rate) were outdated; updated figures:
- ~96% for .NET core tests, ~95.6% for C core tests.
- Some view the post as an in‑progress status report rather than a finished product; others praise the ambition and rapid iteration, while a few question using tools that don’t yet pass 100% of tests.