This document explains how to build the Sindarin compiler from source on Linux, macOS, and Windows.
All platforms require:
- CMake 3.16 or later
- Ninja build system (recommended) or Make
- Python 3.6 or later (for test runner)
- A C99-compatible compiler (GCC or Clang)
The simplest way to build is using the Makefile wrapper:
# Install dependencies (platform-specific, see below)
make setup-deps
# Build
make build
# Test
make test
# Run a sample program
make runOr using CMake directly:
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build buildCMake presets provide pre-configured build settings. List available presets:
cmake --list-presetsBuild with a preset:
# Linux with GCC
cmake --preset linux-gcc-release
cmake --build --preset linux-gcc-release
# macOS with Clang
cmake --preset macos-clang-release
cmake --build --preset macos-clang-release
# Windows with Clang
cmake --preset windows-clang-release
cmake --build --preset windows-clang-releaseInstall dependencies (Ubuntu/Debian):
sudo apt-get update
sudo apt-get install -y build-essential cmake ninja-build zlib1g-dev python3Install dependencies (Fedora/RHEL):
sudo dnf install -y gcc cmake ninja-build zlib-devel python3Install dependencies (Arch Linux):
sudo pacman -S base-devel cmake ninja zlib pythonOr use the setup script:
python3 scripts/setup_deps.pyBuild:
make build
# or
cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_BUILD_TYPE=Release
cmake --build buildVerify:
bin/sn --version
bin/tests # Run unit testsInstall dependencies (via Homebrew):
brew install cmake ninja coreutils zlib python3macOS includes Clang via Xcode Command Line Tools. Install if needed:
xcode-select --installBuild:
make build
# or
cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Release
cmake --build buildVerify:
bin/sn --version
bin/testsOption 1: Automated setup
python scripts/setup_deps.pyThis installs CMake, Ninja, LLVM-MinGW, and vcpkg with zlib.
Option 2: Manual setup (via winget)
winget install Kitware.CMake
winget install Ninja-build.Ninja
winget install mstorsjo.llvm-mingwBuild:
cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Release
cmake --build buildVerify:
bin\sn.exe --version
bin\tests.exeAfter a successful build:
| Path | Description |
|---|---|
bin/sn (or bin/sn.exe) |
The Sindarin compiler |
bin/tests (or bin/tests.exe) |
Unit test runner |
bin/lib/gcc/*.o |
Runtime objects (Linux/macOS) |
bin/lib/clang/*.o |
Runtime objects (Windows) |
bin/include/ |
Runtime headers |
bin/sn.cfg |
Compiler configuration file |
| Option | Default | Description |
|---|---|---|
CMAKE_BUILD_TYPE |
Release |
Build type: Release or Debug |
CMAKE_C_COMPILER |
System default | C compiler: gcc, clang, etc. |
SN_DEBUG |
OFF |
Enable debug symbols and reduced optimization |
SN_ASAN |
OFF |
Enable AddressSanitizer (GCC/Clang only) |
SN_BUNDLE_ZLIB |
OFF |
Bundle zlib with packages for self-contained distribution |
Debug build with AddressSanitizer:
cmake -S . -B build -G Ninja \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_BUILD_TYPE=Debug \
-DSN_DEBUG=ON \
-DSN_ASAN=ON
cmake --build buildThe unified Python test runner works on all platforms:
# Run all tests
python3 scripts/run_tests.py all
# Unit tests only
python3 scripts/run_tests.py unit
# Integration tests
python3 scripts/run_tests.py integration
python3 scripts/run_tests.py integration-errors
# Exploratory tests
python3 scripts/run_tests.py explore
python3 scripts/run_tests.py explore-errors
# SDK tests
python3 scripts/run_tests.py sdkOr use Make targets:
make test # All tests
make test-unit # Unit tests only
make test-integration # Integration tests
make test-explore # Exploratory tests
make test-sdk # SDK testsTest runner options:
python3 scripts/run_tests.py --help
# Exclude specific tests
python3 scripts/run_tests.py integration --exclude test_foo,test_bar
# Verbose output
python3 scripts/run_tests.py all --verboseBuild distributable packages using CPack:
make package
# or
cd build && cpackThis creates platform-specific packages:
- Linux:
.tar.gz,.deb,.rpm - Windows:
.zip - macOS:
.tar.gz
Once built, compile .sn files:
# Compile to executable
bin/sn myprogram.sn -o myprogram
./myprogram
# Emit C code only (don't compile)
bin/sn myprogram.sn --emit-c -o myprogram.c
# Debug build (with symbols, enables ASAN on Linux)
bin/sn myprogram.sn -g -o myprogramThe Sindarin compiler uses a C backend. It reads configuration from sn.cfg and can be overridden via environment variables.
The compiler searches for sn.cfg in these locations (first found wins):
$SINDARIN_CONFIGenvironment variable (if set)- Next to the compiler executable (portable/development mode)
- Platform-specific system paths:
- Linux:
/etc/sindarin/sn.cfg,/usr/local/etc/sindarin/sn.cfg - macOS:
/usr/local/etc/sindarin/sn.cfg,/opt/homebrew/etc/sindarin/sn.cfg - Windows:
%LOCALAPPDATA%\Sindarin\sn.cfg,%ProgramFiles%\Sindarin\sn.cfg
- Linux:
- Built-in defaults
The compiler searches for runtime objects (.o files) in:
$SINDARIN_LIBenvironment variable (if set)- Next to the compiler executable:
<exe_dir>/lib/<backend>/ - FHS-relative:
<exe_dir>/../lib/sindarin/<backend>/ - Platform-specific system paths:
- Linux:
/usr/lib/sindarin/<backend>,/usr/local/lib/sindarin/<backend> - macOS:
/usr/local/lib/sindarin/<backend>,/opt/homebrew/lib/sindarin/<backend> - Windows:
%ProgramFiles%\Sindarin\lib\<backend>
- Linux:
| Variable | Default | Description |
|---|---|---|
SN_CC |
gcc (Linux), clang (macOS/Windows) |
C compiler |
SN_STD |
c99 |
C standard |
SN_DEBUG_CFLAGS |
Platform-specific | Debug mode flags |
SN_RELEASE_CFLAGS |
-O3 -flto |
Release mode flags |
SN_CFLAGS |
(empty) | Additional compiler flags |
SN_LDFLAGS |
(empty) | Additional linker flags |
SN_LDLIBS |
(empty) | Additional libraries |
SINDARIN_CONFIG |
(none) | Override config file path |
SINDARIN_LIB |
(none) | Override runtime library directory |
Example: Using Clang on Linux:
SN_CC=clang bin/sn myprogram.sn -o myprogramExample: Linking additional libraries:
SN_LDLIBS="-lssl -lcrypto" bin/sn myprogram.sn -o myprogramExample: Custom runtime location:
SINDARIN_LIB=/opt/sindarin/lib/gcc bin/sn myprogram.sn -o myprogramThe compiler can't find pre-built runtime objects. This can happen if:
-
Development mode: Ensure CMake completed successfully and check that
bin/lib/gcc/(Linux/macOS) orbin/lib/clang/(Windows) contains.ofiles. -
Installed package: The compiler searches system paths like
/usr/lib/sindarin/gcc/. Ensure the package was installed correctly. -
Custom location: Set
SINDARIN_LIBto your runtime directory:SINDARIN_LIB=/path/to/lib bin/sn myprogram.sn
Set SN_CC to your compiler path:
SN_CC=/usr/bin/gcc bin/sn myprogram.sn -o myprogramIf using LLVM-MinGW, add to PATH:
$env:PATH = "C:\llvm-mingw\llvm-mingw-20241217-ucrt-x86_64\bin;$env:PATH"ASAN has known issues with signal handling on macOS. Some threading tests are excluded on macOS. To explicitly disable ASAN:
SN_DEBUG_CFLAGS="-g" bin/sn myprogram.sn -g -o myprogramThe build system falls back to Unix Makefiles if Ninja isn't installed. For faster builds, install Ninja:
# Linux (Ubuntu/Debian)
sudo apt-get install ninja-build
# macOS
brew install ninja
# Windows
winget install Ninja-build.NinjaThe project uses GitHub Actions for continuous integration. See .github/workflows/ci.yml for the authoritative build configuration covering Linux, macOS, and Windows.