Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sysconfig API: Build information - Compilation #103482

Open
FFY00 opened this issue Apr 12, 2023 · 5 comments
Open

New sysconfig API: Build information - Compilation #103482

FFY00 opened this issue Apr 12, 2023 · 5 comments
Labels
topic-sysconfig type-feature A feature request or enhancement

Comments

@FFY00
Copy link
Member

FFY00 commented Apr 12, 2023

Feature or enhancement

sysconfig should export all the information required to build extensions.

Pitch

The new API should try to expose the information in a compiler-agnostic way.

Information to expose

  • Python version
    • currently: sys.version_info
  • Interpreter version
    • currently: sys.implementation
  • Extension suffixes
    • definition: See PEP 3149
      • consideration: PEP 3149 only defines the names for POSIX
      • design: The API should identify the different extensions types (interpreter, stable abi, none)
    • currently: importlib.machinery.EXTENSION_SUFFIXES, sysconfig.get_config_var('EXT_SUFFIX'), sysconfig.get_config_var('SHLIB_SUFFIX')
  • Is a shared libpython available? What's its name? Location?
    • definition: Yes if built with --enable-shared
    • currently:
      • (available?) bool(sysconfig.get_config_var('LDLIBRARY'))
      • (name?) sysconfig.get_config_var('LDLIBRARY')
      • (location?) sysconfig.get_config_var('LIBDIR')
  • Is a static libpython available? What's its name? Location?
    • definition: Yes unless built with --without-static-libpython
    • currently:
      • (available?) bool(sysconfig.get_config_var('LIBRARY'))
      • (name?) sysconfig.get_config_var('LIBRARY')
      • (location?) sysconfig.get_config_var('LIBDIR')
  • Should extensions link against libpython?
  • Is it a debug build?
    • definition: Yes if built with --with-pydebug
    • currently: bool(sysconfig.get_config_var('Py_DEBUG'))
  • C flags needed when using the C API
    • definition:
      • -fwrapv (until Enable -fstrict-overflow #96821)
        • Currently, we have unsafe code, and for a lack of a better option we assume it made into C macros, so extensions that use the C API should use -fwrapv.
  • what else? please comment...
"definition" sections list the answer, if a question, or the value(s) of the item. "currently" sections list the current way of fetching the information.

This is list is a work in progress. Currently, we need to gather all the information that is required to build extensions. If you see anything that's missing, please comment!

Previous discussion

https://discuss.python.org/t/building-extensions-modules-in-a-post-distutils-world/23938
https://discuss.python.org/t/what-information-is-useful-to-know-statically-about-an-interpreter/25563
https://gregoryszorc.com/docs/python-build-standalone/20230116/distributions.html

New sysconfig API meta-issue: GH-103480

@FFY00 FFY00 added the type-feature A feature request or enhancement label Apr 12, 2023
@FFY00
Copy link
Member Author

FFY00 commented Apr 22, 2023

@zooba
Copy link
Member

zooba commented May 2, 2023

Explicitly capturing the platform (not just the pointer width) that the runtime is targeting would be great. This is probably an arbitrary string used by the build toolset, rather than something universal.

Because Windows OS can emulate earlier architectures, and ARM64 and AMD64 have the same pointer width, the only way to know right now that you've got (in particular) an ARM64 build is to look at sys.winver. The running interpreter on an ARM64 processor could be x86 or AMD64, and the processor may be reported as one of these for emulation purposes, depending on how you ask.

Capturing the target platform at compile time would be much better.

@katietz
Copy link

katietz commented May 12, 2023

I would see such feature as very useful to be able to use host's python interpreter in crosstool scenario. I would be very useful to have a switch/configuration-file, which can be used to setup python-interpreter settings ( platform.* sys.platform and co) so it matches the cross-target. Actually I ran into this issue while looking into emscripten/pyodide, which suffers exactly by this right now

@mattip
Copy link
Contributor

mattip commented Aug 3, 2023

For extension suffixes, there should be a way to expose the limited API name as well. xref this discussion on meson build, which resorts to using

from importlib.machinery import EXTENSION_SUFFIXES
limited_api_suffix = EXTENSION_SUFFIXES[1]

@FFY00
Copy link
Member Author

FFY00 commented Aug 14, 2023

For extension suffixes, there should be a way to expose the limited API name as well.

Yes. All the entries in importlib.machinery.all_extensions() would be provided by name in the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-sysconfig type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants