Contributing to Kagura¶
Getting Started¶
git clone https://github.com/ykus4/kagura.git
cd kagura
bash build.sh
cd build && ctest --output-on-failure
Adding a Pass¶
- Add the pass declaration to
include/kagura/Passes.h - Implement in
lib/Transforms/<Subsystem>/YourPass.cpp - Register the source in
lib/Transforms/CMakeLists.txt - Add a
cl::optflag inlib/Transforms/Options.cppand declare it ininclude/kagura/Options.h - Register in
lib/Transforms/Plugin.cpp: - Named-pass callback via
registerPipelineParsingCallback - Auto-injection via
registerOptimizerLastEPCallback(if applicable) - Add a C source to
tests/pass-inputs/ - Add a
kagura_add_pass_test()entry intests/CMakeLists.txt - Add a FileCheck test in
tests/lit/<your-pass>.ll
Pass Guidelines¶
- Use
PassInfoMixin(New Pass Manager only — no legacy pass support) - Skip declarations:
if (F.isDeclaration()) return PA; - Check
shouldObfuscate(F, "passname", defaultEnabled)fromUtils.hto respect per-function annotations - Skip functions with exception handling when the pass cannot handle EH:
if (hasExceptionHandling(F)) return PA; - Use
kagura::PRNGfromUtils.hfor all randomness; respect-kagura-seed - Keep
isRequired()returningfalsefor all obfuscation passes - Use
kagura::getModuleTriple(M)(notM.getTargetTriple()directly) for LLVM 17–22 compatibility
Runtime Library¶
If your pass needs runtime support, add a .c file under runtime/ and register it in runtime/CMakeLists.txt. Declare any runtime functions in an extern "C" block in the pass file.
Tests¶
- Pass-level IR tests (
tests/pass-inputs/+tests/CMakeLists.txt): each file is compiled to bitcode and run throughoptto verify the pass executes without crashing - FileCheck lit tests (
tests/lit/): verify specific IR transformations using.llinputs with; CHECK:directives
All tests must pass across LLVM 17, 18, 19, 21, and 22.
To run only the FileCheck tests:
To run the differential tests (obfuscated vs. plain output comparison):
Code Style¶
- Follow LLVM coding conventions (camelCase for functions, PascalCase for types)
- File header comment format:
- No
using namespace std - No
LLVM_VERSION_MAJORguards for thegetTargetTriple()API — usekagura::getModuleTriple()instead
Pull Requests¶
- One pass or feature per PR
- Include a FileCheck test (
.ll) that verifies the pass transformation - Run
./scripts/differential-test.shlocally and confirm no regressions - CI must be green before merge
Release Process¶
Releases are published from the main branch. On GitHub:
- Create a new Release tag (e.g.,
v0.2.0) from the GitHub UI. - The
release.ymlworkflow triggers automatically and uploads pre-built binaries for: - macOS arm64 × LLVM 21 and 22
- Linux x86_64 × LLVM 19, 21, and 22
- A source tarball (
kagura-<version>-source.tar.gz) is also attached.
License¶
By contributing, you agree that your contributions will be licensed under the MIT License.