Skip to content

Commit 98d2390

Browse files
committed
unix: properly advertise extension suffix when cross-compiling
This affected Linux and macOS cross builds. imp gets its extension list from C code, which is using the host binary/config. So this commit reimplements the logic for deriving the list in Python using values from sysconfig.
1 parent 3d6e597 commit 98d2390

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cpython-unix/build-cpython.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,23 @@ if os.environ.get("CPYTHON_DEBUG") and "d" not in sysconfig.get_config_var("abif
905905
sys.abiflags += "d"
906906
sysconfig._CONFIG_VARS["abiflags"] += "d"
907907
908+
# importlib.machinery.EXTENSION_SUFFIXES picks up its value from #define in C
909+
# code. When we're doing a cross-build, the C code is the build machine, not
910+
# the host/target and is wrong. The logic here essentially reimplements the
911+
# logic for _PyImport_DynLoadFiletab in dynload_shlib.c, which is what
912+
# importlib.machinery.EXTENSION_SUFFIXES ultimately calls into.
913+
extension_suffixes = [".%s.so" % sysconfig.get_config_var("SOABI")]
914+
915+
alt_soabi = sysconfig.get_config_var("ALT_SOABI")
916+
if alt_soabi:
917+
# The value can be double quoted for some reason.
918+
extension_suffixes.append(".%s.so" % alt_soabi.strip('"'))
919+
920+
# Always version 3 in Python 3.
921+
extension_suffixes.append(".abi3.so")
922+
923+
extension_suffixes.append(".so")
924+
908925
metadata = {
909926
"python_abi_tag": sys.abiflags,
910927
"python_implementation_cache_tag": sys.implementation.cache_tag,
@@ -915,7 +932,7 @@ metadata = {
915932
"python_suffixes": {
916933
"bytecode": importlib.machinery.BYTECODE_SUFFIXES,
917934
"debug_bytecode": importlib.machinery.DEBUG_BYTECODE_SUFFIXES,
918-
"extension": importlib.machinery.EXTENSION_SUFFIXES,
935+
"extension": extension_suffixes,
919936
"optimized_bytecode": importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES,
920937
"source": importlib.machinery.SOURCE_SUFFIXES,
921938
},

0 commit comments

Comments
 (0)