Building
We mostly rely on a build container, but some dependencies are still needed outside that container: our fork of LLVM20, a local copy of lld, and LLVM LIT.
In order to set up those and build Patchestry, please follow the first-time instructions for your development environment of choice: - macOS - Linux
See also: Development
First Time Development Setup: MacOS
-
Install Xcode from the App Store and set up the command line tools:
-
Install the required dependencies using Homebrew:
-
Configure Docker BuildX to work with Colima:
-
Log into Docker Hub (this may not be needed - it is not needed on Linux):
-
For building ClangIR, clone the project and compile with the following CMake configuration:
cmake -G Ninja ../../llvm \ -DCMAKE_INSTALL_PREFIX="/path/to/installdir" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DLLVM_ENABLE_PROJECTS="clang;mlir;clang-tools-extra" \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCLANG_ENABLE_CIR=ON \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DLLVM_ENABLE_RTTI=ON \ -DLLVM_INSTALL_UTILS=ON \ -DLLVM_TARGETS_TO_BUILD="host;AArch64;ARM;X86"
The targets list of "host;AArch64;ARM;X86" is intentional (to always build host arch, AArch64, ARM, and x86), even if host arch is almost certainly either AArch64 or X86.
- Build with:
This setup provides a complete development environment for building and running the project on MacOS. The configuration uses Colima as a Docker backend, which provides better performance and resource management compared to Docker Desktop on MacOS.
First Time Development Setup: Linux
If you'd like to either follow step by step instructions or run a script to automatically follow them in a fresh Linux instance, here's a Gist that sets everything up from zero in a fresh VM for you and runs the Patchestry tests to confirm the setup works. This Gist should stay reasonably up to date since it's used to initialize ephemeral coding environments. It's been tested on Ubuntu 24.04. The only thing that should be different for other Ubuntus or for Debian is the apt package naming.
Steps followed in the Gist to get to a working install: 1. Base dependency install (Docker, lld, build tools such as CMake) 2. Acquire LLVM LIT from Python Pip 3. Build and install LLVM 4. Build and install Patchestry 5. Build the headless container in the Patchestry repository (this should set up and install Ghidra and everything else) 6. Run tests for Patchestry, which requires the container / occurs in the container
Development
CMake Commands
- to build, see the command referenced in step 6 above or the commands used for Linux. You'll use the
defaultpreset to configure and most likely thedebugorreleasepresets for the subsequent build command after configuration. - to run tests, ensure the headless container is available first by running
scripts/ghidra/build-headless-docker.sh, then you maycmake --build builds/default/ -j$((nproc+1)) --preset debug --target test(using the preset of your choice but selecting thetesttarget)
Ghidra
Installing Ghidra Locally
You shouldn't need to do this directly in the current build most of the time. Prefer working in the headless container. You may want Ghidra locally for Ghidra script debugging.
Get Java JDK (x64)
wget -c https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.tar.gz -O jdk.tar.gz
tar xvf jdk.tar.gz
mv jdk-22.0.1 ~/jdk
echo "export PATH=\$PATH:~/jdk/bin" >> ~/.bashrc
Get Ghidra