beeware / Python-Apple-support

A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project.
MIT License
1.1k stars 159 forks source link

FYI: Chaquopy sysconfig notes #152

Closed mhsmith closed 2 years ago

mhsmith commented 2 years ago

Nothing special is done when building CPython. The generated module name is _sysconfigdata__linux_ on all ABIs, because the other two placeholders in the name are empty.

At runtime the file from x86_64 is used on all ABIs. This was not a deliberate choice, but a consequence of it being the last alphabetically in this script, which I wrote before I knew that any standard library .py files files differed between ABIs. Although this is technically wrong, it's never caused any problems, because the sysconfig variables which vary between ABIs are mostly used for package building, which we never do at runtime. Variables which are the same on all ABIs, like LDLIBRARY, are no problem.

One of the other things sysconfig may be used for at runtime is finding the ABI-specific suffix for .so filenames, but that doesn't affect Chaquopy because we don't use that suffix with any of our .so files, either in the standard library or in the package wheels.

If we needed to fix this, it would be easy to supply all 4 files with different names, and modify sysconfig to use the correct one, either with a patch at build time or a monkey-patch at runtime.

The package build tool doesn't use sysconfig either, because it mostly configures build systems using environment variables and a few distutils monkey-patches.

The only package I'm aware of which does uses the generated sysconfig data at build time is tokenizers, which builds some Rust components using the PyO3 library. This has full cross-compilation support, so all we need to do is set some environment variables pointing at the Python installation in the sysroot, and it reads the sysconfig module itself. Unlike at runtime, in this context we actually have 4 separate sysroots with their own different sysconfigdata files, so the correct values will be used for the build.

freakboy3742 commented 2 years ago

I'm going to close this as addressed by #161; there's still more to do for full binary module support, but I think this detail confirms that we don't need to do anything special when it comes to the sysconfig module.