[feat/precompile-macro-infra] feat(cmake): opt-in precompiled static library, starting with pytypes.h (#6132)
* feat(cmake): opt-in precompiled pybind11 static library, starting with pytypes.h
Split the out-of-line pytypes.h definitions into pytypes-inl.h (fmtlib/
CLI11 style): inline by default, compiled once into a per-project static
library when PYBIND11_PRECOMPILED is defined. Infrastructure:
- pybind11_precompile() creates the lazy pybind11::precompiled STATIC
library from the installed or in-tree src/ sources; PRECOMPILE /
NO_PRECOMPILE keywords on pybind11_add_module and a global
PYBIND11_PRECOMPILE switch select it per target.
- A link-time guard symbol encodes PYBIND11_INTERNALS_VERSION,
Py_GIL_DISABLED, PYBIND11_SIMPLE_GIL_MANAGEMENT, and
PYBIND11_DETAILED_ERROR_MESSAGES, so a configuration mismatch is one
readable undefined symbol.
- src/ is installed to share/pybind11/src (wheel stays pure);
src/pybind11_combined.cpp is a single-TU build for non-CMake use.
- Tests: PYBIND11_TEST_PRECOMPILE builds the whole suite against the
library, two new test_cmake_build cases, packaging file lists, tidy
preset, and a 3-platform CI job.
Assisted-by: ClaudeCode:claude-fable-5
* fix(tidy): keep the tidy preset header-only
In precompiled mode the -inl.h definitions are intentionally
non-inline, so misc-definitions-in-headers fires on every one. The
header-only tidy build already analyzes all -inl.h bodies via the
bottom-of-header includes.
Assisted-by: ClaudeCode:claude-fable-5
* fix(cmake): compile the precompiled library with the interpreter ABI macros
pybind11::pybind11 only carries headers; Py_GIL_DISABLED lives on
Python::Module via pybind11::module. Without it the library is
ABI-mismatched on free-threaded builds, and on Windows the pyconfig.h
autolink pragma in its objects requests pythonXY.lib instead of
pythonXYt.lib.
Assisted-by: ClaudeCode:claude-fable-5
20 files changed