Build CPython against modern kernel UAPI headers on *-linux-gnu targets by jjhelmus · Pull Request #1163 · astral-sh/python-build-standalone · GitHub
Skip to content

Build CPython against modern kernel UAPI headers on *-linux-gnu targets - #1163

Merged
jjhelmus merged 4 commits into
mainfrom
jjh/modern_kernel_uapi
Jul 6, 2026
Merged

jjhelmus merged 4 commits into
mainfrom
jjh/modern_kernel_uapi

Conversation

@jjhelmus

Copy link
Copy Markdown
Contributor

Use modern Linux kernel UAPI headers when building CPython for glibc Linux targets.

Adds a linux-uapi package to the project that contains the unpacked linux-libc-dev package from a modern Debian release, currently trixie-backports. This provides Linux UAPI headers from a modern kernel release.

Building CPython against these headers makes newer syscall definitions and macros available at build time, enabling CPython functionality such as os.pidfd_open.

This does not increase the minimum required glibc or runtime kernel version.

APIs compiled using these definitions may still fail at runtime. For example, if an API uses a direct syscall and the running kernel does not implement it, the kernel returns ENOSYS, which Python exposes as an OSError.

Consequently, functions such as os.pidfd_open will exist when running on an older kernel that does not implement the corresponding syscall. Applications should handle OSError with errno.ENOSYS when runtime kernel support is uncertain.

This should be included as a quirk of python-build-standalone and documented as such. The trade-off here is worth introducing this quirk.

Related to #193
Related to astral-sh/uv#11811, astral-sh/uv#9374

jjhelmus added 3 commits June 24, 2026 15:14
Package Debian's linux-libc-dev headers as a build dependency for
*-linux-gnu targets.

This new linux-uapi package provides userspace header from a modern
Linux kernel (currently 7.0.12).

When building CPython on *-linux-gnu targets use these headers to enable
modern kernel features, such as os.pidfp_open. At runtime if the kernel
does not support the needed syscalls ENOSYS will be returned.
Verify that no sysconfig variables contains the build-only linux-uapi path.
Verify that building against the modern Linux UAPI headers enables
os.pidfd_open on GNU/Linux targets.
@jjhelmus jjhelmus added platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform arch:all Select all architectures labels Jun 24, 2026
@jjhelmus

jjhelmus commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@geofft

geofft commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

@jjhelmus
jjhelmus merged commit e2b34ae into main Jul 6, 2026
100 checks passed
@jjhelmus
jjhelmus deleted the jjh/modern_kernel_uapi branch July 6, 2026 19:47
jjhelmus added a commit that referenced this pull request Jul 10, 2026
Always build CPython with `os.memfd_create` but remove the Python
function from the namespace at runtime when glibc does not provide the
an implementation.

This is accomplished using a weak `memfd_create` symbol which is
evaluated at runtime.

This requires the modern kernel UAPI headers from #1163 to define the
`MFD_*` constants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:all Select all architectures platform:darwin Specific to the macOS platform platform:linux Specific to the Linux platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants