b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From e359a7a3c4f9e70360a068bef19c95938fdacede Mon Sep 17 00:00:00 2001 |
| 2 | From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 3 | Date: Wed, 23 Dec 2015 11:33:14 +0100 |
| 4 | Subject: [PATCH] Adjust library/header paths for cross-compilation |
| 5 | |
| 6 | When cross-compiling third-party extensions, the get_python_inc() or |
| 7 | get_python_lib() can be called, to return the path to headers or |
| 8 | libraries. However, they use the sys.prefix of the host Python, which |
| 9 | returns incorrect paths when cross-compiling (paths pointing to host |
| 10 | headers and libraries). |
| 11 | |
| 12 | In order to fix this, we introduce the _python_sysroot, _python_prefix |
| 13 | and _python_exec_prefix variables, that allow to override these |
| 14 | values, and get correct header/library paths when cross-compiling |
| 15 | third-party Python modules. |
| 16 | |
| 17 | Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 18 | [adapt for setuptools, rename environment variable, use fixed lib path] |
| 19 | Signed-off-by: Jeffery To <jeffery.to@gmail.com> |
| 20 | --- |
| 21 | Lib/distutils/command/build_ext.py | 5 ++++- |
| 22 | Lib/sysconfig.py | 15 +++++++++++---- |
| 23 | 2 files changed, 15 insertions(+), 5 deletions(-) |
| 24 | |
| 25 | --- a/setuptools/_distutils/command/build_ext.py |
| 26 | +++ b/setuptools/_distutils/command/build_ext.py |
| 27 | @@ -238,7 +238,10 @@ class build_ext(Command): |
| 28 | if sysconfig.get_config_var('Py_ENABLE_SHARED'): |
| 29 | if not sysconfig.python_build: |
| 30 | # building third party extensions |
| 31 | - self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) |
| 32 | + libdir = sysconfig.get_config_var('LIBDIR') |
| 33 | + if 'STAGING_DIR' in os.environ: |
| 34 | + libdir = os.environ.get('STAGING_DIR') + '/usr/lib' |
| 35 | + self.library_dirs.append(libdir) |
| 36 | else: |
| 37 | # building python standard extensions |
| 38 | self.library_dirs.append('.') |