1From 61af65485f1dade4aa08d0cf2b24082aeda24c51 Mon Sep 17 00:00:00 2001 2From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 3Date: Wed, 23 Dec 2015 11:33:14 +0100 4Subject: [PATCH] Adjust library/header paths for cross-compilation 5 6When cross-compiling third-party extensions, the get_python_inc() or 7get_python_lib() can be called, to return the path to headers or 8libraries. However, they use the sys.prefix of the host Python, which 9returns incorrect paths when cross-compiling (paths pointing to host 10headers and libraries). 11 12In order to fix this, we introduce the _python_sysroot, _python_prefix 13and _python_exec_prefix variables, that allow to override these 14values, and get correct header/library paths when cross-compiling 15third-party Python modules. 16 17Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 18Signed-off-by: Adam Duskett <aduskett@gmail.com> 19Refresh for 3.10.0 20--- 21 Lib/distutils/command/build_ext.py | 5 ++++- 22 Lib/sysconfig.py | 15 +++++++++++---- 23 2 files changed, 15 insertions(+), 5 deletions(-) 24 25diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py 26index 1a9bd12..3cf7d67 100644 27--- a/Lib/distutils/command/build_ext.py 28+++ b/Lib/distutils/command/build_ext.py 29@@ -234,7 +234,10 @@ class build_ext(Command): 30 if (sysconfig.get_config_var('Py_ENABLE_SHARED')): 31 if not sysconfig.python_build: 32 # building third party extensions 33- self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) 34+ libdir = sysconfig.get_config_var('LIBDIR') 35+ if "_python_sysroot" in os.environ: 36+ libdir = os.environ.get("_python_sysroot") + libdir 37+ self.library_dirs.append(libdir) 38 else: 39 # building python standard extensions 40 self.library_dirs.append('.') 41diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py 42index 95b48f6..9fb1956 100644 43--- a/Lib/sysconfig.py 44+++ b/Lib/sysconfig.py 45@@ -123,10 +123,17 @@ _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', 46 _PY_VERSION = sys.version.split()[0] 47 _PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}' 48 _PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}' 49-_PREFIX = os.path.normpath(sys.prefix) 50-_BASE_PREFIX = os.path.normpath(sys.base_prefix) 51-_EXEC_PREFIX = os.path.normpath(sys.exec_prefix) 52-_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix) 53+if "_python_sysroot" in os.environ: 54+ _sysroot=os.environ.get('_python_sysroot') 55+ _PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix')) 56+ _EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix')) 57+ _BASE_PREFIX = _PREFIX 58+ _BASE_EXEC_PREFIX = _EXEC_PREFIX 59+else: 60+ _PREFIX = os.path.normpath(sys.prefix) 61+ _EXEC_PREFIX = os.path.normpath(sys.exec_prefix) 62+ _BASE_PREFIX = os.path.normpath(sys.base_prefix) 63+ _BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix) 64 _CONFIG_VARS = None 65 _USER_BASE = None 66 67-- 682.30.2 69 70