0004-Adjust-library-header-paths-for-cross-compilation.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 132b9dca3bb4d4682f7e318648ce11e1abb31b62 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. When cross-compiling third-party extensions, the get_python_inc() or
  6. get_python_lib() can be called, to return the path to headers or
  7. libraries. However, they use the sys.prefix of the host Python, which
  8. returns incorrect paths when cross-compiling (paths pointing to host
  9. headers and libraries).
  10. In order to fix this, we introduce the _python_sysroot, _python_prefix
  11. and _python_exec_prefix variables, that allow to override these
  12. values, and get correct header/library paths when cross-compiling
  13. third-party Python modules.
  14. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  15. Signed-off-by: Adam Duskett <aduskett@gmail.com>
  16. Refresh for 3.10.0
  17. ---
  18. Lib/distutils/command/build_ext.py | 5 ++++-
  19. Lib/sysconfig.py | 15 +++++++++++----
  20. 2 files changed, 15 insertions(+), 5 deletions(-)
  21. diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
  22. index f287b34998..298234d6a1 100644
  23. --- a/Lib/distutils/command/build_ext.py
  24. +++ b/Lib/distutils/command/build_ext.py
  25. @@ -234,7 +234,10 @@ def finalize_options(self):
  26. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  27. if not sysconfig.python_build:
  28. # building third party extensions
  29. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  30. + libdir = sysconfig.get_config_var('LIBDIR')
  31. + if "_python_sysroot" in os.environ:
  32. + libdir = os.environ.get("_python_sysroot") + libdir
  33. + self.library_dirs.append(libdir)
  34. else:
  35. # building python standard extensions
  36. self.library_dirs.append('.')
  37. diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
  38. index ebe3711827..6328ec41af 100644
  39. --- a/Lib/sysconfig.py
  40. +++ b/Lib/sysconfig.py
  41. @@ -168,10 +168,17 @@ def joinuser(*args):
  42. _PY_VERSION = sys.version.split()[0]
  43. _PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}'
  44. _PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}'
  45. -_PREFIX = os.path.normpath(sys.prefix)
  46. -_BASE_PREFIX = os.path.normpath(sys.base_prefix)
  47. -_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  48. -_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  49. +if "_python_sysroot" in os.environ:
  50. + _sysroot=os.environ.get('_python_sysroot')
  51. + _PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  52. + _EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  53. + _BASE_PREFIX = _PREFIX
  54. + _BASE_EXEC_PREFIX = _EXEC_PREFIX
  55. +else:
  56. + _PREFIX = os.path.normpath(sys.prefix)
  57. + _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  58. + _BASE_PREFIX = os.path.normpath(sys.base_prefix)
  59. + _BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  60. _CONFIG_VARS = None
  61. _USER_BASE = None
  62. --
  63. 2.34.1