This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sleigh is a CMake-based build system for Ghidra's Sleigh/decompiler C++ libraries (by Trail of Bits). It wraps NSA's Ghidra source code — fetched via CMake FetchContent during configure — so the Sleigh disassembly and decompilation engines can be built as standalone C++ libraries for reuse outside Ghidra.
The actual Ghidra C++ source is not in this repo. It is cloned from GitHub automatically during CMake configuration.
# Standard build (fetches Ghidra source on first configure)
cmake -B build -S .
cmake --build build -j$(nproc)
# CI-style build with developer mode (enables tests, docs, warnings)
cmake --preset=ci-ubuntu
cmake --build build -j$(nproc)
# Build with HEAD (bleeding-edge) Ghidra instead of stable
cmake -B build -S . -Dsleigh_RELEASE_TYPE=HEAD
# Use a local Ghidra checkout (avoids re-cloning)
cmake -B build -S . -Dsleigh_RELEASE_TYPE=HEAD \
-DFETCHCONTENT_SOURCE_DIR_GHIDRASOURCE=/path/to/ghidra
# Sanitizer build
cmake --preset=ci-sanitize
cmake --build build/sanitize -j$(nproc)Tests require sleigh_DEVELOPER_MODE=ON (enabled by all ci-* presets).
# Run all tests
cd build && ctest -VV
# Run specific test by name
cd build && ctest -VV -R sleigh_decomp_unittest # unit tests
cd build && ctest -VV -R sleigh_decomp_datatest # data-driven tests
cd build && ctest -VV -R sleigh_namespace_std_test # header hygiene checkTest binary: sleigh_decomp_test — wraps Ghidra's own test suite. Takes -sleighpath for compiled .sla files and a test mode (unittests or datatests).
| Target | Library | C++ Std | Description |
|---|---|---|---|
sleigh::sla |
sla |
C++11 | Core sleigh: disassembly, encoding, p-code, emulation |
sleigh::decomp |
decomp |
C++11 | Full decompiler (superset of sla) |
sleigh::support |
slaSupport |
C++17 | Trail of Bits helpers: FindSpecFile(), version info |
Headers: <ghidra/*.hh> for upstream Ghidra headers, <sleigh/*.h> for ToB additions.
src/setup-ghidra-source.cmake— Pinned Ghidra versions, FetchContent, source file lists, patch application. This is the central file for version bumps and source management.src/patches/{stable,HEAD}/— Git-format patches applied to Ghidra source during fetchsrc/spec_files_{stable,HEAD}.cmake— Lists of ~148 .slaspec files to compiletools/— Ghidra executables (sleigh compiler, decompiler, ghidra service)support/— Trail of Bits support library (C++17)extra-tools/sleigh-lift/— Demo tool for disassembly/p-code liftingcmake/modules/sleighCompile.cmake—sleigh_compile()function exported for downstream users
src/setup-ghidra-source.cmakepins a Ghidra git ref (tag for stable, commit hash for HEAD)- CMake FetchContent clones from
github.com/NationalSecurityAgency/ghidra - Patches from
src/patches/are applied viagit am - Source file lists reference into
Ghidra/Features/Decompiler/src/decompile/cpp/ - Headers are copied into
build/include/ghidra/for clean include paths
- stable (default): Pinned to a Ghidra release tag (e.g.,
Ghidra_12.0.3_build). Shallow clone. - HEAD: Pinned to a specific commit on Ghidra main. Full clone. Updated weekly by CI via
scripts/update_ghidra_head.py.
Patches fix upstream Ghidra bugs (UB sanitizer issues, portability, strict weak ordering violations) without changing Sleigh functionality. They are standard git format-patch files.
src/patches/stable/— Patches for stable releasesrc/patches/HEAD/— Superset of stable patches plus HEAD-specific fixes- Custom patches via:
-Dsleigh_ADDITIONAL_PATCHES="path/to/patch1;path/to/patch2"
When adding patches: create with git format-patch, number sequentially, and add to both directories if applicable. Patches in HEAD must be a superset of stable patches.
- In-source builds are forbidden — enforced by
cmake/prelude.cmake - First configure is slow — Ghidra repo clone takes time (especially HEAD which can't shallow clone)
- Core libraries are C++11 — the support library and extra tools are C++17, but
sleigh::slaandsleigh::decompmust stay C++11 - Source file lists are manual — when Ghidra adds/removes .cc files,
src/setup-ghidra-source.cmakemust be updated; thescripts/update_ghidra_head.pyscript detects new files and flags them - Strict weak ordering — a recurring class of upstream bugs in Ghidra comparators; several patches fix these
- Spec files differ between releases —
src/spec_files_stable.cmakeandsrc/spec_files_HEAD.cmakeare separate lists and must be maintained independently
| Preset | Use Case |
|---|---|
ci-ubuntu |
Linux dev build with warnings and tests |
ci-macos |
macOS dev build |
ci-windows |
Windows dev build (VS 2022, vcpkg) |
ci-sanitize |
ASan + UBSan (builds to build/sanitize/) |
ci-coverage |
Code coverage (builds to build/coverage/) |
.clang-format: BasedOnStyle LLVM- Compiler warnings are strict in CI (see
flags-unix/flags-windowspresets)