|
| 1 | +# Contributing to llamafile |
| 2 | + |
| 3 | +Thank you for your interest in contributing to llamafile. |
| 4 | + |
| 5 | +We welcome fixes, docs improvements, tests, build work, and larger feature work. |
| 6 | + |
| 7 | +Submodule changes (`llama.cpp/`, `whisper.cpp/`, `stable-diffusion.cpp/`) are applied as patches rather than committed directly. If your change should also go upstream, open a PR to the upstream repository (e.g., [llama.cpp](https://github.com/ggml-org/llama.cpp)). Otherwise, follow the [submodule changes workflow](#submodule-changes) described below. |
| 8 | + |
| 9 | +## Before You Start |
| 10 | + |
| 11 | +### Check for duplicates |
| 12 | + |
| 13 | +Before starting new work: |
| 14 | + |
| 15 | +- Search [existing issues](https://github.com/mozilla-ai/llamafile/issues) for duplicates |
| 16 | +- Check [open pull requests](https://github.com/mozilla-ai/llamafile/pulls) to see if someone is already working on it |
| 17 | +- For bugs, verify the issue still exists on `main` |
| 18 | + |
| 19 | +### Discuss major changes first |
| 20 | + |
| 21 | +Please open an issue before starting larger changes such as: |
| 22 | + |
| 23 | +- new user-facing features |
| 24 | +- architectural changes |
| 25 | +- changes to public behavior or defaults |
| 26 | +- new dependencies |
| 27 | +- significant build or packaging changes |
| 28 | + |
| 29 | +This helps us stay aligned and avoids duplicate work. |
| 30 | + |
| 31 | +## Development Setup |
| 32 | + |
| 33 | +### Prerequisites |
| 34 | + |
| 35 | +You will need: |
| 36 | + |
| 37 | +- GNU `make` (called `gmake` on some systems) |
| 38 | +- `sha256sum` or a working `cc` |
| 39 | +- `wget` or `curl` |
| 40 | +- `unzip` |
| 41 | +- Git |
| 42 | + |
| 43 | +Windows contributors can use [MSYS2](https://www.msys2.org/) or WSL. See [docs/building_dlls.md](docs/building_dlls.md) for detailed Windows setup instructions. |
| 44 | + |
| 45 | +### Quick Start |
| 46 | + |
| 47 | +```sh |
| 48 | +# 1. Fork the repository on GitHub |
| 49 | + |
| 50 | +# 2. Clone your fork |
| 51 | +git clone https://github.com/YOUR_USERNAME/llamafile.git |
| 52 | +cd llamafile |
| 53 | + |
| 54 | +# 3. Add upstream remote |
| 55 | +git remote add upstream https://github.com/mozilla-ai/llamafile.git |
| 56 | + |
| 57 | +# 4. Set up submodules, patches, and toolchain |
| 58 | +make setup |
| 59 | + |
| 60 | +# 5. Build with cosmocc's make |
| 61 | +.cosmocc/4.0.2/bin/make -j8 |
| 62 | + |
| 63 | +# 6. Run the default test suite |
| 64 | +.cosmocc/4.0.2/bin/make check |
| 65 | +``` |
| 66 | + |
| 67 | +`make setup` initializes submodules, applies llamafile-specific patches, and downloads the `cosmocc` toolchain into `.cosmocc/`. |
| 68 | + |
| 69 | +For builds and tests, use `.cosmocc/4.0.2/bin/make`, not your system `make`. |
| 70 | + |
| 71 | +## Making Changes |
| 72 | + |
| 73 | +### 1. Create a branch |
| 74 | + |
| 75 | +Always work on a branch, not directly on `main`: |
| 76 | + |
| 77 | +```sh |
| 78 | +git checkout -b docs/your-change |
| 79 | +``` |
| 80 | + |
| 81 | +Common branch prefixes: |
| 82 | + |
| 83 | +- `docs/` for documentation |
| 84 | +- `fix/` for bug fixes |
| 85 | +- `feature/` for new features |
| 86 | +- `build/` for build and tooling changes |
| 87 | + |
| 88 | +### 2. Make your changes |
| 89 | + |
| 90 | +There are two common workflows in this repo. |
| 91 | + |
| 92 | +#### Core code changes |
| 93 | + |
| 94 | +For changes in directories like: |
| 95 | + |
| 96 | +- `llamafile/` |
| 97 | +- `whisperfile/` |
| 98 | +- `docs/` |
| 99 | +- `tests/` |
| 100 | + |
| 101 | +you can edit files normally, rebuild, test, and commit as usual. |
| 102 | + |
| 103 | +#### Submodule changes |
| 104 | + |
| 105 | +The following directories are submodules: |
| 106 | + |
| 107 | +- `llama.cpp/` |
| 108 | +- `whisper.cpp/` |
| 109 | +- `stable-diffusion.cpp/` |
| 110 | + |
| 111 | +If you change code inside one of those directories, you also need to save those changes as patches in the matching `*.patches/` directory. |
| 112 | + |
| 113 | +When working inside a submodule, follow that submodule's local coding and contribution guidelines in addition to this repository's workflow. |
| 114 | + |
| 115 | +Example for `llama.cpp`: |
| 116 | + |
| 117 | +```sh |
| 118 | +cd llama.cpp |
| 119 | +../tools/generate-patches.sh --output-dir ../llama.cpp.patches |
| 120 | +``` |
| 121 | + |
| 122 | +After generating patches, verify them from a clean state: |
| 123 | + |
| 124 | +```sh |
| 125 | +make reset-repo |
| 126 | +make setup |
| 127 | +.cosmocc/4.0.2/bin/make -j8 |
| 128 | +.cosmocc/4.0.2/bin/make check |
| 129 | +``` |
| 130 | + |
| 131 | +For a more detailed walkthrough of the patch-based workflow, see [docs/skills/llamafile/development.md](docs/skills/llamafile/development.md#making-changes-to-a-submodule). |
| 132 | + |
| 133 | +### 3. Write tests |
| 134 | + |
| 135 | +Please add or update tests whenever your change affects behavior. |
| 136 | + |
| 137 | +- New features should include tests |
| 138 | +- Bug fixes should include a regression test when practical |
| 139 | +- Docs-only changes usually do not need tests |
| 140 | +- Avoid mixing unrelated changes in one pull request |
| 141 | + |
| 142 | +There are also integration tests under [tests/integration/README.md](tests/integration/README.md) if you want to validate changes with a real model. |
| 143 | + |
| 144 | +### 4. Update documentation |
| 145 | + |
| 146 | +If your change affects how developers or users work with llamafile, update the relevant docs in `README.md` or `docs/`. |
| 147 | + |
| 148 | +If you add a new page to `docs/`, also add it to [`docs/SUMMARY.md`](docs/SUMMARY.md) — that file controls the GitBook navigation and is maintained by hand. CI will catch any SUMMARY entries that point to missing files, but it will not catch a new file that was never added to SUMMARY. |
| 149 | + |
| 150 | +### 5. Commit your changes |
| 151 | + |
| 152 | +Use clear commit messages: |
| 153 | + |
| 154 | +```sh |
| 155 | +git commit -m "Fix server startup when model path is missing" |
| 156 | +git commit -m "Update contributor guide for patch workflow" |
| 157 | +``` |
| 158 | + |
| 159 | +## Submitting Changes |
| 160 | + |
| 161 | +Before opening a pull request, please make sure: |
| 162 | + |
| 163 | +- the project builds cleanly |
| 164 | +- the default test suite passes |
| 165 | +- submodule changes have been converted into patch files |
| 166 | +- related documentation has been updated |
| 167 | +- the change is focused and easy to review |
| 168 | +- you are ready to explain and maintain the code you changed |
| 169 | + |
| 170 | +## Useful Docs |
| 171 | + |
| 172 | +- [README.md](README.md) |
| 173 | +- [docs/source_installation.md](docs/source_installation.md) |
| 174 | +- [docs/running_llamafile.md](docs/running_llamafile.md) |
| 175 | +- [docs/creating_llamafiles.md](docs/creating_llamafiles.md) |
| 176 | +- [tests/integration/README.md](tests/integration/README.md) |
0 commit comments