From e93d90337301b109aa2010695eac33c7a9891f51 Mon Sep 17 00:00:00 2001 From: Rob Woolley Date: Thu, 13 Aug 2026 20:06:50 -0400 Subject: [PATCH] Add python-numpy-include feature The b2 python.jam file attempts to import the NumPy module to determine whether the Boost.Python NumPy extension should be enabled. This approach is problematic when cross-compiling, particularly because NumPy includes C extensions built for the target architecture. Introduce the new python-numpy-include feature to avoid probing for NumPy at build time by allowing the include path to be specified explicitly. This enables build systems to provide the correct NumPy include directory, eliminating the need to import the NumPy module to find the directory in site-packages. Signed-off-by: Rob Woolley --- src/tools/python.jam | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tools/python.jam b/src/tools/python.jam index 1275ff0a15..d916e9bf5b 100644 --- a/src/tools/python.jam +++ b/src/tools/python.jam @@ -61,6 +61,9 @@ lib rt ; # installed in the development system's default paths. feature.feature pythonpath : : free optional path ; +# Declare python-numpy-include as a free feature accepting a path +feature.feature python-numpy-include : : free path ; + # The best configured version of Python 2 and 3. py2-version = ; py3-version = ; @@ -900,21 +903,33 @@ local rule configure ( version ? : cmd-or-prefix ? : includes * : libraries ? : # Discover the presence of NumPy # debug-message "Checking for NumPy..." ; - local full-cmd = "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())" ; - local full-cmd = $(interpreter-cmd)" -c \"$(full-cmd)\"" ; - debug-message "running command '$(full-cmd)'" ; - local result = [ SHELL $(full-cmd) : strip-eol : exit-status ] ; - if $(result[2]) = 0 + + local custom-numpy = [ feature.get-values : $(condition) ] ; + + if $(custom-numpy) { .numpy = true ; - .numpy-include = $(result[1]) ; + .numpy-include = $(custom-numpy) ; debug-message "NumPy enabled" ; } else { - debug-message "NumPy disabled. Reason:" ; - debug-message " $(full-cmd) aborted with " ; - debug-message " $(result[1])" ; + local full-cmd = "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())" ; + local full-cmd = $(interpreter-cmd)" -c \"$(full-cmd)\"" ; + debug-message "running command '$(full-cmd)'" ; + local result = [ SHELL $(full-cmd) : strip-eol : exit-status ] ; + if $(result[2]) = 0 + { + .numpy = true ; + .numpy-include = $(result[1]) ; + debug-message "NumPy enabled" ; + } + else + { + debug-message "NumPy disabled. Reason:" ; + debug-message " $(full-cmd) aborted with " ; + debug-message " $(result[1])" ; + } } #