Skip to content

feat: small command line helpers for quick tests#4272

Open
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:henryiii/feat/clihelper
Open

feat: small command line helpers for quick tests#4272
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:henryiii/feat/clihelper

Conversation

@henryiii

@henryiii henryiii commented Oct 21, 2022

Copy link
Copy Markdown
Collaborator

Description

These are some small command line helpers intended for quick testing, based on python-config.
On a Unix system, it should be possible to do:

c++ pybindclass.cpp $(pybind11-config --cflags) $(pybind11-config --ldflags) -o pybindclass.$(python-config --extension-suffix)

Or even:

c++ $(pybind11-config --file=pybindclass.cpp)

This is handy for quick tests on issue reports.

Since I have to debug embedded code too, I also added support for --embed:

c++ $(pybind11-config --embed --file=pybindclass.cpp)

Based on https://github.com/python/cpython/blob/3.11/Misc/python-config.in

Suggested changelog entry:

* Small extra features added to the pybind11 command line tool based on python-config.

I can probably come up with a test or two.


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

@henryiii
henryiii marked this pull request as draft October 22, 2022 04:06
@henryiii
henryiii force-pushed the henryiii/feat/clihelper branch from 2a0be18 to 108e975 Compare October 25, 2022 16:45
Add --cflags, --ldflags, --embed, and --file to the pybind11 command
line tool, based on python-config. This makes quick one-off compiles
easy:

    c++ $(python3 -m pybind11 --file=example.cpp)

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii force-pushed the henryiii/feat/clihelper branch from 108e975 to 13ec9d9 Compare July 22, 2026 23:47
@henryiii

Copy link
Copy Markdown
Collaborator Author

🤖 AI text below 🤖

Rebased on current master as a single commit. Changes beyond the rebase:

  • Fixed a LIBIDRLIBDIR typo in the embed link flags.
  • Fixed the Py_ENABLE_SHARED condition: python-config adds -L$LIBPL for static builds, not shared ones. Verified by compiling and running an embedded program against a static (Homebrew framework) Python.
  • -std=c++11-std=c++17 (v3 minimum), and it is now always added, not only when CFLAGS is set.
  • --extension is now --file with --embed support, matching the final design in the PR description; the file path keeps its directory and output paths are quoted like the existing flags.
  • Kept master's --extension-suffix (added separately in the meantime) and shared its include-dir logic via a new get_include_dirs().
  • Added tests in tests/extra_python_package/test_files.py and a short section in docs/compiling.rst.

@henryiii
henryiii marked this pull request as ready for review July 23, 2026 01:15
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