Rust implementation for Writing a C Compiler book
  • Rust 95.7%
  • Just 4.3%
Find a file
Shagun Agrawal 9f06bdab0c Implement binary operators, finish chapter 3
```shell
arch -x86_64 /bin/zsh -cu './tests/writing-a-c-compiler-tests/test_compiler ./bin/rcc --chapter 3'

Ran 66 tests in 18.213s

OK
```
2026-02-08 18:35:08 +05:30
cli Complete chapter 2 2026-02-05 23:36:04 +05:30
compiler Implement binary operators, finish chapter 3 2026-02-08 18:35:08 +05:30
.gitignore Add initial compiler driver setup 2026-01-16 00:31:55 +05:30
Cargo.lock Add logos lexer and complete lexer stage 2026-01-22 22:57:03 +05:30
Cargo.toml Add logos lexer and complete lexer stage 2026-01-22 22:57:03 +05:30
example.env Fix example.env file 2026-01-22 23:05:38 +05:30
justfile Add logos lexer and complete lexer stage 2026-01-22 22:57:03 +05:30
README.md Update readme 2026-01-22 23:02:20 +05:30

rcc

Implementing Writing a C Compiler by Nora Sandler in Rust.

Currently in progress.

Requirements

Similar to the book, only Linux and Mac are supported. For Windows, run in WSL.

  • python3 >=3.8
  • gcc, gdb for Linux
  • clang for Mac
  • rustc
  • just for task runner

The commands are written to be OS agnostic, but I have only tested them on MacOS.

Commands

Run just to see list of all available commands. Requires the setup to be completed

just 

Available recipes:
    # Builds rcc binary.
    # Usage: just build <debug|release> (defaults to debug)
    build mode="debug"
    check-test-compiler-setup # Verify all requirements for test_comiler are met
    clean                     # Clean build artifacts
    default
    # Run's rcc binary.
    # Usage: just run <debug|info|other log levels>)
    run level +args
    show-prefix               # Show's the command prefix for all shell commands
    test-suite +args          # Run's tests from the book's test suite. Pass in chapter and stage flags.

Setup

Create a .env file and set the below values. These values are used in justfile to setup build, test artifacts. Check out example.env.

TEST_COMPILER_PATH=
PATH_TO_BINARY=
  • TEST_COMPILER_PATH

Clone Writing a C Compiler Test Suite locally. Specify the path to this repository add the suffix for test_compiler.

Example. All paths are relative.

mkdir tests && cd tests
git clone --depth=1 https://github.com/nlsandler/writing-a-c-compiler-tests.git
TEST_COMPILER_PATH='./tests/writing-a-c-compiler-tests/test_compiler'
  • PATH_TO_BINARY

Path to the directory where the binary will be created.

Name of the binary is rcc.

PATH_TO_BINARY='./bin'
just build 

./bin/rcc # binary called `rcc` created

Instructions

just build

just run debug ./tests/main.c

Run the book's test suite.

just test-suite --chapter 1 --stage lex
# expands to arch -x86_64 /bin/zsh -cu './tests/writing-a-c-compiler-tests/test_compiler ./bin/rcc --chapter 1 --stage lex'