Building from Source
This guide walks you through building the Zeus compiler from source. This is recommended if you want to:
- Contribute to Zeus development
- Customize the compiler
- Work on the latest unreleased features
- Debug compiler internals
Prerequisites
1. Xcode Command Line Tools (macOS)
Required for the C/C++ compiler (clang) and linker:
xcode-select --install2. Homebrew
If you don’t have Homebrew installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"3. Go (1.23 or later)
The Zeus compiler is written in Go:
brew install goVerify:
go version# Should show: go version go1.23.x darwin/arm64 (or amd64)4. Zig (0.14 or later)
The Zeus runtime is written in Zig:
brew install zigVerify:
zig version# Should show: 0.14.x or later5. LLVM (18)
The Zeus compiler uses LLVM via Go bindings. Install LLVM 18:
brew install llvm@18Then add the following to your shell configuration (~/.zshrc or ~/.bashrc):
# LLVM configuration for Zeusexport LLVM_PATH="$(brew --prefix llvm@18)"export PATH="$LLVM_PATH/bin:$PATH"export LDFLAGS="-L$LLVM_PATH/lib"export CPPFLAGS="-I$LLVM_PATH/include"export CGO_CFLAGS="-I$LLVM_PATH/include"export CGO_LDFLAGS="-L$LLVM_PATH/lib -Wl,-rpath,$LLVM_PATH/lib"Apply the changes:
source ~/.zshrc # or ~/.bashrcVerify:
llvm-config --version# Should show: 18.x.xBuilding the Compiler
-
Clone the repository
Terminal window git clone https://github.com/ameerthehacker/zeus.gitcd zeus -
Install Go dependencies
Terminal window go mod download -
Build the runtime
The runtime provides garbage collection, arrays, and other built-in operations:
Terminal window make build-runtime -
Build the compiler
Terminal window make buildThis creates a
zeusbinary in the project root. -
Verify the build
Terminal window ./zeus --help -
(Optional) Add to PATH
To use
zeusfrom anywhere:Terminal window # Add to ~/.zshrc or ~/.bashrcexport PATH="$HOME/path/to/zeus:$PATH"
Development Workflow
Running Tests
Run the full test suite:
make testRun specific test categories:
make test-go # Go unit testsmake test-runtime # Runtime testsmake test-e2e # End-to-end testsCompiling & Running Zeus Programs
Use the playground directory for quick experiments:
# Create a test fileecho 'function main(): i32 { return 42; }' > playground/test.zs
# Compile and runmake run file=test
# Check exit codeecho $? # Should print 42Debug Mode
Enable verbose output to see compiler internals:
make run file=test debug=trueThis will:
- Print the Zeus IR (intermediate representation)
- Save LLVM IR files to
playground/debug/out/ - Show GC debug information
Build Flags
| Flag | Description |
|---|---|
debug=true | Enable debug output |
nogc=true | Disable garbage collection |
release=true | Use optimized runtime |
Combine flags as needed:
make run file=test debug=true nogc=trueProject Structure
zeus/├── cmd/ # CLI entry points│ ├── main.go # Main entry point│ ├── build.go # Build command│ └── lsp.go # LSP server command├── internal/ # Compiler internals│ ├── lexer/ # Tokenizer│ ├── parser/ # Parser & AST construction│ ├── ast/ # Abstract Syntax Tree definitions│ ├── ir/ # Intermediate representation & type checking│ ├── codegen/ # LLVM IR generation│ ├── symbol_table/ # Symbol table management│ ├── module/ # Module system│ ├── lsp/ # Language Server Protocol│ └── zeus_compiler/ # Compiler orchestration├── runtime/ # Zig runtime│ ├── gc.zig # Garbage collector│ ├── gc_runtime.zig # GC runtime interface│ ├── array_runtime.zig # Array operations│ └── stackmap.zig # Stack map for GC├── playground/ # Test files directory├── examples/ # Example programs├── test/ # Test suites│ ├── e2e/ # End-to-end tests│ ├── lexer/ # Lexer tests│ └── parser/ # Parser tests├── lib/ # Standard library│ └── std/ # Standard modules├── zeus-vscode/ # VS Code extension└── docs/ # Documentation (this site)Working on the Runtime
The runtime is written in Zig and provides:
- Garbage collection
- Array operations
- Memory management
Building the Runtime
make build-runtimeRuntime Debug Mode
For GC debugging:
make build-runtime-debugKey Runtime Files
| File | Purpose |
|---|---|
runtime/gc.zig | Core garbage collector |
runtime/gc_runtime.zig | GC interface for compiled code |
runtime/array_runtime.zig | Dynamic array implementation |
runtime/stackmap.zig | Stack map parsing for precise GC |
Working on the VS Code Extension
The Zeus VS Code extension provides syntax highlighting and LSP support.
Setup
cd zeus-vscodenpm installnpm run compileTesting
Press F5 in VS Code to launch the Extension Development Host.
Packaging
npm run packageCommon Issues
LLVM Not Found / CGO Errors
If you see errors like cannot find -lLLVM or llvm-config: command not found:
-
Ensure LLVM 18 is installed:
Terminal window brew install llvm@18 -
Verify environment variables are set:
Terminal window echo $LLVM_PATH# Should show: /opt/homebrew/opt/llvm@18 (Apple Silicon)# Or: /usr/local/opt/llvm@18 (Intel) -
Check that llvm-config is in PATH:
Terminal window which llvm-configllvm-config --version -
Ensure CGO is enabled:
Terminal window go env CGO_ENABLED# Should show: 1# If not, enable it:go env -w CGO_ENABLED=1 -
Reload your shell configuration:
Terminal window source ~/.zshrc # or ~/.bashrc
Runtime Build Fails
Ensure Zig is properly installed:
zig version # Should be 0.14+Tests Failing
Make sure the runtime is built first:
make build-runtimemake testContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite:
make test - Submit a pull request
See our GitHub repository for contribution guidelines.
Makefile Reference
| Command | Description |
|---|---|
make build | Build the Zeus compiler |
make build-runtime | Build the runtime |
make build-runtime-debug | Build runtime with debug symbols |
make run file=<name> | Compile and run a playground file |
make compile file=<name> | Compile without running |
make test | Run all tests |
make test-go | Run Go tests only |
make test-e2e | Run end-to-end tests |
make clean | Remove build artifacts |
make lsp | Start the Language Server |