mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.54k stars 1.61k forks source link

Detect free-threaded Python from configuration #13656

Open WillAyd opened 2 weeks ago

WillAyd commented 2 weeks ago

Per the work @rgommers did in https://github.com/mesonbuild/meson/pull/13338 it appears that the Meson configuration internally detects when it is using a free-threaded interpreter and does the right thing from there

Is there any API through which the user can detect this in their own configuration? I am seeing a use case in nanobind where that build system defines a macro depending on whether or not a free-threaded interpreter is detected.

eli-schwartz commented 2 weeks ago

It's possible to poke at the raw sysconfig variables from meson.build:

freethreaded = py3.get_variable('Py_GIL_DISABLED', '') != ''

This is essentially what the meson configuration internally does too. You'd have to manually maintain the logic if CPython changes how it communicates this information, and meson would also have to separately maintain the logic. But other than that, it does work today.

It might make sense to expose this for future versions of meson. But we don't expose is_pypy either at the moment...