You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sysconfig --generate-posix-vars creates wrong file when cross compiling #90067
"sysconfig --generate-posix-vars" creates pybuilddir.txt and a platform-specific sysconfig data file like build/lib.linux-x86_64-3.11/_sysconfigdata__linux_x86_64-linux-gnu.py
When creating a cross-compile build of Python, sysconfig mixes data from the cross compile build and the host build. It creates a pybuilddir.txt and build/lib directory with correct values (e.g. wasm32-unknown-emscripten) but sysconfigdata file with name values from the host Python PYTHON_FOR_BUILD (e.g x86_64-unknown-linux-gnu).
$ cat pybuilddir.txt
build/lib.wasm32-unknown-emscripten-3.11
$ ls build/lib.wasm32-unknown-emscripten-3.11/_sysconfigdata*
build/lib.wasm32-unknown-emscripten-3.11/_sysconfigdata__linux_x86_64-linux-gnu.py
$ grep CC build/lib.wasm32-unknown-emscripten-3.11/_sysconfigdata__linux_x86_64-linux-gnu.py
'CC': 'gcc',
$ grep ^CC Makefile
CC= emcc
I just realized that PYTHON_FOR_BUILD is far more complicated. Our WASM build system sets the env var to "$(pwd)/cpython/builddir/build/python". The configure script expects us to set several additional env vars.
I can't cross-compile python because of this. Lib/sysconfig.py uses os.name and sys.platform almost everywhere which are wrong in cross-compile scenario.
For example, when building on windows for non-windows, the build will fail here:
Cross compiling from Windows to a POSIX-like OS is uncharted territory. I suggest that you open a new ticket. Your use case needs feedback from core devs who are familiar with Windows build system, too.
@tiran I don't know much about the WASM builds, but would it be possible for you to set the missing environment variables? Long term, I think we definitely want something better, but I think that requires standardizing and documenting cross-builds.
Activity
tiran commentedon Nov 27, 2021
"sysconfig --generate-posix-vars" creates pybuilddir.txt and a platform-specific sysconfig data file like build/lib.linux-x86_64-3.11/_sysconfigdata__linux_x86_64-linux-gnu.py
When creating a cross-compile build of Python, sysconfig mixes data from the cross compile build and the host build. It creates a pybuilddir.txt and build/lib directory with correct values (e.g. wasm32-unknown-emscripten) but sysconfigdata file with name values from the host Python PYTHON_FOR_BUILD (e.g x86_64-unknown-linux-gnu).
tiran commentedon Nov 27, 2021
I just realized that PYTHON_FOR_BUILD is far more complicated. Our WASM build system sets the env var to "$(pwd)/cpython/builddir/build/python". The configure script expects us to set several additional env vars.
The logic goes like this for cross compiling:
Since we don't set any of the variables _PYTHON_PROJECT_BASE, _PYTHON_HOST_PLATFORM, and _PYTHON_SYSCONFIGDATA_NAME, we get wrong sysconfig data file.
Osyotr commentedon Aug 21, 2022
I can't cross-compile python because of this.
Lib/sysconfig.pyusesos.nameandsys.platformalmost everywhere which are wrong in cross-compile scenario.For example, when building on windows for non-windows, the build will fail here:
cpython/Lib/sysconfig.py
Lines 590 to 593 in d8c7a11
_PYTHON_HOST_PLATFORMshould probably be used instead.Cmdline is like this:
_PYTHON_PROJECT_BASE=/d/vcpkg/buildtrees/python3/ntoarmv7-qnx-rel _PYTHON_HOST_PLATFORM=qnx-arm PYTHONPATH=./../src/v3.11.0rc1-bb53a96c2e.clean/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__qnx_ C:/Users/Osyotr/Desktop/bb_gcc_test/out/vcpkg_installed/x64-windows/tools/python3/python.exe -S -m sysconfig --generate-posix-varstiran commentedon Aug 24, 2022
Cross compiling from Windows to a POSIX-like OS is uncharted territory. I suggest that you open a new ticket. Your use case needs feedback from core devs who are familiar with Windows build system, too.
FFY00 commentedon Nov 21, 2022
@tiran I don't know much about the WASM builds, but would it be possible for you to set the missing environment variables? Long term, I think we definitely want something better, but I think that requires standardizing and documenting cross-builds.
Do you have any alternative proposal?
manueljacob commentedon Apr 7, 2026
This very likely has the same root cause as #136267.