Installation
This guide covers building the Klar compiler from source.
Prerequisites
- Zig 0.15+ - The compiler is written in Zig
- LLVM 17+ - Required for native code generation
- Git - To clone the repository
Installing Zig
Download Zig from ziglang.org/download or use your package manager:
# macOS (Homebrew)
brew install zig
# Ubuntu/Debian
snap install zig --classic
# Windows (Chocolatey)
choco install zigVerify the installation:
zig version
# Should show 0.15.0 or laterInstalling LLVM
# macOS (Homebrew)
brew install llvm@17
# Ubuntu/Debian
apt install llvm-17 llvm-17-dev
# Windows (Chocolatey)
choco install llvm
# Windows (manual)
# Download from releases.llvm.org and install to C:\Program Files\LLVM
# Or set LLVM_PREFIX environment variable to your LLVM install pathBuilding Klar
Clone the repository and build:
git clone https://github.com/yourusername/klar.git
cd klar
./run-build.shThe build script compiles the Klar compiler to ./zig-out/bin/klar.
Windows Build Notes
On Windows, use WSL, Git Bash, or any Bash-compatible shell to run the build and test scripts. Alternatively, you can build directly with Zig:
zig buildThe build system auto-detects LLVM in these locations:
C:\Program Files\LLVMC:\ProgramData\chocolatey\lib\llvm- Custom path via the
LLVM_PREFIXenvironment variable
Known difference: When using klar run on Windows, args[0] shows the temp binary path rather than the source file path. Standalone binaries (klar build) are not affected.
Verifying the Installation
Check that the compiler is working:
./zig-out/bin/klar version
# Klar 0.4.0
./zig-out/bin/klar help
# Shows usage informationAdding to PATH
For convenience, add the Klar binary to your PATH:
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:/path/to/klar/zig-out/bin"Or create a symlink:
sudo ln -s /path/to/klar/zig-out/bin/klar /usr/local/bin/klarAfter adding to PATH:
klar version
# Klar 0.4.0Running Tests
To verify the build, run the test suite:
./run-tests.shThis runs unit tests, native compilation tests, and application tests.
Next Steps
- Hello World - Write your first Klar program
- CLI Reference - Learn the command-line interface