1From debccd4be0a8d619770f63622d9de1b451dd02ac Mon Sep 17 00:00:00 2001
2From: Ben Wolsieffer <benwolsieffer@gmail.com>
3Date: Fri, 25 Sep 2020 16:49:16 -0400
4Subject: [PATCH] Fix finding headers when cross compiling
5
6When cross-compiling third-party extensions, get_python_inc() may be called to
7return the path to Python's headers. However, it uses the sys.prefix or
8sys.exec_prefix of the build Python, which returns incorrect paths when
9cross-compiling (paths pointing to build system headers).
10
11To fix this, we use the INCLUDEPY and CONFINCLUDEPY conf variables, which can
12be configured to point at host Python by setting _PYTHON_SYSCONFIGDATA_NAME.
13The existing behavior is maintained on non-POSIX platforms or if a prefix is
14manually specified.
15---
16 Lib/distutils/sysconfig.py | 14 ++++++++++----
17 1 file changed, 10 insertions(+), 4 deletions(-)
18
19diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
20index 37feae5df7..6d4ad06696 100644
21--- a/Lib/distutils/sysconfig.py
22+++ b/Lib/distutils/sysconfig.py
23@@ -95,8 +95,6 @@ def get_python_inc(plat_specific=0, prefix=None):
24 If 'prefix' is supplied, use it instead of sys.base_prefix or
25 sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
26 """
27- if prefix is None:
28- prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
29 if os.name == "posix":
30 if python_build:
31 # Assume the executable is in the build directory. The
32@@ -109,9 +107,17 @@ def get_python_inc(plat_specific=0, prefix=None):
33 else:
34 incdir = os.path.join(get_config_var('srcdir'), 'Include')
35 return os.path.normpath(incdir)
36- python_dir = 'python' + get_python_version() + build_flags
37- return os.path.join(prefix, "include", python_dir)
38+ if prefix is None:
39+ if plat_specific:
40+ return get_config_var('CONFINCLUDEPY')
41+ else:
42+ return get_config_var('INCLUDEPY')
43+ else:
44+ python_dir = 'python' + get_python_version() + build_flags
45+ return os.path.join(prefix, "include", python_dir)
46 elif os.name == "nt":
47+ if prefix is None:
48+ prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
49 if python_build:
50 # Include both the include and PC dir to ensure we can find
51 # pyconfig.h
52--
532.28.0
54