Skip to content

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:

Terminal window
xcode-select --install

2. Homebrew

If you don’t have Homebrew installed:

Terminal window
/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:

Terminal window
brew install go

Verify:

Terminal window
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:

Terminal window
brew install zig

Verify:

Terminal window
zig version
# Should show: 0.14.x or later

5. LLVM (18)

The Zeus compiler uses LLVM via Go bindings. Install LLVM 18:

Terminal window
brew install llvm@18

Then add the following to your shell configuration (~/.zshrc or ~/.bashrc):

Terminal window
# LLVM configuration for Zeus
export 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:

Terminal window
source ~/.zshrc # or ~/.bashrc

Verify:

Terminal window
llvm-config --version
# Should show: 18.x.x

Building the Compiler

  1. Clone the repository

    Terminal window
    git clone https://github.com/ameerthehacker/zeus.git
    cd zeus
  2. Install Go dependencies

    Terminal window
    go mod download
  3. Build the runtime

    The runtime provides garbage collection, arrays, and other built-in operations:

    Terminal window
    make build-runtime
  4. Build the compiler

    Terminal window
    make build

    This creates a zeus binary in the project root.

  5. Verify the build

    Terminal window
    ./zeus --help
  6. (Optional) Add to PATH

    To use zeus from anywhere:

    Terminal window
    # Add to ~/.zshrc or ~/.bashrc
    export PATH="$HOME/path/to/zeus:$PATH"

Development Workflow

Running Tests

Run the full test suite:

Terminal window
make test

Run specific test categories:

Terminal window
make test-go # Go unit tests
make test-runtime # Runtime tests
make test-e2e # End-to-end tests

Compiling & Running Zeus Programs

Use the playground directory for quick experiments:

Terminal window
# Create a test file
echo 'function main(): i32 { return 42; }' > playground/test.zs
# Compile and run
make run file=test
# Check exit code
echo $? # Should print 42

Debug Mode

Enable verbose output to see compiler internals:

Terminal window
make run file=test debug=true

This will:

  • Print the Zeus IR (intermediate representation)
  • Save LLVM IR files to playground/debug/out/
  • Show GC debug information

Build Flags

FlagDescription
debug=trueEnable debug output
nogc=trueDisable garbage collection
release=trueUse optimized runtime

Combine flags as needed:

Terminal window
make run file=test debug=true nogc=true

Project 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

Terminal window
make build-runtime

Runtime Debug Mode

For GC debugging:

Terminal window
make build-runtime-debug

Key Runtime Files

FilePurpose
runtime/gc.zigCore garbage collector
runtime/gc_runtime.zigGC interface for compiled code
runtime/array_runtime.zigDynamic array implementation
runtime/stackmap.zigStack map parsing for precise GC

Working on the VS Code Extension

The Zeus VS Code extension provides syntax highlighting and LSP support.

Setup

Terminal window
cd zeus-vscode
npm install
npm run compile

Testing

Press F5 in VS Code to launch the Extension Development Host.

Packaging

Terminal window
npm run package

Common Issues

LLVM Not Found / CGO Errors

If you see errors like cannot find -lLLVM or llvm-config: command not found:

  1. Ensure LLVM 18 is installed:

    Terminal window
    brew install llvm@18
  2. 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)
  3. Check that llvm-config is in PATH:

    Terminal window
    which llvm-config
    llvm-config --version
  4. Ensure CGO is enabled:

    Terminal window
    go env CGO_ENABLED
    # Should show: 1
    # If not, enable it:
    go env -w CGO_ENABLED=1
  5. Reload your shell configuration:

    Terminal window
    source ~/.zshrc # or ~/.bashrc

Runtime Build Fails

Ensure Zig is properly installed:

Terminal window
zig version # Should be 0.14+

Tests Failing

Make sure the runtime is built first:

Terminal window
make build-runtime
make test

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run the test suite: make test
  5. Submit a pull request

See our GitHub repository for contribution guidelines.


Makefile Reference

CommandDescription
make buildBuild the Zeus compiler
make build-runtimeBuild the runtime
make build-runtime-debugBuild runtime with debug symbols
make run file=<name>Compile and run a playground file
make compile file=<name>Compile without running
make testRun all tests
make test-goRun Go tests only
make test-e2eRun end-to-end tests
make cleanRemove build artifacts
make lspStart the Language Server

Next Steps