Skip to content

[feat/precompile-pybind11-h] feat: expose the precompiled-mode sources to non-CMake builds - #6137

Open
henryiii wants to merge 1 commit into
feat/precompile-pybind11-hfrom
feat/precompile-tooling
Open

[feat/precompile-pybind11-h] feat: expose the precompiled-mode sources to non-CMake builds#6137
henryiii wants to merge 1 commit into
feat/precompile-pybind11-hfrom
feat/precompile-tooling

Conversation

@henryiii

@henryiii henryiii commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Stacked on #6136. Gives every non-CMake build system a simple way to use the precompiled mode:

  • pybind11.get_source_dir() and python -m pybind11 --srcdir locate the shipped src/ directory (installed package or repo checkout), mirroring get_include().
  • pybind11.pc gains a srcdir= variable.
  • Pybind11Extension(..., precompile=True) appends src/pybind11_combined.cpp (single-TU amalgam) to the extension sources and defines PYBIND11_PRECOMPILED. A missing source tree is a hard error rather than a silent header-only fallback; the standalone-copied setup_helpers.py continues to work when the kwarg is not used. Each extension compiles its own copy (no cross-extension sharing), which keeps per-module state semantics.
  • New test_precompile_setup_py in tests/extra_setuptools/.

Meson users: dependency('pybind11').get_variable('srcdir') + -DPYBIND11_PRECOMPILED — a documentation snippet lands in the docs PR.

Suggested changelog entry:

  • Placeholder.

📚 Documentation preview 📚: https://pybind11--6137.org.readthedocs.build/

@henryiii
henryiii force-pushed the feat/precompile-tooling branch from d355af3 to 9b2f2fa Compare August 7, 2026 03:25
@henryiii
henryiii force-pushed the feat/precompile-tooling branch from 9b2f2fa to 66f3f6d Compare August 7, 2026 03:27
@henryiii
henryiii force-pushed the feat/precompile-tooling branch from 66f3f6d to ebed7aa Compare August 7, 2026 03:33
@henryiii
henryiii force-pushed the feat/precompile-tooling branch 2 times, most recently from 1cf3e84 to bbcdcf6 Compare August 7, 2026 16:27
@henryiii
henryiii force-pushed the feat/precompile-tooling branch 2 times, most recently from 80852b2 to b62428d Compare August 9, 2026 02:51
@henryiii
henryiii force-pushed the feat/precompile-tooling branch from b62428d to 5165282 Compare August 11, 2026 02:59
@henryiii
henryiii force-pushed the feat/precompile-tooling branch from 5165282 to d0cbf2c Compare August 11, 2026 22:13
@henryiii
henryiii force-pushed the feat/precompile-tooling branch 2 times, most recently from 4f75f5f to 8cbb4a7 Compare August 14, 2026 17:24
@henryiii

Copy link
Copy Markdown
Collaborator Author

I'm quite find to not add this to the classic setuptools tooling too. There are some caveats and users really should be using a modern build system instead.

Adds pybind11.get_source_dir() / python -m pybind11 --srcdir and a
srcdir variable in pybind11.pc, so build systems such as Meson can
compile src/pybind11_combined.cpp with PYBIND11_PRECOMPILED defined.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii force-pushed the feat/precompile-tooling branch from 8cbb4a7 to 8dd6204 Compare August 15, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant