2
1

009-distutils-use-python-sysroot.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Adjust library/header paths for cross-compilation
  2. When cross-compiling third-party extensions, the get_python_inc() or
  3. get_python_lib() can be called, to return the path to headers or
  4. libraries. However, they use the sys.prefix of the host Python, which
  5. returns incorrect paths when cross-compiling (paths pointing to host
  6. headers and libraries).
  7. In order to fix this, we introduce the _python_sysroot, _python_prefix
  8. and _python_exec_prefix variables, that allow to override these
  9. values, and get correct header/library paths when cross-compiling
  10. third-party Python modules.
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  12. Index: b/Lib/distutils/sysconfig.py
  13. ===================================================================
  14. --- a/Lib/distutils/sysconfig.py
  15. +++ b/Lib/distutils/sysconfig.py
  16. @@ -16,10 +16,17 @@
  17. from .errors import DistutilsPlatformError
  18. # These are needed in a couple of spots, so just compute them once.
  19. -PREFIX = os.path.normpath(sys.prefix)
  20. -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  21. -BASE_PREFIX = os.path.normpath(sys.base_prefix)
  22. -BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  23. +if "_python_sysroot" in os.environ:
  24. + _sysroot=os.environ.get('_python_sysroot')
  25. + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  26. + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  27. + BASE_PREFIX = PREFIX
  28. + BASE_EXEC_PREFIX = EXEC_PREFIX
  29. +else:
  30. + PREFIX = os.path.normpath(sys.prefix)
  31. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  32. + BASE_PREFIX = os.path.normpath(sys.base_prefix)
  33. + BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  34. # Path to the base directory of the project. On Windows the binary may
  35. # live in project/PCBuild9. If we're dealing with an x64 Windows build,
  36. Index: b/Lib/distutils/command/build_ext.py
  37. ===================================================================
  38. --- a/Lib/distutils/command/build_ext.py
  39. +++ b/Lib/distutils/command/build_ext.py
  40. @@ -239,7 +239,10 @@
  41. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  42. if not sysconfig.python_build:
  43. # building third party extensions
  44. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  45. + libdir = sysconfig.get_config_var('LIBDIR')
  46. + if "_python_sysroot" in os.environ:
  47. + libdir = os.environ.get("_python_sysroot") + libdir
  48. + self.library_dirs.append(libdir)
  49. else:
  50. # building python standard extensions
  51. self.library_dirs.append('.')