Cookbook¶
Small, complete, runnable recipes — one per page, each a standalone consumer
project under examples/cookbook/ and asserted by a CTest in CI. Where the
guide explains each feature in isolation, a recipe shows the
whole dish: the annotated C++, the CMake that builds it, and a check script that
loads the module and proves what bound.
- 01 — One of everything — weld a type, an enum, a free function
and a namespace variable, one
weld_*call each. - 02 — Discovery rules — policies, marks, nested namespaces,
pruning
detail,weld_asrenames,WELDER_MODULE. - 03 — Inheritance — welded bases become native bases; unwelded bases flatten in as mixins.
- 04 — Virtual methods — Python subclasses overriding C++ virtuals through hand-written trampolines.
- 05 — Generated trampolines — the same, with the trampolines reflection-generated at build time.
- 06 — Templates — weld class/function template instantiations under explicit names.
- 07 — One library, two languages — Python (nanobind) + Lua
(sol2 and LuaBridge3) from one header: name styles, per-language
weld_as,mark::onlylanguage flavors,.pyi+ LuaCATS stubs. - 08 — Tack welding — greedily bind a third-party library that carries no welder annotations at all.
- 09 — Custom traversal — subclass the tack
resolution to honor a library's privacy convention: prune
detailnamespaces and_underscoreinternals.
Building the recipes¶
The cookbook is a standalone super-project: it obtains welder with
FetchContent — exactly the way a consumer would
— and FetchContent-pins the backends (pybind11, nanobind, sol2). No Conan, nothing
preinstalled beyond gcc-16, CMake + Ninja, a Python, and (for the Lua half of
recipe 07) a Lua install:
cmake -S examples/cookbook -B build/cookbook -G Ninja \
-DCMAKE_CXX_COMPILER=g++-16 \
-DWELDER_LUA_DIR="$(brew --prefix lua@5.4)" # optional: enables the Lua recipe
cmake --build build/cookbook
ctest --test-dir build/cookbook --output-on-failure
By default welder itself is fetched from GitHub. welder's CI instead points the
fetch at the current checkout (-DFETCHCONTENT_SOURCE_DIR_WELDER=$PWD), so every
recipe — and the FetchContent consumption path itself — is exercised on every
commit.
Copying a recipe
Each recipe directory is deliberately self-contained (one CMakeLists.txt,
one or a few .cpp, a check script). To start your own project from one,
copy the recipe directory plus the dependency block of the top-level
CMakeLists.txt — that block is the "consume welder without Conan"
reference.