008-distutils-use-python-sysroot.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. The _python_sysroot variable is also used to prefix the LIBDIR value
  12. taken from the sysconfigdata module.
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  14. Index: b/Lib/distutils/sysconfig.py
  15. ===================================================================
  16. --- a/Lib/distutils/sysconfig.py
  17. +++ b/Lib/distutils/sysconfig.py
  18. @@ -19,8 +19,13 @@
  19. from distutils.errors import DistutilsPlatformError
  20. # These are needed in a couple of spots, so just compute them once.
  21. -PREFIX = os.path.normpath(sys.prefix)
  22. -EXEC_PREFIX = os.path.normpath(sys.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. +else:
  28. + PREFIX = os.path.normpath(sys.prefix)
  29. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  30. # Path to the base directory of the project. On Windows the binary may
  31. # live in project/PCBuild9. If we're dealing with an x64 Windows build,
  32. Index: b/Lib/distutils/command/build_ext.py
  33. ===================================================================
  34. --- a/Lib/distutils/command/build_ext.py
  35. +++ b/Lib/distutils/command/build_ext.py
  36. @@ -237,7 +237,10 @@
  37. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  38. if not sysconfig.python_build:
  39. # building third party extensions
  40. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  41. + libdir = sysconfig.get_config_var('LIBDIR')
  42. + if "_python_sysroot" in os.environ:
  43. + libdir = os.environ.get("_python_sysroot") + libdir
  44. + self.library_dirs.append(libdir)
  45. else:
  46. # building python standard extensions
  47. self.library_dirs.append('.')