Repository navigation
New sysconfig API: Build information - Compilation #103482
Copy link
Copy link
Open
Labels
Description
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
- currently:
- Interpreter version
- currently:
sys.implementation
- currently:
- Extension suffixes
- definition: See PEP 3149
- consideration: PEP 3149 only defines the names for POSIX
- Windows and other platforms still seem to follow it mostly (refer to
packaging.tags's implementation) - Windows
- Windows and other platforms still seem to follow it mostly (refer to
- design: The API should identify the different extensions types (interpreter, stable abi, none)
- consideration: PEP 3149 only defines the names for POSIX
- currently:
importlib.machinery.EXTENSION_SUFFIXES,sysconfig.get_config_var('EXT_SUFFIX'),sysconfig.get_config_var('SHLIB_SUFFIX')
- definition: See PEP 3149
- Is a shared
libpythonavailable? 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')
- (available?)
- definition: Yes if built with
- Is a static
libpythonavailable? 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')
- (available?)
- definition: Yes unless built with
- Should extensions link against
libpython?- definition: Yes on Android and Cygwin, no everywhere else (see extension built with a shared python cannot be loaded with a static python #65735)
- currently:
bool(sysconfig.get_config_var('LIBPYTHON'))
- Is it a debug build?
- definition: Yes if built with
--with-pydebug - currently:
bool(sysconfig.get_config_var('Py_DEBUG'))
- definition: Yes if built with
- 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.
- 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
- definition:
- 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
Reactions are currently unavailable
Activity
FFY00 commentedon Apr 22, 2023
It seems maturin needs the pointer width (see https://github.com/PyO3/maturin/blob/5d5b96a9974eac26b8cdf601cd2faf64f4999de9/src/python_interpreter/sysconfig-linux.json#L10).
zooba commentedon 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 commentedon 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 commentedon 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
FFY00 commentedon Aug 14, 2023
Yes. All the entries in
importlib.machinery.all_extensions()would be provided by name in the API.sepehr-rs commentedon May 20, 2026
Hi! I’m interested in contributing to this issue.
To help inform the design of the new sysconfig compilation API, I’ve spent some time researching how downstream tools (like maturin, setuptools, packaging, and cibuildwheel) currently interact with sysconfig. I’ve gathered two types of data:
Information required to build extensions
I went through several packaging tools and cataloged the sysconfig variables they use. I also found a curated list in maturin/sysconfig which I’ve cleaned up and organized into a table with labels for platforms, installation schemes, Python versions, and implementations. The attached table has two sections: variables curated by maturin, and additional ones I found manually.
Because the resulting table is quite huge (over 1300 variables), I have uploaded it as a spreadsheet rather than embedding it here:
Link to the spreadsheet
Workarounds that could inform the API design
2.1 Homebrew detection (
_framework_compat.pyin setuptools)The API could directly expose the installation source (e.g., Homebrew) as a dedicated attribute, so tools no longer need to parse projectbase strings.
2.2 Bundled information requiring string parsing
Some sysconfig variables bundle multiple pieces of information together, forcing tools to parse them. For example:
EXT_SUFFIX. to extractABItags whenSOABIis unavailableLDCXXSHAREDorLDSHAREDto strip outLDFLAGSI think the new API could expose these as separate, atomic values (e.g., a standalone ABI tag, and split
LDCXXSHARED/LDFLAGSvariables) to eliminate fragile string parsing.2.3 Non-integer
VERSIONvariableThe VERSION variable can apparently be non-integer in some cases, causing issues (see
test_build_scripts.pyin setuptools). I think the new API should guarantee that this is always an integer.2.4
_d.pydcheck vsPy_DEBUGBoth setuptools and packaging use "_d.pyd" in
EXTENSION_SUFFIXESinstead ofget_config_var('Py_DEBUG'). I might be missing context here, but is this something the API could address? Does it suggestPy_DEBUGis unreliable on Windows?2.5 Relocatable paths and host vs target prefixes
cibuildwheelneeds relocatable paths and a way to distinguish host from target prefixes, especially in cross-compilation. The new API could handle this by introducing explicithost_prefixandtarget_prefixproperties, and by exposing paths relative to a configurable base so that relocation becomes straightforward. I’m new to this area, so I’d be interested to hear if this approach aligns with what others have in mind.2.6 Forcing
sysconfigre-initializationcibuildwheelhas to force re-initialization of sysconfig variables after platform changes (see_cross_venv.py). I believe that the new API could consider adding a native solution for this.2.7 Cross-compilation detection
Both maturin and cibuildwheel need to detect when they’re running in a cross-compilation environment. I think the new API could provide an explicit
is_cross_compilingflag so tools don’t have to rely on heuristic checks.Would love to hear thoughts on any of these, especially from folks with more experience in this area.
zooba commentedon May 20, 2026
This has been fixed already on newer versions. Until older versions are no longer supported, most tools won't change their code.