BRAIDGROUP
RESEARCH & DEV
26. Documentation

Build System

CMake Build

The primary build system for Braid is CMake (minimum version 3.15). The project compiles C11 and C++17 sources with AVX2, FMA, and native architecture optimizations enabled by default.

git clone https://github.com/braidlang/braid.git
cd braid/braid-lang
cmake -B build
cmake --build build
# All binaries are placed under build/

CMake Configuration Flags

Several flags control which backends and features are enabled at build time:

FlagDefaultDescription
BRAID_ENABLE_CPU_ONLYONOptimize for CPU-only training (enables ternary, streaming, memory pool tests)
BRAID_ENABLE_CUDAOFFEnable CUDA GPU backend via gpu_cuda.cu
BRAID_ENABLE_VULKANOFFEnable Vulkan GPU backend via gpu_vulkan.c

Build Targets

The CMakeLists.txt defines multiple executables and libraries:

braidc

The main compiler executable. Links against braid_compiler, braid_vm, braid_storage, braid_runtime, and braid_std object libraries.

cmake --build build --target braidc
# Output: build/tools/braidc/braidc (or build/tools/braidc/Debug/braidc.exe on Windows)

turbo-vm

The standalone BraidVM executable with REPL and direct bytecode execution. Links all runtime components plus JIT when LLVM is available.

cmake --build build --target turbo-vm
# Output: build/src/vm/turbo-vm

braid-run

Lightweight bytecode runner for production deployments. Minimal dependencies; suitable for embedding.

cmake --build build --target braid-run
# Output: build/tools/braid-run/braid-run

braid-model

Standalone ML model inference tool. Does not link the VM — only depends on threading and math libraries.

cmake --build build --target braid-model
# Output: build/tools/braid-model/braid-model

braid-serve

HTTP server for serving Braid applications over REST. Includes an embedded HTTP server and JSON utilities.

cmake --build build --target braid-serve

braid-bench

Benchmarking tool for measuring VM and runtime performance.

cmake --build build --target braid-bench

Test Targets

CPU-only test targets are built when BRAID_ENABLE_CPU_ONLY is ON. Each test is a standalone executable.

cmake --build build --target test-ternary
cmake --build build --target test-hierarchical-head
cmake --build build --target test-local-learning
cmake --build build --target test-cpu-train-driver
cmake --build build --target test-cpu-convergence
cmake --build build --target test-diameter-step
cmake --build build --target test-cpu-streaming-edge
cmake --build build --target test-tensor-transpose
cmake --build build --target test-mempool-c
cmake --build build --target test-llm-api
cmake --build build --target bench-cpu-training

LLVM JIT Support

LLVM is auto-detected via find_package(LLVM). When found, the build enables the JIT module (jit_llvm.cpp, jit_codegen.cpp, jit_graph.cpp) and defines BRAID_LLVM_JIT. The JIT library is linked into turbo-vm, braidc, braid-run, and braid-bench.

cmake -B build -DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm
cmake --build build
# JIT objects included automatically

GPU Backend Builds

## CUDA backend
cmake -B build -DBRAID_ENABLE_CUDA=ON -DBRAID_ENABLE_CPU_ONLY=OFF
cmake --build build

## Vulkan backend
cmake -B build -DBRAID_ENABLE_VULKAN=ON -DBRAID_ENABLE_CPU_ONLY=OFF
cmake --build build

## Both GPU backends
cmake -B build -DBRAID_ENABLE_CUDA=ON -DBRAID_ENABLE_VULKAN=ON
cmake --build build

Object Libraries

The build system uses CMake object libraries to share compiled objects across targets without duplicate compilation:

  • braid_vm — VM core (vm.c, string.c, jit.c, bytecode.c, globals.c)
  • braid_storage — Storage module (all .c in src/storage/)
  • braid_runtime — Runtime module (ML ops, CPU streaming, memory pools)
  • braid_std — Standard library (lib/std/*.c, excludes net.c and regex.c)
  • braid_compiler — Compiler module (lexer, parser, typecheck, codegen, opt, supercompiler)
  • braid_jit — JIT C++ objects (conditional on LLVM)

Makefile Alternative

For environments without CMake, a Makefile provides the same build targets. The Makefile uses explicit source file lists matching the CMake object library splits.

make braidc      # build the compiler
make turbo-vm    # build the VM
make test        # run all tests
make clean       # clean build artifacts