|
| 1 | +# Contributing to java-llama.cpp |
| 2 | + |
| 3 | +Thank you for your interest in contributing! This document explains how to build the project, file issues, submit pull requests, and what we expect from contributors. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +1. [How to Build and Run](#how-to-build-and-run) |
| 8 | +2. [Filing Issues](#filing-issues) |
| 9 | +3. [Pull Request Workflow](#pull-request-workflow) |
| 10 | +4. [Coding Standards](#coding-standards) |
| 11 | +5. [Test Policy](#test-policy) |
| 12 | +6. [Communication Channels](#communication-channels) |
| 13 | +7. [License of Contributions](#license-of-contributions) |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## How to Build and Run |
| 18 | + |
| 19 | +### Prerequisites |
| 20 | + |
| 21 | +- Java 11 or later |
| 22 | +- Maven 3.x |
| 23 | +- CMake 3.22 or later |
| 24 | +- A C++17-capable compiler (GCC, Clang, or MSVC) |
| 25 | + |
| 26 | +### Java Layer (Maven) |
| 27 | + |
| 28 | +```bash |
| 29 | +# Compile Java sources and generate JNI headers (required before CMake build) |
| 30 | +mvn compile |
| 31 | + |
| 32 | +# Run all tests (requires a pre-built native library and model files in place) |
| 33 | +mvn test |
| 34 | + |
| 35 | +# Run a single test |
| 36 | +mvn test -Dtest=LlamaModelTest#testGenerate |
| 37 | + |
| 38 | +# Package a JAR |
| 39 | +mvn package |
| 40 | +``` |
| 41 | + |
| 42 | +### Native Library (CMake) |
| 43 | + |
| 44 | +Run `mvn compile` first to generate the JNI headers, then: |
| 45 | + |
| 46 | +```bash |
| 47 | +# CPU-only build |
| 48 | +cmake -B build |
| 49 | +cmake --build build --config Release |
| 50 | + |
| 51 | +# With CUDA support (Linux) |
| 52 | +cmake -B build -DGGML_CUDA=ON |
| 53 | +cmake --build build --config Release |
| 54 | + |
| 55 | +# With Metal support (macOS) |
| 56 | +cmake -B build -DLLAMA_METAL=ON |
| 57 | +cmake --build build --config Release |
| 58 | + |
| 59 | +# With model-download support (libcurl) |
| 60 | +cmake -B build -DLLAMA_CURL=ON |
| 61 | +cmake --build build --config Release |
| 62 | +``` |
| 63 | + |
| 64 | +Built libraries are placed under `src/main/resources/net/ladenthin/llama/{OS}/{ARCH}/`. |
| 65 | + |
| 66 | +### C++ Unit Tests (no JVM or model file required) |
| 67 | + |
| 68 | +```bash |
| 69 | +cmake -B build -DBUILD_TESTING=ON |
| 70 | +cmake --build build --config Release -j$(nproc) |
| 71 | +ctest --test-dir build --output-on-failure |
| 72 | +``` |
| 73 | + |
| 74 | +### Code Formatting |
| 75 | + |
| 76 | +```bash |
| 77 | +# Format C++ source files |
| 78 | +clang-format -i src/main/cpp/*.cpp src/main/cpp/*.hpp |
| 79 | +``` |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Filing Issues |
| 84 | + |
| 85 | +Please use the GitHub issue tracker: |
| 86 | + |
| 87 | +- **Bug reports, feature requests, questions:** https://github.com/bernardladenthin/java-llama.cpp/issues |
| 88 | + |
| 89 | +Before opening an issue, search existing issues to avoid duplicates. When reporting a bug, include: |
| 90 | + |
| 91 | +- Operating system and architecture |
| 92 | +- Java version (`java -version`) |
| 93 | +- llama.cpp build tag the library was compiled against |
| 94 | +- A minimal reproduction case (model name, parameters, code snippet) |
| 95 | +- Full stack trace or error output |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Pull Request Workflow |
| 100 | + |
| 101 | +1. **Fork** the repository on GitHub. |
| 102 | +2. Create a **feature branch** from `main`: |
| 103 | + ```bash |
| 104 | + git checkout main |
| 105 | + git pull origin main |
| 106 | + git checkout -b feat/my-feature |
| 107 | + ``` |
| 108 | +3. Make your changes, including tests (see [Test Policy](#test-policy)). |
| 109 | +4. Push the branch to your fork and open a **Pull Request** against `bernardladenthin/java-llama.cpp:main`. |
| 110 | +5. Describe what the PR changes and why; link any related issue (`Closes #NNN`). |
| 111 | +6. Respond to review comments and push follow-up commits to the same branch. |
| 112 | +7. A maintainer will merge once the PR is approved and CI is green. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## Coding Standards |
| 117 | + |
| 118 | +- Follow the conventions documented in [CLAUDE.md](CLAUDE.md) — it describes the project architecture, include-order rules, helper-file split (`json_helpers.hpp` vs `jni_helpers.hpp`), and Javadoc HTML-entity conventions. |
| 119 | +- Java code targets Java 11+. |
| 120 | +- C++ code must be compatible with C++17 and compile cleanly with the project's CMake configuration. |
| 121 | +- Format C++ files with `clang-format` before committing (see command above). |
| 122 | +- Use HTML entities in Javadoc for operators and symbols outside ASCII (see CLAUDE.md for the full table). |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Test Policy |
| 127 | + |
| 128 | +> Every new feature or behavior change MUST include automated tests. Pull requests that add or change functionality without corresponding tests will be asked to add tests before merge. Bug fixes SHOULD include a regression test. |
| 129 | +
|
| 130 | +- **Java tests** live in `src/test/java/net/ladenthin/llama/` and `src/test/java/examples/`. |
| 131 | +- **C++ unit tests** (no JVM required) live in `src/test/cpp/`. Add pure-data transforms to `test_json_helpers.cpp`, JNI bridge helpers to `test_jni_helpers.cpp`, and upstream result types to `test_server.cpp`. |
| 132 | +- Tests must pass locally before opening a PR. CI also runs them automatically on push and on pull requests. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Communication Channels |
| 137 | + |
| 138 | +- **GitHub Issues** — bug reports and feature requests: https://github.com/bernardladenthin/java-llama.cpp/issues |
| 139 | +- **GitHub Discussions** — general questions and ideas (if enabled on the repository). |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## License of Contributions |
| 144 | + |
| 145 | +By submitting a pull request you agree that your contribution is made available under the **MIT License** — the same license that governs this repository (see [LICENSE.md](LICENSE.md)). |
0 commit comments