Prerequisites
MCC requires:- Rust 1.93.0 or later - MCC uses Rust 2024 edition features
- A C compiler - For preprocessing, assembling, and linking (typically
ccorclang) - Git - To clone the repository with submodules
MCC delegates preprocessing, assembly, and linking to your system’s C compiler. Make sure
cc or clang is available in your PATH.Install Rust
If you don’t have Rust installed, use rustup:Clone the Repository
Clone MCC with its submodules (includes the writing-a-c-compiler-tests suite):--recursive, initialize submodules:
Build from Source
MCC uses a Cargo workspace with multiple crates. Build the entire workspace:--locked flag ensures you use the exact dependency versions from Cargo.lock.
The debug binary will be at
target/debug/mcc and the release binary at target/release/mcc.Verify Installation
Check that the compiler builds successfully:Install the Binary (Optional)
To installmcc to your Cargo bin directory (~/.cargo/bin):
mcc from anywhere:
Project Structure
After building, you’ll have this structure:Development Setup
Install Additional Tools
For development, install these optional tools:IDE Integration
MCC works well with rust-analyzer:- VS Code: Install the rust-analyzer extension
- Vim/Neovim: Use coc-rust-analyzer or native LSP
- IntelliJ IDEA: Use the Rust plugin
Cargo.toml ensures rust-analyzer understands the multi-crate structure.
Running CI Checks Locally
Before committing, run the same checks as CI:The CI runs on both Ubuntu and macOS to ensure cross-platform compatibility. All tests must pass on both platforms.
Integration Tests
MCC includes comprehensive integration tests based on the writing-a-c-compiler-tests suite:- Test organization by chapters (1-20)
- Stage-specific testing (lex, parse, tacky, codegen)
- Extra credit features (bitwise, compound, increment, goto, switch)
Environment Variables
MCC respects these environment variables:| Variable | Description | Default |
|---|---|---|
CC | C compiler for preprocessing/linking | cc |
RUST_LOG | Logging level (mcc=debug, mcc-syntax=debug) | warn |
Troubleshooting
Build Fails with “could not find Cargo.toml”
Make sure you’re in the repository root, not a subdirectory.
Tests Fail with “cc: command not found”
Install a C compiler:Submodule Not Found
Initialize submodules:Rust Version Too Old
Update Rust:Next Steps
Quick Start
Compile your first C program with MCC