|
| 1 | +--- |
| 2 | +name: mcpplibs-index-add |
| 3 | +description: Add a new C++ library to the mcpplibs-index xmake package repository. Use when user provides a GitHub repo URL and wants to add it as a package. |
| 4 | +--- |
| 5 | + |
| 6 | +# Add Library to mcpplibs-index |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +This skill adds a new library from `https://github.com/mcpplibs/<name>` to the mcpplibs-index xmake package repository. The full workflow: gather info → create package definition → create test → verify build → commit & push. |
| 11 | + |
| 12 | +## References |
| 13 | + |
| 14 | +- xmake package docs: https://xmake.io/mirror/manual/package_dependencies.html |
| 15 | +- mcpplibs org: https://github.com/mcpplibs |
| 16 | +- index repo: https://github.com/mcpplibs/mcpplibs-index |
| 17 | + |
| 18 | +## Step 1: Gather Library Info |
| 19 | + |
| 20 | +From the given GitHub repo URL, collect: |
| 21 | + |
| 22 | +1. **Repo description** — from GitHub page |
| 23 | +2. **License** — typically Apache-2.0 |
| 24 | +3. **Latest release tag** — e.g. `0.0.1` |
| 25 | +4. **Target name** — from the repo's `xmake.lua` (`target("xxx")`) |
| 26 | +5. **Module name** — from `.cppm` files (`export module xxx`) |
| 27 | +6. **Namespace** — from `.cppm` files (`export namespace xxx`) |
| 28 | +7. **Dependencies** — from `add_requires()` in the repo's `xmake.lua` |
| 29 | +8. **Extra headers** — any `.h` files referenced in `.cppm` that need manual install (e.g. `#include "xxx.h"` in module preamble) |
| 30 | +9. **SHA256 of release tarball**: |
| 31 | + |
| 32 | +```bash |
| 33 | +curl -sL https://github.com/mcpplibs/<name>/archive/refs/tags/<version>.tar.gz | sha256sum |
| 34 | +``` |
| 35 | + |
| 36 | +## Step 2: Determine Package Name |
| 37 | + |
| 38 | +**Critical rule**: The package directory name MUST match the `package("xxx")` name exactly. |
| 39 | + |
| 40 | +- If the target name is generic (e.g. same as an existing xmake package like `lua`), use a prefixed name like `mcpplibs-capi-lua` to avoid conflicts |
| 41 | +- If the target name is unique (e.g. `llmapi`, `cmdline`), use it directly |
| 42 | +- Directory path: `packages/<first-letter>/<package-name>/xmake.lua` |
| 43 | + |
| 44 | +Examples: |
| 45 | +- `llmapi` → `packages/l/llmapi/xmake.lua` |
| 46 | +- `mcpplibs-capi-lua` → `packages/m/mcpplibs-capi-lua/xmake.lua` |
| 47 | +- `cmdline` → `packages/c/cmdline/xmake.lua` |
| 48 | + |
| 49 | +## Step 3: Create Package Definition |
| 50 | + |
| 51 | +Create `packages/<first-letter>/<package-name>/xmake.lua`: |
| 52 | + |
| 53 | +```lua |
| 54 | +package("<package-name>") |
| 55 | + |
| 56 | + set_homepage("https://github.com/mcpplibs/<repo-name>") |
| 57 | + set_description("<description>") |
| 58 | + set_license("<license>") |
| 59 | + |
| 60 | + add_urls( |
| 61 | + "https://github.com/mcpplibs/<repo-name>/archive/refs/tags/$(version).tar.gz", |
| 62 | + "https://github.com/mcpplibs/<repo-name>.git" |
| 63 | + ) |
| 64 | + |
| 65 | + add_versions("<version>", "<sha256>") |
| 66 | + |
| 67 | + -- add dependencies if any |
| 68 | + add_deps("<dep1>") |
| 69 | + |
| 70 | + on_install(function (package) |
| 71 | + local configs = {} |
| 72 | + -- If repo has examples/tests targets, specify library target only |
| 73 | + -- to avoid parallel C++23 std module compilation conflicts |
| 74 | + import("package.tools.xmake").install(package, configs, {target = "<target-name>"}) |
| 75 | + -- If cppm files reference headers not installed by default, copy them manually |
| 76 | + -- os.cp("src/path/to/header.h", package:installdir("include")) |
| 77 | + end) |
| 78 | +``` |
| 79 | + |
| 80 | +### Key Pitfalls |
| 81 | + |
| 82 | +- **Target isolation**: If the upstream repo includes examples/tests via `includes()`, they will be built during package install. This causes parallel `std` module compilation conflicts with GCC. Fix: pass `{target = "<name>"}` as the 3rd argument to `install()`. |
| 83 | +- **Missing headers**: C++20 modules using `#include` in the global module fragment need those headers installed. Check the `.cppm` files for `#include "xxx.h"` and add `os.cp(...)` in `on_install`. |
| 84 | +- **Links**: If consumers need to link against specific libraries, add `on_load` with `package:add("links", "xxx")`. |
| 85 | + |
| 86 | +## Step 4: Create Test |
| 87 | + |
| 88 | +Create `tests/<first-letter>/<package-name>/xmake.lua`: |
| 89 | + |
| 90 | +```lua |
| 91 | +add_requires("<package-name> <version>") |
| 92 | + |
| 93 | +target("<package-name>_test") |
| 94 | + set_kind("binary") |
| 95 | + add_languages("c++23") |
| 96 | + add_files("main.cpp") |
| 97 | + add_packages("<package-name>") |
| 98 | + set_policy("build.c++.modules", true) |
| 99 | +``` |
| 100 | + |
| 101 | +**Do NOT** add `add_repositories()` here — it's handled by `tests/xmake.lua`. |
| 102 | + |
| 103 | +Create `tests/<first-letter>/<package-name>/main.cpp` with a minimal usage example based on the library's examples or README. |
| 104 | + |
| 105 | +## Step 5: Register Test in Top-Level |
| 106 | + |
| 107 | +Add an `includes()` line to `tests/xmake.lua`: |
| 108 | + |
| 109 | +```lua |
| 110 | +includes("<first-letter>/<package-name>") |
| 111 | +``` |
| 112 | + |
| 113 | +## Step 6: Verify Build |
| 114 | + |
| 115 | +```bash |
| 116 | +# Clean any cached package |
| 117 | +rm -rf ~/.xmake/packages/<first-letter>/<package-name> |
| 118 | + |
| 119 | +# Configure and install from tests/ directory |
| 120 | +cd tests/ |
| 121 | +xmake f -y -c |
| 122 | + |
| 123 | +# Build the specific test target |
| 124 | +xmake build <package-name>_test |
| 125 | + |
| 126 | +# Run it |
| 127 | +xmake run <package-name>_test |
| 128 | +``` |
| 129 | + |
| 130 | +All three commands must succeed before proceeding. |
| 131 | + |
| 132 | +## Step 7: Create Branch, Commit & Push |
| 133 | + |
| 134 | +```bash |
| 135 | +git checkout -b add-<repo-name>-library |
| 136 | +git add packages/<first-letter>/<package-name>/xmake.lua \ |
| 137 | + tests/<first-letter>/<package-name>/xmake.lua \ |
| 138 | + tests/<first-letter>/<package-name>/main.cpp \ |
| 139 | + tests/xmake.lua |
| 140 | +git commit -m "add <package-name> library" |
| 141 | +git push -u upstream add-<repo-name>-library |
| 142 | +``` |
| 143 | + |
| 144 | +Use `upstream` (SSH remote) for push, not `origin` (HTTPS, no auth). |
| 145 | + |
| 146 | +## Checklist |
| 147 | + |
| 148 | +- [ ] Package directory name == `package("xxx")` name |
| 149 | +- [ ] SHA256 matches release tarball |
| 150 | +- [ ] `on_install` specifies target if repo has examples/tests |
| 151 | +- [ ] Extra headers copied in `on_install` if needed by cppm |
| 152 | +- [ ] Test does NOT have `add_repositories()` (top-level handles it) |
| 153 | +- [ ] Test registered in `tests/xmake.lua` via `includes()` |
| 154 | +- [ ] `xmake build` succeeds |
| 155 | +- [ ] `xmake run` produces expected output |
| 156 | +- [ ] Committed and pushed to upstream |
0 commit comments