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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. --- a/Lib/distutils/sysconfig.py
  15. +++ b/Lib/distutils/sysconfig.py
  16. @@ -19,8 +19,13 @@ import sys
  17. from distutils.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. +if "_python_sysroot" in os.environ:
  22. + _sysroot=os.environ.get('_python_sysroot')
  23. + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  24. + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  25. +else:
  26. + PREFIX = os.path.normpath(sys.prefix)
  27. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  28. # Path to the base directory of the project. On Windows the binary may
  29. # live in project/PCBuild9. If we're dealing with an x64 Windows build,
  30. --- a/Lib/distutils/command/build_ext.py
  31. +++ b/Lib/distutils/command/build_ext.py
  32. @@ -240,7 +240,10 @@ class build_ext (Command):
  33. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  34. if not sysconfig.python_build:
  35. # building third party extensions
  36. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  37. + libdir = sysconfig.get_config_var('LIBDIR')
  38. + if "_python_sysroot" in os.environ:
  39. + libdir = os.environ.get("_python_sysroot") + libdir
  40. + self.library_dirs.append(libdir)
  41. else:
  42. # building python standard extensions
  43. self.library_dirs.append('.')