diff mbox series

[8/9] python3: Pass PLATFORM_TRIPLET explicitly when cross compiling

Message ID 20250821064528.754633-8-raj.khem@gmail.com
State New
Headers show
Series [v2,1/9] m4: Fix ptest on musl | expand

Commit Message

Khem Raj Aug. 21, 2025, 6:45 a.m. UTC
Do not rely on how python detects the platform triplet

We have been lucky to get it cross-compiling since our build hosts
are also using glibc, so the headers and gcc install locations match
and the values it detects are mostly what we will need for glibc
based targets, but when we use musl e.g. the problems show up where
python3 is not able to automitically discover python modules so any
python package having compiled .so modules fail to load.

Example is ptest failures with TCLIBC = "musl"
and running core-image-ptest-python3-rpds-py

This is revamp of patch [1], currently its working for glibc
based cross-compiling because we build on linux systems which are also
glibc based, but python on musl shows the problem.
When python was upgraded to 3.12 [2], this patch was wrongly dropped
and sadly regression went unnoticed, without this patch
Python's automatic module discovery does not work when it is cross-compiled
this is because it tries host tools and compiler installation during configure
to detect it. .so modules e.g. modulename.cpython-*.so are not seen as a result.

This is seen when running python3-rpds-py ptests where it should load
rpds.cpython-313-x86_64-linux-musl.so rpds.so but it does not and the module test
fail.

root@qemux86-64:/usr/lib/python3-rpds-py/ptest# python3 -c "
 import sysconfig
 import importlib.machinery
 print('Extension suffixes:', importlib.machinery.EXTENSION_SUFFIXES)
 print('Soabi:', sysconfig.get_config_var('SOABI'))
 print('Ext suffix:', sysconfig.get_config_var('EXT_SUFFIX'))
 print('Module suffix:', sysconfig.get_config_var('SO'))
 "
Extension suffixes: ['.cpython-313.so', '.abi3.so', '.so']
Soabi: cpython-313
Ext suffix: .cpython-313.so
Module suffix: None

And after fix it is.

root@qemux86-64:~# python3 -c "
 import sysconfig
 import importlib.machinery
 print('Extension suffixes:', importlib.machinery.EXTENSION_SUFFIXES)
 print('Soabi:', sysconfig.get_config_var('SOABI'))
 print('Ext suffix:', sysconfig.get_config_var('EXT_SUFFIX'))
 print('Module suffix:', sysconfig.get_config_var('SO'))
 "
Extension suffixes: ['.cpython-313-x86_64-linux-musl.so', '.abi3.so', '.so']
Soabi: cpython-313-x86_64-linux-musl
Ext suffix: .cpython-313-x86_64-linux-musl.so
Module suffix: None

[1] https://git.openembedded.org/openembedded-core/commit/?id=407744b00d702e3133304e1b43064a5634ca02cf
[2] https://git.openembedded.org/openembedded-core/commit/?id=716d82352545d3667a658b69d65d6127678dd150

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meta/recipes-devtools/python/python3_3.13.7.bb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/recipes-devtools/python/python3_3.13.7.bb b/meta/recipes-devtools/python/python3_3.13.7.bb
index e9eb6109490..81d034bec6b 100644
--- a/meta/recipes-devtools/python/python3_3.13.7.bb
+++ b/meta/recipes-devtools/python/python3_3.13.7.bb
@@ -86,7 +86,7 @@  DEPENDS:append:class-nativesdk = " python3-native"
 
 EXTRA_OECONF = " --without-ensurepip --enable-shared --with-platlibdir=${baselib} --with-system-expat"
 EXTRA_OECONF:append:class-native = " --bindir=${bindir}/${PN}"
-EXTRA_OECONF:append:class-target = " --with-build-python=nativepython3"
+EXTRA_OECONF:append:class-target = " --with-build-python=nativepython3 PLATFORM_TRIPLET=${HOST_ARCH}-${HOST_OS}"
 EXTRA_OECONF:append:class-nativesdk = " --with-build-python=nativepython3"
 
 export CROSSPYTHONPATH = "${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/"