Skip to content

Commit

Permalink
unix: properly advertise extension suffix when cross-compiling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indygreg committed Oct 19, 2021
1 parent 3d6e597 commit 98d2390
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,23 @@ if os.environ.get("CPYTHON_DEBUG") and "d" not in sysconfig.get_config_var("abif
sys.abiflags += "d"
sysconfig._CONFIG_VARS["abiflags"] += "d"
# importlib.machinery.EXTENSION_SUFFIXES picks up its value from #define in C
# code. When we're doing a cross-build, the C code is the build machine, not
# the host/target and is wrong. The logic here essentially reimplements the
# logic for _PyImport_DynLoadFiletab in dynload_shlib.c, which is what
# importlib.machinery.EXTENSION_SUFFIXES ultimately calls into.
extension_suffixes = [".%s.so" % sysconfig.get_config_var("SOABI")]
alt_soabi = sysconfig.get_config_var("ALT_SOABI")
if alt_soabi:
# The value can be double quoted for some reason.
extension_suffixes.append(".%s.so" % alt_soabi.strip('"'))
# Always version 3 in Python 3.
extension_suffixes.append(".abi3.so")
extension_suffixes.append(".so")
metadata = {
"python_abi_tag": sys.abiflags,
"python_implementation_cache_tag": sys.implementation.cache_tag,
Expand All @@ -915,7 +932,7 @@ metadata = {
"python_suffixes": {
"bytecode": importlib.machinery.BYTECODE_SUFFIXES,
"debug_bytecode": importlib.machinery.DEBUG_BYTECODE_SUFFIXES,
"extension": importlib.machinery.EXTENSION_SUFFIXES,
"extension": extension_suffixes,
"optimized_bytecode": importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES,
"source": importlib.machinery.SOURCE_SUFFIXES,
},
Expand Down

0 comments on commit 98d2390

Please sign in to comment.