mirror of
https://github.com/kaepr/rcc.git
synced 2026-03-15 10:27:16 +00:00
Rust implementation for Writing a C Compiler book
- Rust 95.7%
- Just 4.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 ``` |
||
|---|---|---|
| cli | ||
| compiler | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| example.env | ||
| justfile | ||
| README.md | ||
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.8gcc, gdbfor Linuxclangfor Macrustc- 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'