Skip to content

Commit f763de1

Browse files
committed
unix: fix python_paths when cross-compiling
We should arguably fix sysconfig itself because the variables are wrong. But this at least makes the validator happy.
1 parent bf6a740 commit f763de1

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

cpython-unix/build-cpython.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,28 @@ metadata = {
817817
"python_config_vars": {k: str(v) for k, v in sysconfig.get_config_vars().items()},
818818
}
819819
820+
821+
# When cross-compiling, we use a host Python to run this script. There are
822+
# some hacks to get sysconfig to pick up the correct data file. However,
823+
# these hacks don't work for sysconfig.get_paths() and we get paths to the host
824+
# Python paths. We work around this by overwriting some variables used for
825+
# expansion. The Rust validator ensures any paths referenced by python_paths
826+
# exist, so we don't need to validate here.
820827
root = os.environ["ROOT"]
821-
for name, path in sysconfig.get_paths().items():
822-
rel = os.path.relpath(path, os.path.join(root, "out", "python"))
828+
prefix = os.path.join(root, "out", "python")
829+
830+
# These are modified in _PYTHON_BUILD mode. Restore to normal.
831+
sysconfig._INSTALL_SCHEMES["posix_prefix"]["include"] = "{installed_base}/include/python{py_version_short}{abiflags}"
832+
sysconfig._INSTALL_SCHEMES["posix_prefix"]["platinclude"] = "{installed_platbase}/include/python{py_version_short}{abiflags}"
833+
834+
sysconfig_vars = dict(sysconfig.get_config_vars())
835+
sysconfig_vars["base"] = os.path.join(prefix, "install")
836+
sysconfig_vars["installed_base"] = os.path.join(prefix, "install")
837+
sysconfig_vars["installed_platbase"] = os.path.join(prefix, "install")
838+
sysconfig_vars["platbase"] = os.path.join(prefix, "install")
839+
840+
for name, path in sysconfig.get_paths(vars=sysconfig_vars).items():
841+
rel = os.path.relpath(path, prefix)
823842
metadata["python_paths"][name] = rel
824843
825844
with open(sys.argv[1], "w") as fh:

0 commit comments

Comments
 (0)