Bridge Python3_INCLUDE_DIRS when only the unversioned Python module was found - #13
Open
take-cheeze wants to merge 1 commit into
Open
take-cheeze wants to merge 1 commit into
take-cheeze wants to merge 1 commit into
Conversation
…as found find_package(Python 3 ...) and find_package(Python3 ...) are separate CMake modules with separate hint/output variable namespaces. nanobind's own CMake config reads the versioned, plural Python3_INCLUDE_DIRS variable specifically -- it is never populated by the unversioned find_package(Python ...) call this file uses for ONNX_BUILD_PYTHON. On a normal host build this goes unnoticed because something else in the dependency graph (onnx's own CMakeLists.txt) has usually already called find_package(Python3) and populated it first. Cross-compiling (found while cross-compiling for wasm32-emscripten via onnxsim, see github.com/onnxsim/onnxsim's docs/wasm_pyodide.md) can reach this find_package(Python) call with nothing else having populated the Python3_* variables yet, and nanobind then fails with "Python.h file not found" immediately afterward, despite Development.Module having just been found successfully. Bridge it explicitly instead of relying on incidental ordering elsewhere in the build. Guarded so it's a no-op whenever Python3_INCLUDE_DIRS is already set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
find_package(Python 3 ...)andfind_package(Python3 ...)are separate CMake modules with separate hint/output variable namespaces. nanobind's own CMake config reads the versioned, pluralPython3_INCLUDE_DIRSvariable specifically — it's never populated by the unversionedfind_package(Python ...)call this file uses forONNX_BUILD_PYTHON.On a normal host build this goes unnoticed, because something else in the dependency graph (onnx's own
CMakeLists.txt) has usually already calledfind_package(Python3)and populated it first. Cross-compiling can reach thisfind_package(Python)call with nothing else having populated thePython3_*variables yet —nanobind_add_modulethen fails withPython.h file not foundimmediately afterward, despiteDevelopment.Modulehaving just been found successfully one line above.Found while cross-compiling onnxsim (github.com/onnxsim/onnxsim) for Pyodide/wasm32-emscripten — see that repo's
docs/wasm_pyodide.mdfor the full context. Its own build script currently has to work around this by passing bothPython3_*and unversionedPython_*CMake hints from the calling side; this fix bridges the gap at the source instead.The fix
Minimal and guarded: after the existing
find_package(Python 3 ...)call, setPython3_INCLUDE_DIRSfromPython_INCLUDE_DIRSonly if the former isn't already defined. No behavior change to thefind_packagecall itself, and it's a no-op on any build wherePython3_INCLUDE_DIRSis already populated (i.e. every normal host build) — it only kicks in for the specific cross-compile ordering gap described above.Test plan
Python.h file not foundfailure, confirmed it disappears oncePython3_INCLUDE_DIRSis populated)Generated by Claude Code