pybind / pybind/pybind11

[BUG]: Not detecting the SUFFIX and DEBUG_POSTFIX for cmake correctly

Open
#4,699 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
What version (or hash if on master) of pybind11 are you using?

2.10.4

Problem description

pybind11 uses this to figure out the SUFFIX (extension) for cmake.

https://github.com/pybind/pybind11/blob/0e43fcc75e6b7429e3511dfb44343ec05a0ab843/tools/pybind11NewTools.cmake#L100-L102

This is problematic because this can also contain the debug postfix ("_d" on Windows in debug mode) because of this:

https://github.com/python/cpython/blob/a8d69fe92c65d636fc454cfb1825c357eb2e6325/Python/dynload_win.c#L18

What should be done instead is splitting the result into SUFFIX and DEBUG_POSTFIX.

At the moment, we are trying to use pybind11 with a Python that sets the DEBUG_POSTFIX _d when it needs. This is great for all python libraries.

However, cmake combines DEBUG_POSTFIX and SUFFIX, so we end up with double _d, so we _d_d which then crashes since Windows in debug mode is looking for a single _d.

At the moment, as a consumer of pybind11, we have no easy solution to fix this, only to avoid using pybind11_add_module, but then we would need to reinvent quite a bit of boilerplate, which does not look sustainable.

So, the issue is that our Python package sets the DEBUG_POSTFIX and pybind11 sets the SUFFIX. These two get combined in debug mode. They do not overwrite each other.

pybind11_extension sets SUFFIX to _d.something and we set DEBUG_POSTFIX to _d.

_d + _d.something = _d_d.something

Reproducible example code
Call pybind11_add_module() from a consumer cmake extension module in the CMakeLists.txt file on Windows in debug mode.
Is this a regression? Put the last known working version here if it is.

Not a regression

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tools/pybind11NewTools.cmake around the SUFFIX handling at lines 100-102 and inspect pybind11_extension and pybind11_add_module. Reproduce the Windows debug-mode case described in the issue, then verify that SUFFIX and DEBUG_POSTFIX are handled separately so their values are not duplicated.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.