ClementTsang
rustcc
Rust

A (toy) C compiler written in Rust with no dependencies.

Last updated Jun 20, 2026
89
Stars
8
Forks
3
Issues
0
Stars/day
Attention Score
13
Language breakdown
Rust 98.2%
Shell 1.8%
โ–ธ Files click to expand
README

rustcc - a Rust C compiler

A basic C compiler written in Rust that compiles C code into x86 assembly, following GAS/AT&T syntax, with no external Rust dependencies. Inspired by this post by Nora Sandler.

Note this was done for learning purposes as my intro to Rust, and isn't intended to be used too seriously.

Features

Currently, rustcc supports the following features:
  • Unary operators (logical negation, bitwise complements, negation)
  • Binary operators (basic arithmetic, bitwise operations, comparisons)
  • Local variables (assignment, declaration, variable calling, postfix and prefix incrementing)
  • If-else branching
  • Ternary operator
  • While loops, do-while loops, for loops, break, continue
  • Function calling and creation
As of now, rustcc only supports variables of type int.

Installation

To install, ensure beforehand that you have Rust and Cargo installed. After that, clone the repository. Then, run `cargo build --release.

Usage

To use the compiler, run the
rustcc script as follows: <pre><code class="lang-">./rustcc /path/to/source.c</code></pre> Upon running, the compiled executable file will be in the same directory and name as the input source file. The created assembly source.s file will be deleted upon running the script.

Alternatively, you can directly run ./target/release/rustcc /path/to/source.c (or target/release/rustcc.exe /path/to/source.c` on Windows) to retain the assembly file.

Disclaimer

rustcc is a project done purely out of personal interest. The compiled x86 code is most likely not optimized and the possibility of something not working or being supported is quite probable. I am not responsible for anything going wrong with the use of this.
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท ClementTsang/rustcc ยท Updated daily from GitHub