|
| 1 | +<!-- GitHub Copilot / AI agent instructions for wireguard-tools --> |
| 2 | + |
| 3 | +# Purpose |
| 4 | + |
| 5 | +Short, actionable guidance for AI coding agents to be immediately productive in |
| 6 | +this repository. Focus on how the project is structured, build/test/debug |
| 7 | +workflows, and concrete file examples you should read before changing code. |
| 8 | + |
| 9 | +# Big picture |
| 10 | + |
| 11 | +- **What this repo is**: userspace tooling for WireGuard: the `wg(8)` CLI and |
| 12 | + `wg-quick(8)` helper scripts. Primary code lives in `src/` and platform |
| 13 | + specifics under `uapi/` and `wincompat/`. |
| 14 | +- **Major components**: |
| 15 | + - `src/` — main C sources (`wg.c`, `setconf.c`, `show.c`, etc.) and `src/Makefile`. |
| 16 | + - `wg-quick/` — platform-specific shell scripts (bash) used by install. |
| 17 | + - `uapi/` — platform-specific kernel/user API headers included at build time. |
| 18 | + - `contrib/` and `external-tests/` — sample integrations and language bindings. |
| 19 | + - `wincompat/` — compatibility layer and resources for Windows builds. |
| 20 | + |
| 21 | +# What to read first (examples) |
| 22 | + |
| 23 | +- `README.md` — project overview and canonical build/install commands. |
| 24 | +- `src/Makefile` — most important: how compilation, platform detection, and |
| 25 | + installation variables work (`PREFIX`, `WITH_WGQUICK`, `WITH_BASHCOMPLETION`). |
| 26 | +- `src/wg.c`, `src/setconf.c`, `src/show.c` — core CLI behavior and parsing. |
| 27 | +- `wg-quick/` — how the quick helper expects configuration files. |
| 28 | +- `uapi/linux/` — shows kernel-compatible headers used when compiling. |
| 29 | + |
| 30 | +# Build, test and debug (concrete commands) |
| 31 | + |
| 32 | +- Build the tools (recommended): |
| 33 | + |
| 34 | + `cd src && make` |
| 35 | + |
| 36 | +- Install (honors packaging env vars): |
| 37 | + |
| 38 | + `make install PREFIX=/usr DESTDIR=... WITH_WGQUICK=yes WITH_BASHCOMPLETION=yes` |
| 39 | + |
| 40 | +- Useful Makefile knobs: |
| 41 | + - `V=1` — disable pretty short messages and print full compiler/linker commands. |
| 42 | + - `DEBUG=yes` — compile with `-g` for debugging symbols. |
| 43 | + - `PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')` is auto-detected. |
| 44 | + |
| 45 | +- Static analysis: |
| 46 | + |
| 47 | + `cd src && make check` # runs `scan-build` if available |
| 48 | + |
| 49 | +- Windows cross-build: `wincompat/` files are used when `PLATFORM=windows`. |
| 50 | + The Makefile sets `CC` for mingw (`x86_64-w64-mingw32-clang`) when building |
| 51 | + for Windows; inspect `wincompat/` for resource and manifest handling. |
| 52 | + |
| 53 | +# Project-specific conventions & patterns |
| 54 | + |
| 55 | +- Minimal dependencies: the top-level `README.md` states "no dependencies other |
| 56 | + than a good C compiler and a sane libc." Expect simple, portable C patterns. |
| 57 | +- Platform headers: `src/Makefile` adds `-isystem uapi/$(PLATFORM)` when that |
| 58 | + directory exists. Prefer adding platform-specific headers under `uapi/`. |
| 59 | +- Packaging variables and conditional installs are controlled in `src/Makefile`. |
| 60 | + When adding files that should be packaged, update `install` target there. |
| 61 | +- Shell helpers: `wg-quick` is intentionally a small, opinionated bash script; |
| 62 | + changes to interface/flags must remain compatible with it. |
| 63 | + |
| 64 | +# Integration points & external interfaces |
| 65 | + |
| 66 | +- Kernel/user API: code relies on headers in `uapi/` to match kernel wireguard |
| 67 | + definitions — don't diverge without coordinating kernel changes. |
| 68 | +- System integration: systemd unit templates are in `systemd/`; `install` |
| 69 | + target will optionally install them if `WITH_SYSTEMDUNITS` is enabled. |
| 70 | +- Completion scripts are under `completion/` and are installed when |
| 71 | + `WITH_BASHCOMPLETION=yes`. |
| 72 | +- `contrib/embeddable-wg-library/` contains an example of embedding wireguard |
| 73 | + logic into other languages; use it as a reference for integrations. |
| 74 | + |
| 75 | +# Testing & external test harnesses |
| 76 | + |
| 77 | +- Look at `external-tests/` for example consumers in Go, Rust, Python and |
| 78 | + Haskell. These show how others interact with the CLI or wireguard APIs. |
| 79 | +- Fuzzing harness is in `fuzz/` with its own `Makefile` — follow that |
| 80 | + directory's README before changing the fuzz targets. |
| 81 | + |
| 82 | +# Helpful patterns and examples for edits |
| 83 | + |
| 84 | +- When adding a new source file to `src/`, add it to the wildcard `*.c` pattern |
| 85 | + in `src/Makefile` (it already builds all `*.c`). Keep compilation flags |
| 86 | + consistent with the existing `CFLAGS` defined there. |
| 87 | +- To preserve portable behavior, prefer using existing helpers in `ipc-*.h` |
| 88 | + and `netlink.h` rather than adding custom platform IPC code. |
| 89 | + |
| 90 | +# What an AI agent should do when making a change |
| 91 | + |
| 92 | +1. Read `src/Makefile` and the relevant `uapi/<platform>/` headers. |
| 93 | +2. Run `cd src && make V=1` locally to verify build commands and locate |
| 94 | + compile-time failures. |
| 95 | +3. Update `install` target only if adding runtime files (scripts, manpages, |
| 96 | + completions, systemd units) and test installation locally using `DESTDIR`. |
| 97 | +4. Run `make check` if the change touches memory/undefined behavior sensitive |
| 98 | + code and static analysis is available. |
| 99 | + |
| 100 | +# Questions / feedback |
| 101 | + |
| 102 | +If any of these sections are unclear or you'd like more examples (e.g. a |
| 103 | +short walkthrough of adding a new CLI flag in `wg.c`), tell me which area to |
| 104 | +expand and I'll update this file. |
0 commit comments