Skip to content

Commit 924261e

Browse files
authored
chore(cmake): Add an author warning that auto-calculated PYTHON_MODULE_EXTENSION may not respect SETUPTOOLS_EXT_SUFFIX during cross-compilation (#5495)
1 parent c19c291 commit 924261e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tools/FindPythonLibsNew.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
200200
endif()
201201
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_EXTENSION)
202202
get_filename_component(PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT)
203+
if((NOT "$ENV{SETUPTOOLS_EXT_SUFFIX}" STREQUAL "") AND (NOT "$ENV{SETUPTOOLS_EXT_SUFFIX}"
204+
STREQUAL "${PYTHON_MODULE_EXTENSION}"))
205+
message(
206+
AUTHOR_WARNING,
207+
"SETUPTOOLS_EXT_SUFFIX is set to \"$ENV{SETUPTOOLS_EXT_SUFFIX}\", "
208+
"but the auto-calculated Python extension suffix is \"${PYTHON_MODULE_EXTENSION}\". "
209+
"This may cause problems when importing the Python extensions. "
210+
"If you are using cross-compiling Python, you may need to "
211+
"set PYTHON_MODULE_EXTENSION manually.")
212+
endif()
203213
endif()
204214

205215
# Make sure the Python has the same pointer-size as the chosen compiler

tools/pybind11NewTools.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ if(NOT _PYBIND11_CROSSCOMPILING)
171171
set(PYTHON_MODULE_EXTENSION
172172
"${_PYTHON_MODULE_EXTENSION}"
173173
CACHE INTERNAL "")
174+
if((NOT "$ENV{SETUPTOOLS_EXT_SUFFIX}" STREQUAL "")
175+
AND (NOT "$ENV{SETUPTOOLS_EXT_SUFFIX}" STREQUAL "${PYTHON_MODULE_EXTENSION}"))
176+
message(
177+
AUTHOR_WARNING,
178+
"SETUPTOOLS_EXT_SUFFIX is set to \"$ENV{SETUPTOOLS_EXT_SUFFIX}\", "
179+
"but the auto-calculated Python extension suffix is \"${PYTHON_MODULE_EXTENSION}\". "
180+
"This may cause problems when importing the Python extensions. "
181+
"If you are using cross-compiling Python, you may need to "
182+
"set PYTHON_MODULE_EXTENSION manually.")
183+
endif()
174184
endif()
175185
endif()
176186
else()

0 commit comments

Comments
 (0)